Skip to content

Commit

Permalink
refactor(chat-saga): create detached task for marking conversations a…
Browse files Browse the repository at this point in the history
…s read when performing validation (#2746)

* refactor(chat-saga): create detached task for marking conversations as read when performing validation

* refactor: fix/update tests
  • Loading branch information
domw30 authored Mar 6, 2025
1 parent 61a0d20 commit 1eda40f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/store/chat/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe(performValidateActiveConversation, () => {
.call(getRoomIdForAlias, '#' + alias)
.not.call(apiJoinRoom, conversationId)
.put(rawSetActiveConversationId(conversationId))
.call(markConversationAsRead, conversationId)
.spawn(markConversationAsRead, conversationId)
.run();

expect(storeState.chat.activeConversationId).toBe(conversationId);
Expand Down Expand Up @@ -170,7 +170,7 @@ describe(performValidateActiveConversation, () => {
[matchers.call.fn(markConversationAsRead), undefined],
])
.put(rawSetActiveConversationId('social-channel'))
.call(markConversationAsRead, 'social-channel')
.spawn(markConversationAsRead, 'social-channel')
.not.call(openFirstConversation)
.run();
});
Expand All @@ -193,11 +193,11 @@ describe(performValidateActiveConversation, () => {
[matchers.call.fn(getHistory), history],
])
.put(rawSetActiveConversationId('convo-1'))
.call(markConversationAsRead, 'convo-1')
.spawn(markConversationAsRead, 'convo-1')
.run();
});

it('does not set active conversation ID if URL path has changed during validation', async () => {
it('does not set active conversation ID or mark conversation as read if URL path has changed during validation', async () => {
const initialState = new StoreBuilder()
.withCurrentUser({ id: 'current-user' })
.withConversationList({ id: 'convo-1', name: 'Conversation 1', otherMembers: [{ userId: 'user-2' } as User] });
Expand Down Expand Up @@ -229,7 +229,7 @@ describe(performValidateActiveConversation, () => {
},
])
.not.put(rawSetActiveConversationId('convo-1'))
.call(markConversationAsRead, 'convo-1')
.not.spawn(markConversationAsRead, 'convo-1')
.run();
});
});
Expand Down
5 changes: 2 additions & 3 deletions src/store/chat/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,9 @@ export function* performValidateActiveConversation(activeConversationId: string)
// check if path has changed before setting active conversation
if (currentPathNow === originalPath) {
yield put(rawSetActiveConversationId(conversationId));
// Mark conversation as read, now that it has been set as active
yield spawn(markConversationAsRead, conversationId);
}

// Mark conversation as read, now that it has been set as active
yield call(markConversationAsRead, conversationId);
}

export function* closeErrorDialog() {
Expand Down

0 comments on commit 1eda40f

Please sign in to comment.