File tree Expand file tree Collapse file tree 5 files changed +102
-1
lines changed Expand file tree Collapse file tree 5 files changed +102
-1
lines changed Original file line number Diff line number Diff line change @@ -481,7 +481,6 @@ sealed class Message {
481
481
final String senderRealmStr;
482
482
@JsonKey (name: 'subject' )
483
483
String topic;
484
- // final List<string> submessages; // TODO handle
485
484
final int timestamp;
486
485
String get type;
487
486
Original file line number Diff line number Diff line change
1
+ import 'package:json_annotation/json_annotation.dart' ;
2
+
3
+ part 'submessage.g.dart' ;
4
+
5
+ /// Data used for certain experimental Zulip widgets including polls and todo
6
+ /// lists.
7
+ ///
8
+ /// See:
9
+ /// https://zulip.com/api/get-messages#response
10
+ /// https://zulip.readthedocs.io/en/latest/subsystems/widgets.html
11
+ @JsonSerializable (fieldRename: FieldRename .snake)
12
+ class Submessage {
13
+ const Submessage ({
14
+ required this .msgType,
15
+ required this .content,
16
+ required this .senderId,
17
+ });
18
+
19
+ @JsonKey (unknownEnumValue: SubmessageType .unknown)
20
+ final SubmessageType msgType;
21
+ final String content;
22
+ // final int messageId; // ignored; redundant with [Message.id]
23
+ final int senderId;
24
+ // final int id; // ignored because it is unused
25
+
26
+ factory Submessage .fromJson (Map <String , Object ?> json) =>
27
+ _$SubmessageFromJson (json);
28
+
29
+ Map <String , Object ?> toJson () => _$SubmessageToJson (this );
30
+ }
31
+
32
+ /// As in [Submessage.msgType] .
33
+ enum SubmessageType {
34
+ widget,
35
+ unknown,
36
+ }
Original file line number Diff line number Diff line change
1
+
2
+ import 'package:checks/checks.dart' ;
3
+ import 'package:zulip/api/model/submessage.dart' ;
4
+
5
+ extension SubmessageChecks on Subject <Submessage > {
6
+ Subject <SubmessageType > get msgType => has ((e) => e.msgType, 'msgType' );
7
+ Subject <Object ?> get content => has ((e) => e.content, 'content' );
8
+ Subject <int > get senderId => has ((e) => e.senderId, 'senderId' );
9
+ }
Original file line number Diff line number Diff line change
1
+ import 'package:checks/checks.dart' ;
2
+ import 'package:test/scaffolding.dart' ;
3
+ import 'package:zulip/api/model/submessage.dart' ;
4
+
5
+ import '../../example_data.dart' as eg;
6
+ import 'submessage_checks.dart' ;
7
+
8
+ void main () {
9
+ group ('Message.submessages' , () {
10
+ test ('no crash on unrecognized submessage type' , () {
11
+ final baseJson = {
12
+ 'content' : '[]' ,
13
+ 'message_id' : 123 ,
14
+ 'sender_id' : eg.selfUser.userId,
15
+ 'id' : 1 ,
16
+ };
17
+
18
+ check (Submessage .fromJson ({
19
+ ...baseJson,
20
+ 'msg_type' : 'widget' ,
21
+ })).msgType.equals (SubmessageType .widget);
22
+
23
+ check (Submessage .fromJson ({
24
+ ...baseJson,
25
+ 'msg_type' : 'unknown_widget' ,
26
+ })).msgType.equals (SubmessageType .unknown);
27
+ });
28
+ });
29
+ }
You can’t perform that action at this time.
0 commit comments