@@ -765,78 +765,35 @@ class StreamMessage extends Message {
765765 Map <String , dynamic > toJson () => _$StreamMessageToJson (this );
766766}
767767
768- @JsonSerializable (fieldRename: FieldRename .snake)
769- class DmRecipient {
770- final int id;
771- final String email;
772- final String fullName;
773-
774- // final String? shortName; // obsolete, ignore
775- // final bool? isMirrorDummy; // obsolete, ignore
776-
777- DmRecipient ({required this .id, required this .email, required this .fullName});
778-
779- factory DmRecipient .fromJson (Map <String , dynamic > json) =>
780- _$DmRecipientFromJson (json);
781-
782- Map <String , dynamic > toJson () => _$DmRecipientToJson (this );
783-
784- @override
785- String toString () => 'DmRecipient(id: $id , email: $email , fullName: $fullName )' ;
786-
787- @override
788- bool operator == (Object other) {
789- if (other is ! DmRecipient ) return false ;
790- return other.id == id && other.email == email && other.fullName == fullName;
791- }
792-
793- @override
794- int get hashCode => Object .hash ('DmRecipient' , id, email, fullName);
795- }
796-
797- class DmRecipientListConverter extends JsonConverter <List <DmRecipient >, List <dynamic >> {
798- const DmRecipientListConverter ();
799-
800- @override
801- List <DmRecipient > fromJson (List <dynamic > json) {
802- return json.map ((e) => DmRecipient .fromJson (e as Map <String , dynamic >))
803- .toList (growable: false )
804- ..sort ((a, b) => a.id.compareTo (b.id));
805- }
806-
807- @override
808- List <dynamic > toJson (List <DmRecipient > object) => object;
809- }
810-
811768@JsonSerializable (fieldRename: FieldRename .snake)
812769class DmMessage extends Message {
813770 @override
814771 @JsonKey (includeToJson: true )
815772 String get type => 'private' ;
816773
817- /// The `display_recipient` from the server, sorted by user ID numerically.
774+ /// The user IDs of all users in the thread, sorted numerically, as in
775+ /// the `display_recipient from the server.
776+ ///
777+ /// The other fields on `display_recipient` are ignored and won't roundtrip.
818778 ///
819779 /// This lists the sender as well as all (other) recipients, and it
820780 /// lists each user just once. In particular the self-user is always
821781 /// included.
822- ///
823- /// Note the data here is not updated on changes to the users, so everything
824- /// other than the user IDs may be stale.
825- /// Consider using [allRecipientIds] instead, and getting user details
826- /// from the store.
827782 // TODO(server): Document that it's all users. That statement is based on
828783 // reverse-engineering notes in zulip-mobile:src/api/modelTypes.js at PmMessage.
829- @DmRecipientListConverter ()
830- final List <DmRecipient > displayRecipient;
784+ @JsonKey (name: 'display_recipient' , fromJson: _allRecipientIdsFromJson, toJson: _allRecipientIdsToJson)
785+ final List <int > allRecipientIds;
786+
787+ static List <int > _allRecipientIdsFromJson (Object ? json) {
788+ return (json as List <dynamic >).map (
789+ (element) => ((element as Map <String , dynamic >)['id' ] as num ).toInt ()
790+ ).toList (growable: false )
791+ ..sort ();
792+ }
831793
832- /// The user IDs of all users in the thread, sorted numerically.
833- ///
834- /// This lists the sender as well as all (other) recipients, and it
835- /// lists each user just once. In particular the self-user is always
836- /// included.
837- ///
838- /// This is a result of [List.map] , so it has an efficient `length` .
839- Iterable <int > get allRecipientIds => displayRecipient.map ((e) => e.id);
794+ static List <Map <String , dynamic >> _allRecipientIdsToJson (List <int > allRecipientIds) {
795+ return allRecipientIds.map ((element) => {'id' : element}).toList ();
796+ }
840797
841798 DmMessage ({
842799 required super .client,
@@ -856,7 +813,7 @@ class DmMessage extends Message {
856813 required super .flags,
857814 required super .matchContent,
858815 required super .matchTopic,
859- required this .displayRecipient ,
816+ required this .allRecipientIds ,
860817 });
861818
862819 factory DmMessage .fromJson (Map <String , dynamic > json) =>
0 commit comments