Skip to content

Commit efe7ca9

Browse files
committed
api: Mark {InitialSnapshot,PerAccountStore}.userSettings as required, relying on server 5+, FL 89+
See "Feature level 89" from Zulip API changelog: https://zulip.com/api/changelog Signed-off-by: Zixuan James Li <[email protected]>
1 parent f8da37f commit efe7ca9

File tree

6 files changed

+14
-22
lines changed

6 files changed

+14
-22
lines changed

lib/api/model/initial_snapshot.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,7 @@ class InitialSnapshot {
5555

5656
final List<ZulipStream> streams;
5757

58-
// Servers pre-5.0 don't have `user_settings`, and instead provide whatever
59-
// user settings they support at toplevel in the initial snapshot. Since we're
60-
// likely to desupport pre-5.0 servers before wide release, we prefer to
61-
// ignore the toplevel fields and use `user_settings` where present instead,
62-
// even at the expense of functionality with pre-5.0 servers.
63-
// TODO(server-5) remove pre-5.0 comment
64-
final UserSettings? userSettings; // TODO(server-5)
58+
final UserSettings userSettings;
6559

6660
final List<UserTopicItem>? userTopics; // TODO(server-6)
6761

lib/api/model/initial_snapshot.g.dart

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/model/store.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
334334
/// Always equal to `account.userId`.
335335
final int selfUserId;
336336

337-
final UserSettings? userSettings; // TODO(server-5)
337+
final UserSettings userSettings;
338338

339339
////////////////////////////////
340340
// Users and data about them.
@@ -435,11 +435,11 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
435435
}
436436
switch (event.property!) {
437437
case UserSettingName.twentyFourHourTime:
438-
userSettings?.twentyFourHourTime = event.value as bool;
438+
userSettings.twentyFourHourTime = event.value as bool;
439439
case UserSettingName.displayEmojiReactionUsers:
440-
userSettings?.displayEmojiReactionUsers = event.value as bool;
440+
userSettings.displayEmojiReactionUsers = event.value as bool;
441441
case UserSettingName.emojiset:
442-
userSettings?.emojiset = event.value as Emojiset;
442+
userSettings.emojiset = event.value as Emojiset;
443443
}
444444
notifyListeners();
445445

lib/widgets/emoji_reaction.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class ReactionChipsList extends StatelessWidget {
117117
@override
118118
Widget build(BuildContext context) {
119119
final store = PerAccountStoreWidget.of(context);
120-
final displayEmojiReactionUsers = store.userSettings?.displayEmojiReactionUsers ?? false;
120+
final displayEmojiReactionUsers = store.userSettings.displayEmojiReactionUsers ?? false;
121121
final showNames = displayEmojiReactionUsers && reactions.total <= 3;
122122

123123
return Wrap(spacing: 4, runSpacing: 4, crossAxisAlignment: WrapCrossAlignment.center,
@@ -149,7 +149,7 @@ class ReactionChip extends StatelessWidget {
149149
final emojiName = reactionWithVotes.emojiName;
150150
final userIds = reactionWithVotes.userIds;
151151

152-
final emojiset = store.userSettings?.emojiset ?? Emojiset.google;
152+
final emojiset = store.userSettings.emojiset;
153153

154154
final selfVoted = userIds.contains(store.selfUserId);
155155
final label = showName

test/model/store_checks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extension PerAccountStoreChecks on Subject<PerAccountStore> {
3838
Subject<int> get accountId => has((x) => x.accountId, 'accountId');
3939
Subject<Account> get account => has((x) => x.account, 'account');
4040
Subject<int> get selfUserId => has((x) => x.selfUserId, 'selfUserId');
41-
Subject<UserSettings?> get userSettings => has((x) => x.userSettings, 'userSettings');
41+
Subject<UserSettings> get userSettings => has((x) => x.userSettings, 'userSettings');
4242
Subject<Map<int, User>> get users => has((x) => x.users, 'users');
4343
Subject<Map<int, ZulipStream>> get streams => has((x) => x.streams, 'streams');
4444
Subject<Map<String, ZulipStream>> get streamsByName => has((x) => x.streamsByName, 'streamsByName');

test/model/store_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,15 @@ void main() {
380380
updateMachine.poll();
381381

382382
// Pick some arbitrary event and check it gets processed on the store.
383-
check(store.userSettings!.twentyFourHourTime).isFalse();
383+
check(store.userSettings.twentyFourHourTime).isFalse();
384384
connection.prepare(json: GetEventsResult(events: [
385385
UserSettingsUpdateEvent(id: 2,
386386
property: UserSettingName.twentyFourHourTime, value: true),
387387
], queueId: null).toJson());
388388
updateMachine.debugAdvanceLoop();
389389
async.flushMicrotasks();
390390
await Future<void>.delayed(Duration.zero);
391-
check(store.userSettings!.twentyFourHourTime).isTrue();
391+
check(store.userSettings.twentyFourHourTime).isTrue();
392392
}));
393393

394394
test('handles expired queue', () => awaitFakeAsync((async) async {
@@ -416,15 +416,15 @@ void main() {
416416
// The new UpdateMachine updates the new store.
417417
updateMachine.debugPauseLoop();
418418
updateMachine.poll();
419-
check(store.userSettings!.twentyFourHourTime).isFalse();
419+
check(store.userSettings.twentyFourHourTime).isFalse();
420420
connection.prepare(json: GetEventsResult(events: [
421421
UserSettingsUpdateEvent(id: 2,
422422
property: UserSettingName.twentyFourHourTime, value: true),
423423
], queueId: null).toJson());
424424
updateMachine.debugAdvanceLoop();
425425
async.flushMicrotasks();
426426
await Future<void>.delayed(Duration.zero);
427-
check(store.userSettings!.twentyFourHourTime).isTrue();
427+
check(store.userSettings.twentyFourHourTime).isTrue();
428428
}));
429429

430430
void checkRetry(void Function() prepareError) {

0 commit comments

Comments
 (0)