Skip to content

Commit e431d68

Browse files
domw30colbr
authored andcommitted
refactor(chat-saga): create detached task for marking conversations as read when performing validation (#2746)
* refactor(chat-saga): create detached task for marking conversations as read when performing validation * refactor: fix/update tests
1 parent c48b11c commit e431d68

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/store/chat/saga.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe(performValidateActiveConversation, () => {
8181
.call(getRoomIdForAlias, '#' + alias)
8282
.not.call(apiJoinRoom, conversationId)
8383
.put(rawSetActiveConversationId(conversationId))
84-
.call(markConversationAsRead, conversationId)
84+
.spawn(markConversationAsRead, conversationId)
8585
.run();
8686

8787
expect(storeState.chat.activeConversationId).toBe(conversationId);
@@ -170,7 +170,7 @@ describe(performValidateActiveConversation, () => {
170170
[matchers.call.fn(markConversationAsRead), undefined],
171171
])
172172
.put(rawSetActiveConversationId('social-channel'))
173-
.call(markConversationAsRead, 'social-channel')
173+
.spawn(markConversationAsRead, 'social-channel')
174174
.not.call(openFirstConversation)
175175
.run();
176176
});
@@ -193,11 +193,11 @@ describe(performValidateActiveConversation, () => {
193193
[matchers.call.fn(getHistory), history],
194194
])
195195
.put(rawSetActiveConversationId('convo-1'))
196-
.call(markConversationAsRead, 'convo-1')
196+
.spawn(markConversationAsRead, 'convo-1')
197197
.run();
198198
});
199199

200-
it('does not set active conversation ID if URL path has changed during validation', async () => {
200+
it('does not set active conversation ID or mark conversation as read if URL path has changed during validation', async () => {
201201
const initialState = new StoreBuilder()
202202
.withCurrentUser({ id: 'current-user' })
203203
.withConversationList({ id: 'convo-1', name: 'Conversation 1', otherMembers: [{ userId: 'user-2' } as User] });
@@ -229,7 +229,7 @@ describe(performValidateActiveConversation, () => {
229229
},
230230
])
231231
.not.put(rawSetActiveConversationId('convo-1'))
232-
.call(markConversationAsRead, 'convo-1')
232+
.not.spawn(markConversationAsRead, 'convo-1')
233233
.run();
234234
});
235235
});

src/store/chat/saga.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,9 @@ export function* performValidateActiveConversation(activeConversationId: string)
217217
// check if path has changed before setting active conversation
218218
if (currentPathNow === originalPath) {
219219
yield put(rawSetActiveConversationId(conversationId));
220+
// Mark conversation as read, now that it has been set as active
221+
yield spawn(markConversationAsRead, conversationId);
220222
}
221-
222-
// Mark conversation as read, now that it has been set as active
223-
yield call(markConversationAsRead, conversationId);
224223
}
225224

226225
export function* closeErrorDialog() {

0 commit comments

Comments
 (0)