@@ -29,6 +29,8 @@ class InitialSnapshot {
29
29
30
30
final List <Subscription > subscriptions;
31
31
32
+ final UnreadMessagesSnapshot unreadMsgs;
33
+
32
34
final List <ZulipStream > streams;
33
35
34
36
// Servers pre-5.0 don't have `user_settings`, and instead provide whatever
@@ -79,6 +81,7 @@ class InitialSnapshot {
79
81
required this .customProfileFields,
80
82
required this .recentPrivateConversations,
81
83
required this .subscriptions,
84
+ required this .unreadMsgs,
82
85
required this .streams,
83
86
required this .userSettings,
84
87
required this .maxFileUploadSizeMib,
@@ -163,3 +166,101 @@ enum UserSettingName {
163
166
static final _byRawString = _$UserSettingNameEnumMap
164
167
.map ((key, value) => MapEntry (value, key));
165
168
}
169
+
170
+ /// The `unread_msgs` snapshot.
171
+ ///
172
+ /// For docs, search for "unread_msgs:"
173
+ /// in <https://zulip.com/api/register-queue>.
174
+ @JsonSerializable (fieldRename: FieldRename .snake)
175
+ class UnreadMessagesSnapshot {
176
+ final int count;
177
+
178
+ @JsonKey (name: 'pms' )
179
+ final List <UnreadDmSnapshot > dms;
180
+
181
+ final List <UnreadStreamSnapshot > streams;
182
+ final List <UnreadHuddleSnapshot > huddles;
183
+ final List <int > mentions;
184
+ final bool oldUnreadsMissing;
185
+
186
+ UnreadMessagesSnapshot ({
187
+ required this .count,
188
+ required this .dms,
189
+ required this .streams,
190
+ required this .huddles,
191
+ required this .mentions,
192
+ required this .oldUnreadsMissing,
193
+ });
194
+
195
+ factory UnreadMessagesSnapshot .fromJson (Map <String , dynamic > json) =>
196
+ _$UnreadMessagesSnapshotFromJson (json);
197
+
198
+ Map <String , dynamic > toJson () => _$UnreadMessagesSnapshotToJson (this );
199
+ }
200
+
201
+ /// An item in [UnreadMessagesSnapshot.dms] .
202
+ @JsonSerializable (fieldRename: FieldRename .snake)
203
+ class UnreadDmSnapshot {
204
+ @JsonKey (readValue: _readOtherUserId)
205
+ final int otherUserId;
206
+
207
+ // The doc mistakenly calls this `unread_ids`:
208
+ // https://chat.zulip.org/#narrow/stream/412-api-documentation/topic/register.3A.20.60unread_msgs.2Epms.5B.5D.2Eunread_message_ids.60/near/1623940
209
+ final List <int > unreadMessageIds;
210
+
211
+ // other_user_id was introduced at FL 119 as the new name for sender_id:
212
+ // 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
213
+ // TODO(server-5): Simplify away.
214
+ static _readOtherUserId (Map json, String key) {
215
+ return json[key] ?? json['sender_id' ];
216
+ }
217
+
218
+ UnreadDmSnapshot ({
219
+ required this .otherUserId,
220
+ required this .unreadMessageIds,
221
+ });
222
+
223
+ factory UnreadDmSnapshot .fromJson (Map <String , dynamic > json) =>
224
+ _$UnreadDmSnapshotFromJson (json);
225
+
226
+ Map <String , dynamic > toJson () => _$UnreadDmSnapshotToJson (this );
227
+ }
228
+
229
+ /// An item in [UnreadMessagesSnapshot.streams] .
230
+ @JsonSerializable (fieldRename: FieldRename .snake)
231
+ class UnreadStreamSnapshot {
232
+ final String topic;
233
+ final int streamId;
234
+ final List <int > unreadMessageIds;
235
+
236
+ UnreadStreamSnapshot ({
237
+ required this .topic,
238
+ required this .streamId,
239
+ required this .unreadMessageIds,
240
+ });
241
+
242
+ factory UnreadStreamSnapshot .fromJson (Map <String , dynamic > json) =>
243
+ _$UnreadStreamSnapshotFromJson (json);
244
+
245
+ Map <String , dynamic > toJson () => _$UnreadStreamSnapshotToJson (this );
246
+ }
247
+
248
+ /// An item in [UnreadMessagesSnapshot.huddles] .
249
+ @JsonSerializable (fieldRename: FieldRename .snake)
250
+ class UnreadHuddleSnapshot {
251
+ final String userIdsString;
252
+
253
+ // The doc mistakenly calls this `unread_ids`:
254
+ // https://chat.zulip.org/#narrow/stream/412-api-documentation/topic/register.3A.20.60unread_msgs.2Epms.5B.5D.2Eunread_message_ids.60/near/1623940
255
+ final List <int > unreadMessageIds;
256
+
257
+ UnreadHuddleSnapshot ({
258
+ required this .userIdsString,
259
+ required this .unreadMessageIds,
260
+ });
261
+
262
+ factory UnreadHuddleSnapshot .fromJson (Map <String , dynamic > json) =>
263
+ _$UnreadHuddleSnapshotFromJson (json);
264
+
265
+ Map <String , dynamic > toJson () => _$UnreadHuddleSnapshotToJson (this );
266
+ }
0 commit comments