Skip to content

Commit 4868baa

Browse files
committed
flags model: Fix bug where mark-all-as-read would *add* unread markers
(Edit: Actually, the previous commit changed the symptom of #5597, making this commit message a bit inaccurate. At this point, things have changed so that "Mark as read" won't add unread markers, it'll just fail to remove them. See discussion on the PR.) You're not meant to use Object.keys on an Immutable.Map; details at issue #5597 for how this caused a display-only bug where messages in view would get marked with unread markers. Greg points out, at #5597 (comment) > If we'd had type-checking on those tests, Flow would have pointed > out that the test data needed to change when we changed the > definition of `MessagesState`, which would have alerted us that > `flagsReducer` was consuming data of that type and given us a > better chance to see we needed to update that logic. We'll start type-checking flagsReducer-test.js soon. But for now, just for this one test, give input that's unchecked but well formed, and fix the reducer's implementation. The fixed test passes with this new reducer implementation, and it would fail with the old, buggy implementation. Fixes: #5597
1 parent 844d7e5 commit 4868baa

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/chat/__tests__/flagsReducer-test.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import deepFreeze from 'deep-freeze';
22

3+
import * as eg from '../../__tests__/lib/exampleData';
34
import flagsReducer from '../flagsReducer';
45
import {
56
MESSAGE_FETCH_COMPLETE,
@@ -280,40 +281,42 @@ describe('flagsReducer', () => {
280281
});
281282

282283
test('when all=true, flag=read, and op=add, all messages become read; other flags untouched', () => {
284+
const message1 = eg.streamMessage();
285+
const message2 = eg.streamMessage();
286+
const message3 = eg.streamMessage();
287+
const message4 = eg.streamMessage();
288+
const message5 = eg.streamMessage();
289+
283290
const prevState = deepFreeze({
291+
...eg.plusReduxState.flags,
284292
starred: {
285-
1: true,
286-
4: true,
293+
[message1.id]: true,
294+
[message4.id]: true,
287295
},
288296
read: {
289-
1: true,
290-
3: true,
297+
[message1.id]: true,
298+
[message3.id]: true,
291299
},
292300
});
293301

294302
const action = deepFreeze({
303+
id: 1,
295304
type: EVENT_UPDATE_MESSAGE_FLAGS,
305+
all: true,
306+
allMessages: eg.makeMessagesState([message1, message2, message3, message4, message5]),
296307
messages: [],
297308
flag: 'read',
298309
op: 'add',
299-
all: true,
300-
allMessages: {
301-
1: {},
302-
2: {},
303-
3: {},
304-
4: {},
305-
5: {},
306-
},
307310
});
308311

309312
const expectedState = {
310313
...prevState,
311314
read: {
312-
1: true,
313-
2: true,
314-
3: true,
315-
4: true,
316-
5: true,
315+
[message1.id]: true,
316+
[message2.id]: true,
317+
[message3.id]: true,
318+
[message4.id]: true,
319+
[message5.id]: true,
317320
},
318321
};
319322

src/chat/flagsReducer.js

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

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

0 commit comments

Comments
 (0)