Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model: Remove various fallbacks for ancient, sometimes prehistoric servers #5706

Merged
merged 4 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 0 additions & 1 deletion src/message/fetchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ export async function fetchServerSettings(realm: URL): Promise<
> {
try {
return { type: 'success', value: await api.getServerSettings(realm) };
// TODO(#5102): Disallow connecting to ancient servers
} catch (errorIllTyped) {
const error: mixed = errorIllTyped;

Expand Down
10 changes: 0 additions & 10 deletions src/mute/__tests__/muteModel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,6 @@ describe('reducer', () => {
expect(newState).toBeTruthy();
expect(newState && getMute(newState)).toEqual(makeMuteState([[eg.stream, 'topic']]));
});

// TODO(#5102): Delete; see comment on implementation.
test('in ancient no-muted-topics format', () => {
const state = makeMuteState([[eg.stream, 'topic']]);
const action = eg.mkActionRegisterComplete({
muted_topics: undefined,
user_topics: undefined,
});
expect(reducer(state, action, eg.plusReduxState)).toEqual(initialState);
});
});

describe('RESET_ACCOUNT_DATA', () => {
Expand Down
10 changes: 4 additions & 6 deletions src/mute/muteModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ export const reducer = (
// TODO(server-6.0): Stop caring about that, when we cut muted_topics.
return convertLegacy(
action.data.muted_topics
// 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.
// Unnecessary fallback just to satisfy Flow: the old
// `muted_topics` is absent only when the new `user_topics` is
// present (ignoring ancient unsupported servers), but Flow
// doesn't track that.
?? [],
getStreamsByName(globalState),
);
Expand Down
22 changes: 0 additions & 22 deletions src/presence/__tests__/presenceModel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,28 +224,6 @@ describe('presenceReducer', () => {
const expectedState = makePresenceState([[user, userPresence]]);
expect(presenceReducer(prevState, action)).toEqual(expectedState);
});

// TODO(#5102): Delete; see comment on implementation.
test('when no `presence` data is given reset state', () => {
const user = eg.otherUser;
const userPresence = {
aggregated: { client: 'website', status: 'active', timestamp: 123 },
website: { client: 'website', status: 'active', timestamp: 123 },
};
const prevState = makePresenceState([[user, userPresence]]);
const action = 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.
presences: undefined,
});
const expectedState = makePresenceState([]);
expect(presenceReducer(prevState, action)).toEqual(expectedState);
});
});

describe('PRESENCE_RESPONSE', () => {
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