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;
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.

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

/// Get an [Emojiset] from a raw string. Throws if the string is unrecognized.
///
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.

12 changes: 12 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,15 @@ void main() {
'unread_message_ids': [11, 2, 3],
})).throws<AssertionError>();
});

test('UserSettings.emojiset handles various unknown values', () {
final unknownValues = ['apple', 'microsoft', 'facebook', ''];
for (final unknownValue in unknownValues) {
final json = eg.userSettings().toJson()..['emojiset'] = unknownValue;
final settings = UserSettings.fromJson(json);

// Verify unknown emojiset defaults to Emojiset.unknown
check(settings.emojiset).equals(Emojiset.unknown);
}
});
}
14 changes: 14 additions & 0 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,20 @@ const _globalStore = globalStore;

const String defaultRealmEmptyTopicDisplayName = 'test general chat';

UserSettings userSettings({
TwentyFourHourTimeMode? twentyFourHourTime,
bool? displayEmojiReactionUsers,
Emojiset? emojiset,
bool? presenceEnabled,
}) {
return UserSettings(
twentyFourHourTime: twentyFourHourTime ?? TwentyFourHourTimeMode.twentyFourHour,
displayEmojiReactionUsers: displayEmojiReactionUsers ?? true,
emojiset: emojiset ?? Emojiset.unknown ,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should aim to make the defaults boring and representative of real data, and I think Emojiset.google would be better for that than Emojiset.unknown.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also this helper can deduplicate some code in the initialSnapshot helper just below this.

Just below the userSettings function declaration, you can say

const _userSettings = userSettings;

then in initialSnapshot in choosing arguments for the InitialSnapshot constructor, you can say:

    userSettings: userSettings ?? _userSettings(),

presenceEnabled: presenceEnabled ?? true,
);
}

InitialSnapshot initialSnapshot({
String? queueId,
int? lastEventId,
Expand Down