Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/api/model/initial_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ class UserSettings {
TwentyFourHourTimeMode twentyFourHourTime;

bool displayEmojiReactionUsers;
@JsonKey(unknownEnumValue: Emojiset.unknown)
Emojiset emojiset;
Comment on lines +298 to 299
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at other references to Emojiset to see if we might need this elsewhere.

One is in events:

      case UserSettingName.emojiset:
        return Emojiset.fromRawString(value as String);

It looks like the effect of that is that if the user's value for this setting gets changed to an unknown value, we'd still throw. Let's fix that so that it produces Emojiset.unknown, just like if the same unknown value is found in the initial snapshot.

bool presenceEnabled;

Expand Down
7 changes: 6 additions & 1 deletion lib/api/model/initial_snapshot.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,14 @@ enum Emojiset {
google,
googleBlob,
twitter,
text;
text,
unknown;

/// Get an [Emojiset] from a raw string. Throws if the string is unrecognized.
///
/// Example:
/// 'google-blob' -> Emojiset.googleBlob
static Emojiset fromRawString(String raw) => _byRawString[raw]!;
static Emojiset fromRawString(String raw) => _byRawString[raw] ?? unknown;

// _$…EnumMap is thanks to `alwaysCreate: true` and `fieldRename: FieldRename.kebab`
static final _byRawString = _$EmojisetEnumMap
Expand Down
1 change: 1 addition & 0 deletions lib/api/model/model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,10 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
version: "0.13.0"
meta:
dependency: transitive
description:
Expand Down
10 changes: 10 additions & 0 deletions test/api/model/initial_snapshot_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:test/scaffolding.dart';
import 'package:zulip/api/model/initial_snapshot.dart';
import 'package:zulip/api/model/model.dart';

import '../../example_data.dart' as eg;
import '../../stdlib_checks.dart';

void main() {
Expand Down Expand Up @@ -62,4 +63,13 @@ void main() {
'unread_message_ids': [11, 2, 3],
})).throws<AssertionError>();
});

test('UserSettings.emojiset handles various unknown values', () {
final unknownValues = ['apple', ''];
for (final unknownValue in unknownValues) {
final json = eg.userSettings().toJson()..['emojiset'] = unknownValue;
final settings = UserSettings.fromJson(json);
check(settings.emojiset).equals(Emojiset.unknown);
}
});
}
22 changes: 16 additions & 6 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,21 @@ const _globalStore = globalStore;

const String defaultRealmEmptyTopicDisplayName = 'test general chat';

UserSettings userSettings({
TwentyFourHourTimeMode? twentyFourHourTime,
bool? displayEmojiReactionUsers,
Emojiset? emojiset,
bool? presenceEnabled,
}) {
return UserSettings(
twentyFourHourTime: twentyFourHourTime ?? TwentyFourHourTimeMode.twelveHour,
displayEmojiReactionUsers: displayEmojiReactionUsers ?? true,
emojiset: emojiset ?? Emojiset.google,
presenceEnabled: presenceEnabled ?? true,
);
}
const _userSettings = userSettings;

InitialSnapshot initialSnapshot({
String? queueId,
int? lastEventId,
Expand Down Expand Up @@ -1387,12 +1402,7 @@ InitialSnapshot initialSnapshot({
unreadMsgs: unreadMsgs ?? _unreadMsgs(),
streams: streams ?? [], // TODO add streams to default
userStatuses: userStatuses ?? {},
userSettings: userSettings ?? UserSettings(
twentyFourHourTime: TwentyFourHourTimeMode.twelveHour,
displayEmojiReactionUsers: true,
emojiset: Emojiset.google,
presenceEnabled: true,
),
userSettings: userSettings ?? _userSettings(),
userTopics: userTopics ?? [],
// no default; allow `null` to simulate servers without this
realmCanDeleteAnyMessageGroup: realmCanDeleteAnyMessageGroup,
Expand Down