Skip to content

Commit f391df7

Browse files
committed
accountsReducer: Make REALM_ADD store 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. Part of #4049.
1 parent b9f1028 commit f391df7

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

src/__tests__/lib/exampleData.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export const makeAccount = (
123123
email?: string,
124124
realm?: string,
125125
apiKey?: string,
126+
zulipFeatureLevel?: number | null,
126127
zulipVersion?: ZulipVersion | null,
127128
ackedPushToken?: string | null,
128129
} = {},
@@ -132,13 +133,15 @@ export const makeAccount = (
132133
email = user.email,
133134
realm: realmInner = realm,
134135
apiKey = randString() + randString(),
136+
zulipFeatureLevel: zulipFeatureLevelInner = zulipFeatureLevel,
135137
zulipVersion: zulipVersionInner = zulipVersion,
136138
ackedPushToken = null,
137139
} = args;
138140
return deepFreeze({
139141
realm: realmInner,
140142
email,
141143
apiKey,
144+
zulipFeatureLevel: zulipFeatureLevelInner,
142145
zulipVersion: zulipVersionInner,
143146
ackedPushToken,
144147
});

src/account/__tests__/accountsReducer-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ describe('accountsReducer', () => {
171171
172172
realm: 'https://new.realm.org',
173173
zulipVersion: null,
174+
zulipFeatureLevel: null,
174175
});
175176

176177
const action = deepFreeze({

src/account/accountsReducer.js

Lines changed: 6 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,
@@ -65,7 +67,10 @@ const loginSuccess = (state, action) => {
6567
const { realm, email, apiKey } = action;
6668
const accountIndex = findAccount(state, { realm, email });
6769
if (accountIndex === -1) {
68-
return [{ realm, email, apiKey, ackedPushToken: null, zulipVersion: null }, ...state];
70+
return [
71+
{ realm, email, apiKey, ackedPushToken: null, zulipVersion: null, zulipFeatureLevel: null },
72+
...state,
73+
];
6974
}
7075
return [
7176
{ ...state[accountIndex], email, apiKey, ackedPushToken: null },

src/types.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ export type Account = {|
9595
*/
9696
zulipVersion: ZulipVersion | null,
9797

98+
/**
99+
* An integer indicating what features are available on the server.
100+
*
101+
* The feature level increases monotonically; a value of N means the
102+
* server supports all API features introduced before feature level N.
103+
* This is designed to provide a simple way for mobile apps to decide
104+
* whether the server supports a given feature or API change.
105+
*/
106+
zulipFeatureLevel: number | null,
107+
98108
/**
99109
* The last device token value the server has definitely heard from us.
100110
*

0 commit comments

Comments
 (0)