@@ -42,6 +42,9 @@ mixin ChannelStore on UserStore {
42
42
/// and [streamsByName] .
43
43
Map <int , Subscription > get subscriptions;
44
44
45
+ /// All the channel folders, including archived ones, indexed by ID.
46
+ Map <int , ChannelFolder > get channelFolders;
47
+
45
48
static int compareChannelsByName (ZulipStream a, ZulipStream b) {
46
49
// A user gave feedback wanting zulip-flutter to match web in putting
47
50
// emoji-prefixed channels first; see #1202.
@@ -267,6 +270,9 @@ mixin ProxyChannelStore on ChannelStore {
267
270
@override
268
271
Map <int , Subscription > get subscriptions => channelStore.subscriptions;
269
272
273
+ @override
274
+ Map <int , ChannelFolder > get channelFolders => channelStore.channelFolders;
275
+
270
276
@override
271
277
UserTopicVisibilityPolicy topicVisibilityPolicy (int streamId, TopicName topic) =>
272
278
channelStore.topicVisibilityPolicy (streamId, topic);
@@ -306,6 +312,9 @@ class ChannelStoreImpl extends HasUserStore with ChannelStore {
306
312
streams.putIfAbsent (stream.streamId, () => stream);
307
313
}
308
314
315
+ final channelFolders = Map .fromEntries ((initialSnapshot.channelFolders ?? [])
316
+ .map ((channelFolder) => MapEntry (channelFolder.id, channelFolder)));
317
+
309
318
final topicVisibility = < int , TopicKeyedMap <UserTopicVisibilityPolicy >> {};
310
319
for (final item in initialSnapshot.userTopics ?? const < UserTopicItem > []) {
311
320
if (_warnInvalidVisibilityPolicy (item.visibilityPolicy)) {
@@ -321,6 +330,7 @@ class ChannelStoreImpl extends HasUserStore with ChannelStore {
321
330
streams: streams,
322
331
streamsByName: streams.map ((_, stream) => MapEntry (stream.name, stream)),
323
332
subscriptions: subscriptions,
333
+ channelFolders: channelFolders,
324
334
topicVisibility: topicVisibility,
325
335
);
326
336
}
@@ -330,6 +340,7 @@ class ChannelStoreImpl extends HasUserStore with ChannelStore {
330
340
required this .streams,
331
341
required this .streamsByName,
332
342
required this .subscriptions,
343
+ required this .channelFolders,
333
344
required this .topicVisibility,
334
345
});
335
346
@@ -339,6 +350,8 @@ class ChannelStoreImpl extends HasUserStore with ChannelStore {
339
350
final Map <String , ZulipStream > streamsByName;
340
351
@override
341
352
final Map <int , Subscription > subscriptions;
353
+ @override
354
+ final Map <int , ChannelFolder > channelFolders;
342
355
343
356
@override
344
357
Map <int , TopicKeyedMap <UserTopicVisibilityPolicy >> get debugTopicVisibility => topicVisibility;
@@ -500,6 +513,31 @@ class ChannelStoreImpl extends HasUserStore with ChannelStore {
500
513
}
501
514
}
502
515
516
+ void handleChannelFolderEvent (ChannelFolderEvent event) {
517
+ switch (event) {
518
+ case ChannelFolderAddEvent ():
519
+ final newChannelFolder = event.channelFolder;
520
+ channelFolders[newChannelFolder.id] = newChannelFolder;
521
+ case ChannelFolderUpdateEvent ():
522
+ final change = event.data;
523
+ final channelFolder = channelFolders[event.channelFolderId];
524
+ if (channelFolder == null ) return ; // TODO(log)
525
+
526
+ if (change.name != null ) channelFolder.name = change.name! ;
527
+ if (change.description != null ) channelFolder.description = change.description! ;
528
+ if (change.renderedDescription != null ) channelFolder.renderedDescription = change.renderedDescription! ;
529
+ if (change.isArchived != null ) channelFolder.isArchived = change.isArchived! ;
530
+ case ChannelFolderReorderEvent ():
531
+ final order = event.order;
532
+ for (int i = 0 ; i < order.length; i++ ) {
533
+ final id = order[i];
534
+ final channelFolder = channelFolders[id];
535
+ if (channelFolder == null ) continue ; // TODO(log)
536
+ channelFolder.order = i;
537
+ }
538
+ }
539
+ }
540
+
503
541
void handleUserTopicEvent (UserTopicEvent event) {
504
542
UserTopicVisibilityPolicy visibilityPolicy = event.visibilityPolicy;
505
543
if (_warnInvalidVisibilityPolicy (visibilityPolicy)) {
0 commit comments