Skip to content

Commit 662b122

Browse files
committed
realm state: Store presenceEnabled
1 parent b8b74e6 commit 662b122

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

src/realm/__tests__/realmReducer-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ describe('realmReducer', () => {
9191
/* $FlowIgnore[incompatible-use] - testing modern servers, which
9292
send user_settings. */
9393
twentyFourHourTime: action.data.user_settings.twenty_four_hour_time,
94+
// $FlowIgnore[incompatible-use] - see above
95+
presenceEnabled: action.data.user_settings.presence_enabled,
9496

9597
//
9698
// Misc.: Not in the /register response. (These should be unchanged.)
@@ -330,6 +332,14 @@ describe('realmReducer', () => {
330332
check(false, true);
331333
check(false, false);
332334
});
335+
336+
describe('presenceEnabled / presence_enabled', () => {
337+
const check = mkCheck('presenceEnabled', 'presence_enabled');
338+
check(true, true);
339+
check(true, false);
340+
check(false, true);
341+
check(false, false);
342+
});
333343
});
334344

335345
describe('type `realm`, op `update_dict`', () => {

src/realm/realmReducer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const initialState = {
7575
//
7676

7777
twentyFourHourTime: false,
78+
presenceEnabled: false,
7879

7980
//
8081
// Misc.: Not in the /register response.
@@ -194,6 +195,11 @@ export default (
194195
/* $FlowIgnore[incompatible-cast]: If `user_settings` is absent,
195196
this will be present. */
196197
?? (action.data.twenty_four_hour_time: boolean),
198+
199+
// Let this be null for servers that don't support the
200+
// user_settings_object client capability. Support begins at FL 89,
201+
// and we currently don't need this value when the server is pre-89.
202+
presenceEnabled: action.data.user_settings?.presence_enabled ?? null,
197203
};
198204
}
199205

@@ -300,6 +306,10 @@ export default (
300306
// $FlowFixMe[incompatible-cast] - fix UserSettingsUpdateEvent
301307
return { ...state, twentyFourHourTime: (value: boolean) };
302308
}
309+
case 'presence_enabled': {
310+
// $FlowFixMe[incompatible-cast] - fix UserSettingsUpdateEvent
311+
return { ...state, presenceEnabled: (value: boolean) };
312+
}
303313

304314
default:
305315
return state;

src/reduxTypes.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ export type RealmState = {|
335335

336336
+twentyFourHourTime: boolean,
337337

338+
// We let this be null if `user_settings` isn't supported, just because we
339+
// don't currently need the value for pre-FL 89 servers. If we start
340+
// needing it, we can fall back to the deprecated `presence_enabled`
341+
// directly on the /register response.
342+
// TODO(server-5.0): user_settings supported in FL 89; remove null case
343+
+presenceEnabled: boolean | null,
344+
338345
//
339346
// Misc.: Not in the /register response.
340347
//

src/storage/__tests__/migrations-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('migrations', () => {
104104
// What `base` becomes after all migrations.
105105
const endBase = {
106106
...base52,
107-
migrations: { version: 55 },
107+
migrations: { version: 56 },
108108
};
109109

110110
for (const [desc, before, after] of [
@@ -127,9 +127,9 @@ describe('migrations', () => {
127127
// redundant with this one, because none of the migration steps notice
128128
// whether any properties outside `storeKeys` are present or not.
129129
[
130-
'check dropCache at 55',
130+
'check dropCache at 56',
131131
// Just before the `dropCache`, plus a `cacheKeys` property, plus junk.
132-
{ ...base52, migrations: { version: 54 }, mute: [], nonsense: [1, 2, 3] },
132+
{ ...base52, migrations: { version: 55 }, mute: [], nonsense: [1, 2, 3] },
133133
// Should wind up with the same result as without the extra properties.
134134
endBase,
135135
],

src/storage/migrations.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,9 @@ const migrationsInner: {| [string]: (LessPartialState) => LessPartialState |} =
469469
// Drop old never-used message flags from state.flags.
470470
'55': dropCache,
471471

472+
// Add presenceEnabled to state.realm.
473+
'56': dropCache,
474+
472475
// TIP: When adding a migration, consider just using `dropCache`.
473476
// (See its jsdoc for guidance on when that's the right answer.)
474477
};

0 commit comments

Comments
 (0)