diff --git a/packages/backend/src/nest/storage/storage.service.ts b/packages/backend/src/nest/storage/storage.service.ts index d3b21f8164..53988be1ff 100644 --- a/packages/backend/src/nest/storage/storage.service.ts +++ b/packages/backend/src/nest/storage/storage.service.ts @@ -567,7 +567,7 @@ export class StorageService extends EventEmitter { ) const channel = this.channels.get(channelId) - this.logger(`Found existing channel: ${channel}`) + this.logger('Found existing channel:', channel) if (channel === undefined) { await this.channels.put(channelId, { ...channelData }) diff --git a/packages/desktop/src/rtl-tests/community.join.test.tsx b/packages/desktop/src/rtl-tests/community.join.test.tsx index 880ad07f1c..9ddf17c4e7 100644 --- a/packages/desktop/src/rtl-tests/community.join.test.tsx +++ b/packages/desktop/src/rtl-tests/community.join.test.tsx @@ -29,6 +29,7 @@ import { AnyAction } from 'redux' import { InvitationData, ChannelsReplicatedPayload, + ChannelSubscribedPayload, Community, ErrorPayload, type NetworkInfo, @@ -116,6 +117,9 @@ describe('User', () => { }, }, }) + socket.socketClient.emit(SocketActionTypes.CHANNEL_SUBSCRIBED, { + channelId: 'general', + }) } } @@ -184,6 +188,7 @@ describe('User', () => { "Network/addInitializedCommunity", "Communities/clearInvitationCodes", "PublicChannels/channelsReplicated", + "PublicChannels/setChannelSubscribed", "PublicChannels/addChannel", "Messages/addPublicChannelsMessagesBase", "PublicChannels/sendIntroductionMessage", diff --git a/packages/state-manager/src/sagas/publicChannels/sendIntroductionMessage/sendIntroductionMessage.saga.ts b/packages/state-manager/src/sagas/publicChannels/sendIntroductionMessage/sendIntroductionMessage.saga.ts index 8a485494b4..87e2cd04f4 100644 --- a/packages/state-manager/src/sagas/publicChannels/sendIntroductionMessage/sendIntroductionMessage.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/sendIntroductionMessage/sendIntroductionMessage.saga.ts @@ -1,4 +1,4 @@ -import { put, select, call } from 'typed-redux-saga' +import { put, select, call, delay } from 'typed-redux-saga' import { messagesActions } from '../../messages/messages.slice' import { publicChannelsSelectors } from '../publicChannels.selectors' import { WriteMessagePayload, MessageType, PublicChannel, PublicChannelStorage } from '@quiet/types' @@ -24,6 +24,24 @@ export function* sendIntroductionMessageSaga(): Generator { channelId: generalChannel.id, } + // FIXME: This is a quick fix for an issue that can be fixed by + // unifying CHANNELS_STORED and CHANNELS_SUBSCRIBED events and + // refactoring a bit. The problem is that the frontend sends a + // message upon receiving the CHANNELS_STORED event, but the channel + // hasn't been fully initialized/subscribed yet (it doesn't exist in + // publicChannelsRepos on the backend so the backend fails to send + // it). Ideally, I think we should only tell the frontend about + // channels once they've been fully initialized. Once we fix that, + // we can remove the following code. + while (true) { + const subscribedChannels = yield* select(publicChannelsSelectors.subscribedChannels) + if (subscribedChannels.includes(generalChannel.id)) { + break + } + console.error('Failed to send introduction message, general channel not subscribed. Retrying...') + yield* delay(500) + } + yield* put(messagesActions.sendMessage(payload)) yield* put(identityActions.updateIdentity({ ...identity, introMessageSent: true })) }