Skip to content

Commit

Permalink
Remove existing channels from list When fetching full conversation li…
Browse files Browse the repository at this point in the history
…st (#1068)
  • Loading branch information
dalefukami authored Oct 3, 2023
1 parent c89e061 commit e485424
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/store/channels-list/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, () => {
Expand Down
5 changes: 4 additions & 1 deletion src/store/channels-list/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
])
Expand Down

0 comments on commit e485424

Please sign in to comment.