Skip to content

Commit 553f9a8

Browse files
committed
wip api: Add unreadMsgs in initial snapshot
TODO resolve two #api documentation discussions: https://chat.zulip.org/#narrow/stream/412-api-documentation/topic/register.3A.20.60unread_msgs.2Epms.5B.5D.2Eunread_message_ids.60/near/1623940 https://chat.zulip.org/#narrow/stream/412-api-documentation/topic/register.3A.20When.20was.20.60unread_msgs.2Epms.5B.5D.2Eother_user_id.60.20added.3F/near/1623961 Our own data structure in PerAccountStore will be constructed from this value, and it will probably have quite a different shape; for example, we're likely to want to collapse the distinction between 1:1 and group DMs. But now we're validating this part of the /register response and making it available to feed into those new internal data structures. Related: #253
1 parent aa905d7 commit 553f9a8

File tree

3 files changed

+199
-0
lines changed

3 files changed

+199
-0
lines changed

lib/api/model/initial_snapshot.dart

+98
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class InitialSnapshot {
2828

2929
final List<Subscription> subscriptions;
3030

31+
final UnreadMessagesSnapshot unreadMsgs;
32+
3133
final List<ZulipStream> streams;
3234

3335
final int maxFileUploadSizeMib;
@@ -70,6 +72,7 @@ class InitialSnapshot {
7072
required this.customProfileFields,
7173
required this.recentPrivateConversations,
7274
required this.subscriptions,
75+
required this.unreadMsgs,
7376
required this.streams,
7477
required this.maxFileUploadSizeMib,
7578
required this.realmUsers,
@@ -102,3 +105,98 @@ class RecentDmConversation {
102105

103106
Map<String, dynamic> toJson() => _$RecentDmConversationToJson(this);
104107
}
108+
109+
/// The `unread_msgs` snapshot.
110+
///
111+
/// For docs, search for "unread_msgs:"
112+
/// in <https://zulip.com/api/register-queue>.
113+
@JsonSerializable(fieldRename: FieldRename.snake)
114+
class UnreadMessagesSnapshot {
115+
final int count;
116+
117+
@JsonKey(name: 'pms')
118+
final List<UnreadDmSnapshot> dms;
119+
120+
final List<UnreadStreamSnapshot> streams;
121+
final List<UnreadHuddleSnapshot> huddles;
122+
final List<int> mentions;
123+
final bool oldUnreadsMissing;
124+
125+
UnreadMessagesSnapshot({
126+
required this.count,
127+
required this.dms,
128+
required this.streams,
129+
required this.huddles,
130+
required this.mentions,
131+
required this.oldUnreadsMissing,
132+
});
133+
134+
factory UnreadMessagesSnapshot.fromJson(Map<String, dynamic> json) =>
135+
_$UnreadMessagesSnapshotFromJson(json);
136+
137+
Map<String, dynamic> toJson() => _$UnreadMessagesSnapshotToJson(this);
138+
}
139+
140+
/// An item in `unread_msgs.pms`.
141+
///
142+
/// For docs, search for "unread_msgs:" and see "pms:"
143+
/// in <https://zulip.com/api/register-queue>.
144+
@JsonSerializable(fieldRename: FieldRename.snake)
145+
class UnreadDmSnapshot {
146+
final int otherUserId;
147+
// final int senderId; // deprecated; ignore
148+
final List<int> unreadMessageIds;
149+
150+
UnreadDmSnapshot({
151+
required this.otherUserId,
152+
required this.unreadMessageIds,
153+
});
154+
155+
factory UnreadDmSnapshot.fromJson(Map<String, dynamic> json) =>
156+
_$UnreadDmSnapshotFromJson(json);
157+
158+
Map<String, dynamic> toJson() => _$UnreadDmSnapshotToJson(this);
159+
}
160+
161+
/// An item in `unread_msgs.streams`.
162+
///
163+
/// For docs, search for "unread_msgs:" and see "streams:"
164+
/// in <https://zulip.com/api/register-queue>.
165+
@JsonSerializable(fieldRename: FieldRename.snake)
166+
class UnreadStreamSnapshot {
167+
final String topic;
168+
final int streamId;
169+
final List<int> unreadMessageIds;
170+
// final List<int> senderIds; // deprecated; ignore
171+
172+
UnreadStreamSnapshot({
173+
required this.topic,
174+
required this.streamId,
175+
required this.unreadMessageIds,
176+
});
177+
178+
factory UnreadStreamSnapshot.fromJson(Map<String, dynamic> json) =>
179+
_$UnreadStreamSnapshotFromJson(json);
180+
181+
Map<String, dynamic> toJson() => _$UnreadStreamSnapshotToJson(this);
182+
}
183+
184+
/// An item in `unread_msgs.huddles`.
185+
///
186+
/// For docs, search for "unread_msgs:" and see "huddles:"
187+
/// in <https://zulip.com/api/register-queue>.
188+
@JsonSerializable(fieldRename: FieldRename.snake)
189+
class UnreadHuddleSnapshot {
190+
final String userIdsString;
191+
final List<int> unreadMessageIds;
192+
193+
UnreadHuddleSnapshot({
194+
required this.userIdsString,
195+
required this.unreadMessageIds,
196+
});
197+
198+
factory UnreadHuddleSnapshot.fromJson(Map<String, dynamic> json) =>
199+
_$UnreadHuddleSnapshotFromJson(json);
200+
201+
Map<String, dynamic> toJson() => _$UnreadHuddleSnapshotToJson(this);
202+
}

lib/api/model/initial_snapshot.g.dart

+80
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/example_data.dart

+21
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ ZulipStream stream({
9292
);
9393
}
9494

95+
UnreadMessagesSnapshot unreadMsgs({
96+
int? count,
97+
List<UnreadDmSnapshot>? dms,
98+
List<UnreadStreamSnapshot>? streams,
99+
List<UnreadHuddleSnapshot>? huddles,
100+
List<int>? mentions,
101+
bool? oldUnreadsMissing,
102+
}) {
103+
return UnreadMessagesSnapshot(
104+
count: count ?? 0,
105+
dms: dms ?? [],
106+
streams: streams ?? [],
107+
huddles: huddles ?? [],
108+
mentions: mentions ?? [],
109+
oldUnreadsMissing: oldUnreadsMissing ?? false,
110+
);
111+
}
112+
const _unreadMsgs = unreadMsgs;
113+
95114
final _messagePropertiesBase = {
96115
'is_me_message': false,
97116
'recipient_id': 32, // obsolescent in API, and ignored
@@ -207,6 +226,7 @@ InitialSnapshot initialSnapshot({
207226
List<CustomProfileField>? customProfileFields,
208227
List<RecentDmConversation>? recentPrivateConversations,
209228
List<Subscription>? subscriptions,
229+
UnreadMessagesSnapshot? unreadMsgs,
210230
List<ZulipStream>? streams,
211231
int? maxFileUploadSizeMib,
212232
List<User>? realmUsers,
@@ -223,6 +243,7 @@ InitialSnapshot initialSnapshot({
223243
customProfileFields: customProfileFields ?? [],
224244
recentPrivateConversations: recentPrivateConversations ?? [],
225245
subscriptions: subscriptions ?? [], // TODO add subscriptions to default
246+
unreadMsgs: unreadMsgs ?? _unreadMsgs(),
226247
streams: streams ?? [], // TODO add streams to default
227248
maxFileUploadSizeMib: maxFileUploadSizeMib ?? 25,
228249
realmUsers: realmUsers ?? [],

0 commit comments

Comments
 (0)