From e4854249cf26ecab000323166cc8ce27c928864c Mon Sep 17 00:00:00 2001 From: Dale Fukami Date: Tue, 3 Oct 2023 11:36:04 -0600 Subject: [PATCH] Remove existing channels from list When fetching full conversation list (#1068) --- src/store/channels-list/saga.test.ts | 13 +++++++++++++ src/store/channels-list/saga.ts | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) 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, ])