Skip to content

Commit abfbd62

Browse files
chrisbobbegnprice
authored andcommitted
api: Transform zulip_{version,feature_level} in registerForEvents
Instead of doing so in accountsReducer.
1 parent b792652 commit abfbd62

File tree

6 files changed

+27
-13
lines changed

6 files changed

+27
-13
lines changed

src/__tests__/lib/exampleData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ export const action = Object.freeze({
723723
msg: '',
724724
queue_id: '1',
725725
zulip_feature_level: recentZulipFeatureLevel,
726-
zulip_version: recentZulipVersion.raw(),
726+
zulip_version: recentZulipVersion,
727727

728728
// InitialDataAlertWords
729729
alert_words: [],

src/account/__tests__/accountsReducer-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('accountsReducer', () => {
2626
expect(
2727
accountsReducer(
2828
deepFreeze([account1, account2, account3]),
29-
eg.mkActionRegisterComplete({ zulip_version: newZulipVersion.raw() }),
29+
eg.mkActionRegisterComplete({ zulip_version: newZulipVersion }),
3030
),
3131
).toEqual([{ ...account1, zulipVersion: newZulipVersion }, account2, account3]);
3232
});

src/account/accountsReducer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const registerComplete = (state, action) => [
2121
{
2222
...state[0],
2323
userId: action.data.user_id,
24-
zulipFeatureLevel: action.data.zulip_feature_level ?? 0,
25-
zulipVersion: new ZulipVersion(action.data.zulip_version),
24+
zulipFeatureLevel: action.data.zulip_feature_level,
25+
zulipVersion: action.data.zulip_version,
2626
lastDismissedServerPushSetupNotice: action.data.realm_push_notifications_enabled
2727
? null
2828
: state[0].lastDismissedServerPushSetupNotice,

src/api/initialDataTypes.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type {
2121
CreateWebPublicStreamPolicy,
2222
EmailAddressVisibility,
2323
} from './permissionsTypes';
24+
import type { ZulipVersion } from '../utils/zulipVersion';
2425

2526
/*
2627
The types in this file are organized by which `fetch_event_types` values
@@ -29,12 +30,7 @@ import type {
2930
See comments at `InitialData`, at the bottom, for details.
3031
*/
3132

32-
/**
33-
* The parts of the `/register` response sent regardless of `fetch_event_types`.
34-
*
35-
* See `InitialData` for more discussion.
36-
*/
37-
export type InitialDataBase = $ReadOnly<{|
33+
export type RawInitialDataBase = $ReadOnly<{|
3834
last_event_id: number,
3935
msg: string,
4036
queue_id: string,
@@ -52,7 +48,7 @@ export type InitialDataBase = $ReadOnly<{|
5248
* Same meaning as in the server_settings response:
5349
* https://zulip.com/api/get-server-settings. See also the comment above.
5450
*/
55-
// TODO(server-3.0): Mark as required.
51+
// TODO(server-3.0): Mark as required; remove missing-to-zero transform
5652
zulip_feature_level?: number,
5753

5854
/**
@@ -64,6 +60,20 @@ export type InitialDataBase = $ReadOnly<{|
6460
zulip_version: string,
6561
|}>;
6662

63+
/**
64+
* The parts of the `/register` response sent regardless of `fetch_event_types`.
65+
*
66+
* Post-transformation. For what we expect directly from the server, see
67+
* RawInitialDataBase.
68+
*
69+
* See `InitialData` for more discussion.
70+
*/
71+
export type InitialDataBase = $ReadOnly<{|
72+
...RawInitialDataBase,
73+
zulip_feature_level: number, // filled in with zero if missing
74+
zulip_version: ZulipVersion, // parsed from string
75+
|}>;
76+
6777
export type InitialDataAlertWords = $ReadOnly<{|
6878
alert_words: $ReadOnlyArray<string>,
6979
|}>;
@@ -716,6 +726,7 @@ export type InitialData = {|
716726
*/
717727
export type RawInitialData = $ReadOnly<{|
718728
...InitialData,
729+
...RawInitialDataBase,
719730
...RawInitialDataRealmUser,
720731
...RawInitialDataRealmFilters,
721732
|}>;

src/api/registerForEvents.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { Auth } from './transportTypes';
66
import type { CrossRealmBot, User } from './modelTypes';
77
import { apiPost } from './apiFetch';
88
import { AvatarURL } from '../utils/avatar';
9+
import { ZulipVersion } from '../utils/zulipVersion';
910

1011
const transformUser = (rawUser: {| ...User, avatar_url?: string | null |}, realm: URL): User => {
1112
const { avatar_url: rawAvatarUrl, email } = rawUser;
@@ -36,6 +37,9 @@ const transformCrossRealmBot = (
3637
const transform = (rawInitialData: RawInitialData, auth: Auth): InitialData => ({
3738
...rawInitialData,
3839

40+
zulip_feature_level: rawInitialData.zulip_feature_level ?? 0,
41+
zulip_version: new ZulipVersion(rawInitialData.zulip_version),
42+
3943
// Transform the newer `realm_linkifiers` format, if present, to the
4044
// older `realm_filters` format. We do the same transformation on
4145
// 'realm_linkifiers' events.

src/events/eventActions.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { BackoffMachine, TimeoutError } from '../utils/async';
2323
import { ApiError, RequestError, Server5xxError, NetworkError } from '../api/apiErrors';
2424
import * as logging from '../utils/logging';
2525
import { showErrorAlert } from '../utils/info';
26-
import { ZulipVersion } from '../utils/zulipVersion';
2726
import { tryFetch, fetchPrivateMessages } from '../message/fetchActions';
2827
import { MIN_RECENTPMS_SERVER_VERSION } from '../pm-conversations/pmConversationsModel';
2928
import { sendOutbox } from '../outbox/outboxActions';
@@ -171,7 +170,7 @@ export const registerAndStartPolling =
171170
return;
172171
}
173172

174-
const serverVersion = new ZulipVersion(initData.zulip_version);
173+
const serverVersion = initData.zulip_version;
175174

176175
// Set Sentry tags for the server version immediately, so they're accurate
177176
// in case we hit an exception in reducers on `registerComplete` below.

0 commit comments

Comments
 (0)