From 9ab4b1b78c66404752b0df8f362b3b03bdc2254d Mon Sep 17 00:00:00 2001 From: Ratik Jindal Date: Fri, 13 Oct 2023 20:14:51 +0530 Subject: [PATCH] fix user name --- src/store/channels-list/saga.test.ts | 12 +++++++----- src/store/channels-list/saga.ts | 13 +++++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/store/channels-list/saga.test.ts b/src/store/channels-list/saga.test.ts index 300badff2..674397f45 100644 --- a/src/store/channels-list/saga.test.ts +++ b/src/store/channels-list/saga.test.ts @@ -428,15 +428,17 @@ describe('channels list saga', () => { }); describe(otherUserJoinedChannel, () => { - it('adds the user to the otherMember list', async () => { + it('finds the zOS user and adds the user to the otherMember list', async () => { const existingMembers = [ { userId: 'user-1', matrixId: 'user-1' }, { userId: 'user-2', matrixId: 'user-2' }, ] as any; - const initialState = new StoreBuilder().withConversationList({ - id: 'conversation-id', - otherMembers: existingMembers, - }); + const initialState = new StoreBuilder() + .withConversationList({ + id: 'conversation-id', + otherMembers: existingMembers, + }) + .withUsers({ userId: 'new-user', matrixId: 'new-user', firstName: 'Jane', lastName: 'doe' }); const { storeState } = await expectSaga(otherUserJoinedChannel, 'conversation-id', { userId: 'new-user', diff --git a/src/store/channels-list/saga.ts b/src/store/channels-list/saga.ts index d698f93e4..f0972675c 100644 --- a/src/store/channels-list/saga.ts +++ b/src/store/channels-list/saga.ts @@ -202,6 +202,10 @@ export function* createOptimisticConversation(userIds: string[], name: string = } export function* receiveCreatedConversation(conversation, optimisticConversation = { id: '', optimisticId: '' }) { + if (!conversation) { + return; + } + const existingConversationsList = yield select(rawConversationsList()); const listWithoutOptimistic = existingConversationsList.filter((id) => id !== optimisticConversation.id); @@ -409,12 +413,17 @@ export function* otherUserJoinedChannel(roomId: string, user: User) { return; } - // TODO: Fetch user from zOS if we don't know about them yet + if (user.userId === user.matrixId) { + user = yield select(userByMatrixId, user.matrixId); + } + if (!channel.otherMembers.includes(user.userId)) { + const otherMembers = [...channel.otherMembers, user]; yield put( receiveChannel({ id: channel.id, - otherMembers: [...channel.otherMembers, user], + isOneOnOne: otherMembers.length === 1, + otherMembers, }) ); }