Skip to content

Commit 7e79010

Browse files
api: Accept unknown "emojiset" values in initial snapshot
Fixes #1981.
1 parent 3ae958e commit 7e79010

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

lib/api/model/initial_snapshot.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ class UserSettings {
295295
TwentyFourHourTimeMode twentyFourHourTime;
296296

297297
bool displayEmojiReactionUsers;
298+
@JsonKey(unknownEnumValue: Emojiset.unknown)
298299
Emojiset emojiset;
299300
bool presenceEnabled;
300301

lib/api/model/initial_snapshot.g.dart

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/api/model/model.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ enum Emojiset {
390390
google,
391391
googleBlob,
392392
twitter,
393-
text;
393+
text,
394+
unknown;
394395

395396
/// Get an [Emojiset] from a raw string. Throws if the string is unrecognized.
396397
///

lib/api/model/model.g.dart

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/api/model/initial_snapshot_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:test/scaffolding.dart';
33
import 'package:zulip/api/model/initial_snapshot.dart';
44
import 'package:zulip/api/model/model.dart';
55

6+
import '../../example_data.dart' as eg;
67
import '../../stdlib_checks.dart';
78

89
void main() {
@@ -62,4 +63,15 @@ void main() {
6263
'unread_message_ids': [11, 2, 3],
6364
})).throws<AssertionError>();
6465
});
66+
67+
test('UserSettings.emojiset handles various unknown values', () {
68+
final unknownValues = ['apple', 'microsoft', 'facebook', ''];
69+
for (final unknownValue in unknownValues) {
70+
final json = eg.userSettings().toJson()..['emojiset'] = unknownValue;
71+
final settings = UserSettings.fromJson(json);
72+
73+
// Verify unknown emojiset defaults to Emojiset.unknown
74+
check(settings.emojiset).equals(Emojiset.unknown);
75+
}
76+
});
6577
}

test/example_data.dart

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,22 @@ const _globalStore = globalStore;
13041304

13051305
const String defaultRealmEmptyTopicDisplayName = 'test general chat';
13061306

1307+
UserSettings userSettings({
1308+
TwentyFourHourTimeMode? twentyFourHourTime,
1309+
bool? displayEmojiReactionUsers,
1310+
Emojiset? emojiset,
1311+
bool? presenceEnabled,
1312+
}) {
1313+
return UserSettings(
1314+
twentyFourHourTime: twentyFourHourTime ?? TwentyFourHourTimeMode.twelveHour,
1315+
displayEmojiReactionUsers: displayEmojiReactionUsers ?? true,
1316+
emojiset: emojiset ?? Emojiset.google,
1317+
presenceEnabled: presenceEnabled ?? true,
1318+
);
1319+
}
1320+
1321+
const _userSettings = userSettings;
1322+
13071323
InitialSnapshot initialSnapshot({
13081324
String? queueId,
13091325
int? lastEventId,
@@ -1387,12 +1403,7 @@ InitialSnapshot initialSnapshot({
13871403
unreadMsgs: unreadMsgs ?? _unreadMsgs(),
13881404
streams: streams ?? [], // TODO add streams to default
13891405
userStatuses: userStatuses ?? {},
1390-
userSettings: userSettings ?? UserSettings(
1391-
twentyFourHourTime: TwentyFourHourTimeMode.twelveHour,
1392-
displayEmojiReactionUsers: true,
1393-
emojiset: Emojiset.google,
1394-
presenceEnabled: true,
1395-
),
1406+
userSettings: userSettings ?? _userSettings(),
13961407
userTopics: userTopics ?? [],
13971408
// no default; allow `null` to simulate servers without this
13981409
realmCanDeleteAnyMessageGroup: realmCanDeleteAnyMessageGroup,

0 commit comments

Comments
 (0)