-
Notifications
You must be signed in to change notification settings - Fork 310
model: Start tracking a few user_settings
, including display_emoji_reaction_users
#261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3dd73cb
ee0504a
9cb2e4d
4bcbffd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
import 'model.dart'; | ||
|
@@ -30,6 +31,14 @@ class InitialSnapshot { | |
|
||
final List<ZulipStream> streams; | ||
|
||
// Servers pre-5.0 don't have `user_settings`, and instead provide whatever | ||
// user settings they support at toplevel in the initial snapshot. Since we're | ||
// likely to desupport pre-5.0 servers before wide release, we prefer to | ||
// ignore the toplevel fields and use `user_settings` where present instead, | ||
// even at the expense of functionality with pre-5.0 servers. | ||
// TODO(server-5) remove pre-5.0 comment | ||
Comment on lines
+34
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, sounds good. This does seem like a spot where properly supporting both old and new versions would be kind of a pain. (Would have been totally doable, if the timing were such that we had to — we'd probably use a |
||
final UserSettings? userSettings; // TODO(server-5) | ||
|
||
final int maxFileUploadSizeMib; | ||
|
||
@JsonKey(readValue: _readUsersIsActiveFallbackTrue) | ||
|
@@ -71,6 +80,7 @@ class InitialSnapshot { | |
required this.recentPrivateConversations, | ||
required this.subscriptions, | ||
required this.streams, | ||
required this.userSettings, | ||
required this.maxFileUploadSizeMib, | ||
required this.realmUsers, | ||
required this.realmNonActiveUsers, | ||
|
@@ -102,3 +112,54 @@ class RecentDmConversation { | |
|
||
Map<String, dynamic> toJson() => _$RecentDmConversationToJson(this); | ||
} | ||
|
||
/// The `user_settings` dictionary. | ||
/// | ||
/// For docs, search for "user_settings:" | ||
/// in <https://zulip.com/api/register-queue>. | ||
@JsonSerializable(fieldRename: FieldRename.snake, createFieldMap: true) | ||
class UserSettings { | ||
bool twentyFourHourTime; | ||
bool? displayEmojiReactionUsers; // TODO(server-6) | ||
|
||
// TODO more, as needed. When adding a setting here, please also: | ||
// (1) add it to the [UserSettingName] enum below | ||
// (2) then re-run the command to refresh the .g.dart files | ||
// (3) handle the event that signals an update to the setting | ||
|
||
UserSettings({ | ||
required this.twentyFourHourTime, | ||
required this.displayEmojiReactionUsers, | ||
}); | ||
|
||
factory UserSettings.fromJson(Map<String, dynamic> json) => | ||
_$UserSettingsFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$UserSettingsToJson(this); | ||
|
||
/// A list of [UserSettings]'s properties, as strings. | ||
// _$…FieldMap is thanks to `createFieldMap: true` | ||
@visibleForTesting | ||
static final Iterable<String> debugKnownNames = _$UserSettingsFieldMap.keys; | ||
} | ||
|
||
/// The name of a user setting that has a property in [UserSettings]. | ||
/// | ||
/// In Zulip event-handling code (for [UserSettingsUpdateEvent]), | ||
/// we switch exhaustively on a value of this type | ||
/// to ensure that every setting in [UserSettings] responds to the event. | ||
@JsonEnum(fieldRename: FieldRename.snake, alwaysCreate: true) | ||
enum UserSettingName { | ||
twentyFourHourTime, | ||
displayEmojiReactionUsers; | ||
|
||
/// Get a [UserSettingName] from a raw, snake-case string we recognize, else null. | ||
/// | ||
/// Example: | ||
/// 'display_emoji_reaction_users' -> UserSettingName.displayEmojiReactionUsers | ||
static UserSettingName? fromRawString(String raw) => _byRawString[raw]; | ||
|
||
// _$…EnumMap is thanks to `alwaysCreate: true` and `fieldRename: FieldRename.snake` | ||
static final _byRawString = _$UserSettingNameEnumMap | ||
.map((key, value) => MapEntry(value, key)); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly this should get marked
includeToJson
so that thetoJson
round-trips.