Skip to content

Commit 844d7e5

Browse files
committed
flags: Stop clearing all other flags on mark-all-as-read event
And improve a test so that it would catch this bug. Fixes: #5596
1 parent fccfa23 commit 844d7e5

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/chat/__tests__/flagsReducer-test.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,12 @@ describe('flagsReducer', () => {
279279
expect(actualState).toEqual(expectedState);
280280
});
281281

282-
test('when all=true, flag=read, and op=add, all messages become read', () => {
282+
test('when all=true, flag=read, and op=add, all messages become read; other flags untouched', () => {
283283
const prevState = deepFreeze({
284+
starred: {
285+
1: true,
286+
4: true,
287+
},
284288
read: {
285289
1: true,
286290
3: true,
@@ -302,16 +306,19 @@ describe('flagsReducer', () => {
302306
},
303307
});
304308

305-
const expectedReadState = {
306-
1: true,
307-
2: true,
308-
3: true,
309-
4: true,
310-
5: true,
309+
const expectedState = {
310+
...prevState,
311+
read: {
312+
1: true,
313+
2: true,
314+
3: true,
315+
4: true,
316+
5: true,
317+
},
311318
};
312319

313320
const actualState = flagsReducer(prevState, action);
314-
expect(actualState.read).toEqual(expectedReadState);
321+
expect(actualState).toEqual(expectedState);
315322
});
316323
});
317324

src/chat/flagsReducer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ const processFlagsForMessages = (
103103
const eventUpdateMessageFlags = (state, action) => {
104104
if (action.all) {
105105
if (action.op === 'add') {
106-
return addFlagsForMessages(initialState, Object.keys(action.allMessages).map(Number), [
107-
action.flag,
108-
]);
106+
return addFlagsForMessages(state, Object.keys(action.allMessages).map(Number), [action.flag]);
109107
}
110108

111109
if (action.op === 'remove') {

0 commit comments

Comments
 (0)