From 34494194c3941fa604d6ac387b02a47653daba11 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sun, 8 Dec 2024 16:08:55 -0800 Subject: [PATCH] api [nfc]: Rename RealmEmojiItem.id to emojiCode This way the binding encapsulates an important fact about this bit of the API -- namely that these values are the same as the "emoji code" values seen elsewhere in the API -- so that we don't have to re-verify it when working elsewhere in the codebase and using this class. Also edit a doc comment in the model code to take advantage of that understanding. --- lib/api/model/model.dart | 6 +++--- lib/api/model/model.g.dart | 4 ++-- lib/model/emoji.dart | 2 +- test/example_data.dart | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/api/model/model.dart b/lib/api/model/model.dart index a5040010df..d009bb9f29 100644 --- a/lib/api/model/model.dart +++ b/lib/api/model/model.dart @@ -115,7 +115,8 @@ class CustomProfileFieldExternalAccountData { /// in . @JsonSerializable(fieldRename: FieldRename.snake) class RealmEmojiItem { - final String id; + @JsonKey(name: 'id') + final String emojiCode; final String name; final String sourceUrl; final String? stillUrl; @@ -123,7 +124,7 @@ class RealmEmojiItem { final int? authorId; RealmEmojiItem({ - required this.id, + required this.emojiCode, required this.name, required this.sourceUrl, required this.stillUrl, @@ -137,7 +138,6 @@ class RealmEmojiItem { Map toJson() => _$RealmEmojiItemToJson(this); } - /// The name of a user setting that has a property in [UserSettings]. /// /// In Zulip event-handling code (for [UserSettingsUpdateEvent]), diff --git a/lib/api/model/model.g.dart b/lib/api/model/model.g.dart index e128c78b18..3f9e84d042 100644 --- a/lib/api/model/model.g.dart +++ b/lib/api/model/model.g.dart @@ -72,7 +72,7 @@ Map _$CustomProfileFieldExternalAccountDataToJson( RealmEmojiItem _$RealmEmojiItemFromJson(Map json) => RealmEmojiItem( - id: json['id'] as String, + emojiCode: json['id'] as String, name: json['name'] as String, sourceUrl: json['source_url'] as String, stillUrl: json['still_url'] as String?, @@ -82,7 +82,7 @@ RealmEmojiItem _$RealmEmojiItemFromJson(Map json) => Map _$RealmEmojiItemToJson(RealmEmojiItem instance) => { - 'id': instance.id, + 'id': instance.emojiCode, 'name': instance.name, 'source_url': instance.sourceUrl, 'still_url': instance.stillUrl, diff --git a/lib/model/emoji.dart b/lib/model/emoji.dart index e4d52cbedc..c1270eddce 100644 --- a/lib/model/emoji.dart +++ b/lib/model/emoji.dart @@ -131,7 +131,7 @@ class EmojiStoreImpl with EmojiStore { /// The same as [PerAccountStore.realmUrl]. final Uri realmUrl; - /// The realm's custom emoji, indexed by [Reaction.emojiCode], + /// The realm's custom emoji, indexed by their [RealmEmojiItem.emojiCode], /// including deactivated emoji not available for new uses. /// /// These are the emoji that can have [ReactionType.realmEmoji]. diff --git a/test/example_data.dart b/test/example_data.dart index dee5285b06..2339727eb6 100644 --- a/test/example_data.dart +++ b/test/example_data.dart @@ -77,7 +77,7 @@ RealmEmojiItem realmEmojiItem({ }) { assert(RegExp(r'^[1-9][0-9]*$').hasMatch(emojiCode)); return RealmEmojiItem( - id: emojiCode, + emojiCode: emojiCode, name: emojiName, sourceUrl: sourceUrl ?? '/emoji/$emojiCode.png', stillUrl: stillUrl,