Skip to content

Commit c40af51

Browse files
committed
model: Add TODOs to remove aging fallbacks, once less risky
1 parent f378c31 commit c40af51

File tree

10 files changed

+57
-8
lines changed

10 files changed

+57
-8
lines changed

src/alertWords/__tests__/alertWordsReducer-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('alertWordsReducer', () => {
2020
expect(actualState).toEqual(expectedState);
2121
});
2222

23+
// TODO(#5102): Delete; see comment on implementation.
2324
test('when no `alert_words` data is given reset state', () => {
2425
const initialState = deepFreeze(['word']);
2526
const action = deepFreeze({

src/alertWords/alertWordsReducer.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ export default (
1515
return initialState;
1616

1717
case REGISTER_COMPLETE:
18-
return action.data.alert_words || initialState;
18+
return (
19+
action.data.alert_words
20+
// TODO(#5102): Delete fallback once we enforce any threshold for
21+
// ancient servers we refuse to connect to. It was added in #2878
22+
// (2018-11-16), but it wasn't clear even then, it seems, whether
23+
// any servers actually omit the data. The API doc doesn't mention
24+
// any servers that omit it, and our Flow types mark it required.
25+
|| initialState
26+
);
1927

2028
case EVENT_ALERT_WORDS:
2129
return action.alert_words || initialState;

src/mute/__tests__/muteModel-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe('reducer', () => {
3030
expect(newState && getMute(newState)).toEqual(makeMuteState([[eg.stream, 'topic']]));
3131
});
3232

33+
// TODO(#5102): Delete; see comment on implementation.
3334
test('when no `mute` data is given reset state', () => {
3435
const state = makeMuteState([[eg.stream, 'topic']]);
3536
const action = eg.mkActionRegisterComplete({ muted_topics: [] });

src/mute/muteModel.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,17 @@ export const reducer = (
5555
// We require this `globalState` to reflect the `streams` sub-reducer
5656
// already having run, so that `getStreamsByName` gives the data we
5757
// just received. See this sub-reducer's call site in `reducers.js`.
58-
return convert(action.data.muted_topics ?? [], getStreamsByName(globalState));
58+
return convert(
59+
action.data.muted_topics
60+
// TODO(#5102): Delete fallback once we enforce any threshold for
61+
// ancient servers we refuse to connect to. It was added in
62+
// #2878 (2018-11-16), but it wasn't clear even then, it seems,
63+
// whether any servers actually omit the data. The API doc
64+
// doesn't mention any servers that omit it, and our Flow types
65+
// mark it required.
66+
?? [],
67+
getStreamsByName(globalState),
68+
);
5969

6070
case EVENT_MUTED_TOPICS:
6171
return convert(action.muted_topics, getStreamsByName(globalState));

src/presence/__tests__/presenceReducer-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('presenceReducer', () => {
4747
expect(actualState).toEqual(presenceData);
4848
});
4949

50+
// TODO(#5102): Delete; see comment on implementation.
5051
test('when no `presence` data is given reset state', () => {
5152
const initialState = deepFreeze({
5253

src/presence/presenceReducer.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ export default (
2525
return initialState;
2626

2727
case REGISTER_COMPLETE:
28-
return action.data.presences || initialState;
28+
return (
29+
action.data.presences
30+
// TODO(#5102): Delete fallback once we enforce any threshold for
31+
// ancient servers we refuse to connect to. It was added in
32+
// #2878 (2018-11-16), but it wasn't clear even then, it seems,
33+
// whether any servers actually omit the data. The API doc
34+
// doesn't mention any servers that omit it, and our Flow types
35+
// mark it required.
36+
|| initialState
37+
);
2938

3039
case PRESENCE_RESPONSE:
3140
return {

src/unread/unreadHuddlesReducer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ export default (
9696
return initialState;
9797

9898
case REGISTER_COMPLETE:
99-
return (action.data.unread_msgs && action.data.unread_msgs.huddles) || initialState;
99+
return (
100+
(action.data.unread_msgs && action.data.unread_msgs.huddles)
101+
// TODO(#5102): Delete fallback once we refuse to connect to Zulip
102+
// servers before 1.7.0, when it seems this feature was added; see
103+
// comment on InitialDataUpdateMessageFlags.
104+
|| initialState
105+
);
100106

101107
case EVENT_NEW_MESSAGE:
102108
return eventNewMessage(state, action);

src/unread/unreadMentionsReducer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ export default (
5454
return initialState;
5555

5656
case REGISTER_COMPLETE:
57-
return (action.data.unread_msgs && action.data.unread_msgs.mentions) || initialState;
57+
return (
58+
(action.data.unread_msgs && action.data.unread_msgs.mentions)
59+
// TODO(#5102): Delete fallback once we refuse to connect to Zulip
60+
// servers before 1.7.0, when it seems this feature was added; see
61+
// comment on InitialDataUpdateMessageFlags.
62+
|| initialState
63+
);
5864

5965
case EVENT_NEW_MESSAGE: {
6066
const { flags } = action.message;

src/unread/unreadModel.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,9 @@ function streamsReducer(
230230
return initialStreamsState;
231231

232232
case REGISTER_COMPLETE: {
233-
// This may indeed be unnecessary, but it's legacy; have not investigated
234-
// if it's this bit of our API types that is too optimistic.
233+
// TODO(#5102): Delete fallback once we refuse to connect to Zulip
234+
// servers before 1.7.0, when it seems this feature was added; see
235+
// comment on InitialDataUpdateMessageFlags.
235236
// flowlint-next-line unnecessary-optional-chain:off
236237
const data = action.data.unread_msgs?.streams ?? [];
237238

src/unread/unreadPmsReducer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ export default (
9696
return initialState;
9797

9898
case REGISTER_COMPLETE:
99-
return (action.data.unread_msgs && action.data.unread_msgs.pms) || initialState;
99+
return (
100+
(action.data.unread_msgs && action.data.unread_msgs.pms)
101+
// TODO(#5102): Delete fallback once we refuse to connect to Zulip
102+
// servers before 1.7.0, when it seems this feature was added; see
103+
// comment on InitialDataUpdateMessageFlags.
104+
|| initialState
105+
);
100106

101107
case EVENT_NEW_MESSAGE:
102108
return eventNewMessage(state, action);

0 commit comments

Comments
 (0)