diff --git a/src/store/channels-list/saga.test.ts b/src/store/channels-list/saga.test.ts index 3ba467b11..8bc6d64bd 100644 --- a/src/store/channels-list/saga.test.ts +++ b/src/store/channels-list/saga.test.ts @@ -170,6 +170,19 @@ describe('channels list saga', () => { 'conversation-id', ]); }); + + it('removes channels that are duplicates of the newly fetched conversations', async () => { + const fetchedConversations = [{ id: 'previously-a-channel' }]; + + const initialState = new StoreBuilder().withChannelList({ id: 'previously-a-channel' }); + + const { storeState } = await subject(fetchConversations, undefined) + .provide([[matchers.call([chatClient, chatClient.getConversations]), fetchedConversations]]) + .withReducer(rootReducer, initialState.build()) + .run(); + + expect(storeState.channelsList.value).toIncludeSameMembers(['previously-a-channel']); + }); }); describe(fetchChannelsAndConversations, () => { diff --git a/src/store/channels-list/saga.ts b/src/store/channels-list/saga.ts index 232434f29..cbb428d2a 100644 --- a/src/store/channels-list/saga.ts +++ b/src/store/channels-list/saga.ts @@ -66,9 +66,12 @@ export function* fetchConversations() { .map((c) => c.id); const channelsList = yield select(rawChannelsList()); + const conversationIds = conversations.map((c) => c.id); + // Channels can change to conversations (due to the nature of Matrix) + const filteredChannelsList = channelsList.filter((id) => !conversationIds.includes(id)); yield put( receive([ - ...channelsList, + ...filteredChannelsList, ...optimisticConversationIds, ...conversations, ])