Skip to content

Commit 721e0d8

Browse files
committed
api [nfc]: Expand comments on Submessage; put fields in logical order
1 parent d7cd703 commit 721e0d8

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

lib/api/model/submessage.dart

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,44 @@ import 'package:json_annotation/json_annotation.dart';
22

33
part 'submessage.g.dart';
44

5-
/// Data used for certain experimental Zulip widgets including polls and todo
6-
/// lists.
5+
/// Data used for Zulip "widgets" within messages, like polls and todo lists.
76
///
8-
/// See:
9-
/// https://zulip.com/api/get-messages#response
7+
/// For docs, see:
8+
/// https://zulip.com/api/get-messages#response (search for "submessage")
109
/// https://zulip.readthedocs.io/en/latest/subsystems/widgets.html
10+
///
11+
/// This is an underdocumented part of the Zulip Server API.
12+
/// So in addition to docs, see other clients:
13+
/// https://github.com/zulip/zulip-mobile/blob/2217c858e/src/api/modelTypes.js#L800-L861
14+
/// https://github.com/zulip/zulip-mobile/blob/2217c858e/src/webview/html/message.js#L118-L192
15+
/// https://github.com/zulip/zulip/blob/40f59a05c/web/src/submessage.ts
16+
/// https://github.com/zulip/zulip/blob/40f59a05c/web/shared/src/poll_data.ts
1117
@JsonSerializable(fieldRename: FieldRename.snake)
1218
class Submessage {
1319
const Submessage({
20+
required this.senderId,
1421
required this.msgType,
1522
required this.content,
16-
required this.senderId,
1723
});
1824

25+
// TODO(server): should we be sorting a message's submessages by ID? Web seems to:
26+
// https://github.com/zulip/zulip/blob/40f59a05c55e0e4f26ca87d2bca646770e94bff0/web/src/submessage.ts#L88
27+
// final int id; // ignored because we don't use it
28+
29+
/// The sender of this submessage (not necessarily of the [Message] it's on).
30+
final int senderId;
31+
32+
// final int messageId; // ignored; redundant with [Message.id]
33+
1934
@JsonKey(unknownEnumValue: SubmessageType.unknown)
2035
final SubmessageType msgType;
21-
/// [SubmessageData] encoded in JSON.
36+
37+
/// A JSON encoding of a [SubmessageData].
2238
// We cannot parse the String into one of the [SubmessageData] classes because
2339
// information from other submessages are required. Specifically, we need:
2440
// * the index of this submessage in [Message.submessages];
2541
// * the [WidgetType] of the first [Message.submessages].
2642
final String content;
27-
// final int messageId; // ignored; redundant with [Message.id]
28-
final int senderId;
29-
// final int id; // ignored because it is unused
3043

3144
factory Submessage.fromJson(Map<String, Object?> json) =>
3245
_$SubmessageFromJson(json);
@@ -35,6 +48,10 @@ class Submessage {
3548
}
3649

3750
/// As in [Submessage.msgType].
51+
///
52+
/// The only type of submessage that actually exists in Zulip (as of 2024,
53+
/// and since this "submessages" subsystem was created in 2017–2018)
54+
/// is [SubmessageType.widget].
3855
enum SubmessageType {
3956
widget,
4057
unknown,

lib/api/model/submessage.g.dart

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

test/api/model/submessage_checks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import 'package:checks/checks.dart';
33
import 'package:zulip/api/model/submessage.dart';
44

55
extension SubmessageChecks on Subject<Submessage> {
6+
Subject<int> get senderId => has((e) => e.senderId, 'senderId');
67
Subject<SubmessageType> get msgType => has((e) => e.msgType, 'msgType');
78
Subject<Object?> get content => has((e) => e.content, 'content');
8-
Subject<int> get senderId => has((e) => e.senderId, 'senderId');
99
}
1010

1111
extension WidgetDataChecks on Subject<WidgetData> {

test/api/model/submessage_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ void main() {
99
group('Message.submessages', () {
1010
test('no crash on unrecognized submessage type', () {
1111
final baseJson = {
12-
'content': '[]',
13-
'message_id': 123,
14-
'sender_id': eg.selfUser.userId,
1512
'id': 1,
13+
'sender_id': eg.selfUser.userId,
14+
'message_id': 123,
15+
'content': '[]',
1616
};
1717

1818
check(Submessage.fromJson({

0 commit comments

Comments
 (0)