Skip to content

Commit

Permalink
model: Remove various fallbacks for ancient, sometimes prehistoric se…
Browse files Browse the repository at this point in the history
…rvers

This completes all our `TODO(zulip#5102)`s.
  • Loading branch information
chrisbobbe committed Mar 31, 2023
1 parent b303fda commit cbf8b3a
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 81 deletions.
20 changes: 0 additions & 20 deletions src/alertWords/__tests__/alertWordsReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,6 @@ describe('alertWordsReducer', () => {
),
).toEqual(['word', '@mobile-core', 'alert']);
});

// TODO(#5102): Delete; see comment on implementation.
test('when no `alert_words` data is given reset state', () => {
const prevState = deepFreeze(['word']);
const actualState = alertWordsReducer(
prevState,
eg.mkActionRegisterComplete({
// Hmm, we should need a Flow suppression here. This property is
// marked required in InitialData, and this explicit undefined is
// meant to defy that; see TODO(#5102) above.
// mkActionRegisterComplete is designed to accept input with this or
// any property *omitted*… and I think, as a side effect of handling
// that, Flow mistakenly accepts an explicit undefined here, so it
// doesn't catch the resulting malformed InitialData.
alert_words: undefined,
}),
);

expect(actualState).toEqual([]);
});
});

describe('EVENT_ALERT_WORDS', () => {
Expand Down
10 changes: 1 addition & 9 deletions src/alertWords/alertWordsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@ export default (
return initialState;

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

case EVENT_ALERT_WORDS:
return action.alert_words || initialState;
Expand Down
4 changes: 0 additions & 4 deletions src/api/initialDataTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,6 @@ export type InitialDataRealmUser = $ReadOnly<{|
|}>;

export type InitialDataRealmUserGroups = $ReadOnly<{|
// New in Zulip 1.8.
// TODO(#5102): In userGroupsReducer, we still have a fallback for pre-1.8
// servers; remove that, and remove the above comment, which will be
// irrelevant.
realm_user_groups: $ReadOnlyArray<UserGroup>,
|}>;

Expand Down
8 changes: 1 addition & 7 deletions src/unread/unreadHuddlesReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,7 @@ export default (
return initialState;

case REGISTER_COMPLETE:
return (
(action.data.unread_msgs && action.data.unread_msgs.huddles)
// TODO(#5102): Delete fallback once we refuse to connect to Zulip
// servers before 1.7.0, when it seems this feature was added; see
// comment on InitialDataUpdateMessageFlags.
|| initialState
);
return action.data.unread_msgs.huddles;

case EVENT_NEW_MESSAGE:
return eventNewMessage(state, action);
Expand Down
8 changes: 1 addition & 7 deletions src/unread/unreadMentionsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ export default (
return initialState;

case REGISTER_COMPLETE:
return (
(action.data.unread_msgs && action.data.unread_msgs.mentions)
// TODO(#5102): Delete fallback once we refuse to connect to Zulip
// servers before 1.7.0, when it seems this feature was added; see
// comment on InitialDataUpdateMessageFlags.
|| initialState
);
return action.data.unread_msgs.mentions;

case EVENT_NEW_MESSAGE: {
const { flags } = action.message;
Expand Down
6 changes: 1 addition & 5 deletions src/unread/unreadModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ function streamsReducer(
return initialStreamsState;

case REGISTER_COMPLETE: {
// TODO(#5102): Delete fallback once we refuse to connect to Zulip
// servers before 1.7.0, when it seems this feature was added; see
// comment on InitialDataUpdateMessageFlags.
// flowlint-next-line unnecessary-optional-chain:off
const data = action.data.unread_msgs?.streams ?? [];
const data = action.data.unread_msgs.streams;

// First, collect together all the data for a given stream, just in a
// plain old Array.
Expand Down
8 changes: 1 addition & 7 deletions src/unread/unreadPmsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,7 @@ export default (
return initialState;

case REGISTER_COMPLETE:
return (
(action.data.unread_msgs && action.data.unread_msgs.pms)
// TODO(#5102): Delete fallback once we refuse to connect to Zulip
// servers before 1.7.0, when it seems this feature was added; see
// comment on InitialDataUpdateMessageFlags.
|| initialState
);
return action.data.unread_msgs.pms;

case EVENT_NEW_MESSAGE:
return eventNewMessage(state, action);
Expand Down
20 changes: 0 additions & 20 deletions src/user-groups/__tests__/userGroupsReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,6 @@ describe('userGroupsReducer', () => {
userGroupsReducer(prevState, eg.mkActionRegisterComplete({ realm_user_groups: [group] })),
).toEqual([group]);
});

// TODO(#5102): Remove this test case, which is for pre-1.8 servers.
test('when no data is given reset state', () => {
const prevState = deepFreeze([eg.makeUserGroup()]);
expect(
userGroupsReducer(
prevState,
eg.mkActionRegisterComplete({
// Hmm, we should need a Flow suppression here. This property is
// marked required in InitialData, and this explicit undefined is
// meant to defy that; see TODO(#5102) above.
// mkActionRegisterComplete is designed to accept input with this or
// any property *omitted*… and I think, as a side effect of handling
// that, Flow mistakenly accepts an explicit undefined here, so it
// doesn't catch the resulting malformed InitialData.
realm_user_groups: undefined,
}),
),
).toEqual([]);
});
});

describe('RESET_ACCOUNT_DATA', () => {
Expand Down
3 changes: 1 addition & 2 deletions src/user-groups/userGroupsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ export default (
return initialState;

case REGISTER_COMPLETE:
// TODO(#5102): Remove fallback for pre-1.8 servers
return action.data.realm_user_groups || initialState;
return action.data.realm_user_groups;

case EVENT_USER_GROUP_ADD:
return [...state, action.group];
Expand Down

0 comments on commit cbf8b3a

Please sign in to comment.