Skip to content

Commit 22f50a6

Browse files
committed
accountsReducer: Store server feature level in Redux.
Firstly, we add zulipFeatureLevel in Account type. We had to tweak `loginSuccess()` and `realmAdd()` methods in accountsReducer to include `zulipFeatureLevel` in their return values too. Then, we store the feature level in Redux on REALM_ADD and REALM_INIT. Part of #4049.
1 parent 90901e1 commit 22f50a6

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

src/__tests__/lib/exampleData.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export const makeAccount = (
135135
email?: string,
136136
realm?: string,
137137
apiKey?: string,
138+
zulipFeatureLevel?: number | null,
138139
zulipVersion?: ZulipVersion | null,
139140
ackedPushToken?: string | null,
140141
} = {},
@@ -144,13 +145,15 @@ export const makeAccount = (
144145
email = user.email,
145146
realm: realmInner = realm,
146147
apiKey = randString() + randString(),
148+
zulipFeatureLevel: zulipFeatureLevelInner = zulipFeatureLevel,
147149
zulipVersion: zulipVersionInner = zulipVersion,
148150
ackedPushToken = null,
149151
} = args;
150152
return deepFreeze({
151153
realm: realmInner,
152154
email,
153155
apiKey,
156+
zulipFeatureLevel: zulipFeatureLevelInner,
154157
zulipVersion: zulipVersionInner,
155158
ackedPushToken,
156159
});

src/account/__tests__/accountsReducer-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ describe('accountsReducer', () => {
228228
229229
realm: 'https://new.realm.org',
230230
zulipVersion: null,
231+
zulipFeatureLevel: null,
231232
});
232233

233234
const action = deepFreeze({

src/account/accountsReducer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const realmAdd = (state, action) => {
2121
if (accountIndex !== -1) {
2222
const newAccount = {
2323
...state[accountIndex],
24+
zulipFeatureLevel: action.zulipFeatureLevel,
2425
zulipVersion: action.zulipVersion,
2526
};
2627
return [newAccount, ...state.slice(0, accountIndex), ...state.slice(accountIndex + 1)];
@@ -32,6 +33,7 @@ const realmAdd = (state, action) => {
3233
apiKey: '',
3334
email: '',
3435
ackedPushToken: null,
36+
zulipFeatureLevel: action.zulipFeatureLevel,
3537
zulipVersion: action.zulipVersion,
3638
},
3739
...state,
@@ -41,6 +43,7 @@ const realmAdd = (state, action) => {
4143
const realmInit = (state, action) => [
4244
{
4345
...state[0],
46+
zulipFeatureLevel: action.data.zulip_feature_level ?? 0,
4447
zulipVersion: action.zulipVersion,
4548
},
4649
...state.slice(1),
@@ -65,7 +68,10 @@ const loginSuccess = (state, action) => {
6568
const { realm, email, apiKey } = action;
6669
const accountIndex = findAccount(state, { realm, email });
6770
if (accountIndex === -1) {
68-
return [{ realm, email, apiKey, ackedPushToken: null, zulipVersion: null }, ...state];
71+
return [
72+
{ realm, email, apiKey, ackedPushToken: null, zulipVersion: null, zulipFeatureLevel: null },
73+
...state,
74+
];
6975
}
7076
return [
7177
{ ...state[accountIndex], email, apiKey, ackedPushToken: null },

src/boot/store.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ const migrations: { [string]: (GlobalState) => GlobalState } = {
179179
})),
180180
}),
181181

182+
// Added Accounts.zulipFeatureLevel as number | null
183+
'14': state => ({
184+
...state,
185+
accounts: state.accounts.map(a => ({
186+
...a,
187+
zulipFeatureLevel: null,
188+
})),
189+
}),
190+
182191
// TIP: When adding a migration, consider just using `dropCache`.
183192
};
184193

src/types.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ export type Account = {|
6565
*/
6666
zulipVersion: ZulipVersion | null,
6767

68+
/**
69+
* An integer indicating what features are available on the server.
70+
*
71+
* The feature level increases monotonically; a value of N means the
72+
* server supports all API features introduced before feature level N.
73+
* This is designed to provide a simple way for mobile apps to decide
74+
* whether the server supports a given feature or API change.
75+
*
76+
* Like zulipVersion, we learn the feature level from /server_settings
77+
* at the start of the login process, and again from /register when
78+
* setting up an event queue.
79+
*/
80+
zulipFeatureLevel: number | null,
81+
6882
/**
6983
* The last device token value the server has definitely heard from us.
7084
*

0 commit comments

Comments
 (0)