@@ -42,6 +42,9 @@ mixin ChannelStore on UserStore {
4242 /// and [streamsByName] .
4343 Map <int , Subscription > get subscriptions;
4444
45+ /// All the channel folders, including archived ones, indexed by ID.
46+ Map <int , ChannelFolder > get channelFolders;
47+
4548 static int compareChannelsByName (ZulipStream a, ZulipStream b) {
4649 // A user gave feedback wanting zulip-flutter to match web in putting
4750 // emoji-prefixed channels first; see #1202.
@@ -267,6 +270,9 @@ mixin ProxyChannelStore on ChannelStore {
267270 @override
268271 Map <int , Subscription > get subscriptions => channelStore.subscriptions;
269272
273+ @override
274+ Map <int , ChannelFolder > get channelFolders => channelStore.channelFolders;
275+
270276 @override
271277 UserTopicVisibilityPolicy topicVisibilityPolicy (int streamId, TopicName topic) =>
272278 channelStore.topicVisibilityPolicy (streamId, topic);
@@ -306,6 +312,9 @@ class ChannelStoreImpl extends HasUserStore with ChannelStore {
306312 streams.putIfAbsent (stream.streamId, () => stream);
307313 }
308314
315+ final channelFolders = Map .fromEntries ((initialSnapshot.channelFolders ?? [])
316+ .map ((channelFolder) => MapEntry (channelFolder.id, channelFolder)));
317+
309318 final topicVisibility = < int , TopicKeyedMap <UserTopicVisibilityPolicy >> {};
310319 for (final item in initialSnapshot.userTopics) {
311320 if (_warnInvalidVisibilityPolicy (item.visibilityPolicy)) {
@@ -321,6 +330,7 @@ class ChannelStoreImpl extends HasUserStore with ChannelStore {
321330 streams: streams,
322331 streamsByName: streams.map ((_, stream) => MapEntry (stream.name, stream)),
323332 subscriptions: subscriptions,
333+ channelFolders: channelFolders,
324334 topicVisibility: topicVisibility,
325335 );
326336 }
@@ -330,6 +340,7 @@ class ChannelStoreImpl extends HasUserStore with ChannelStore {
330340 required this .streams,
331341 required this .streamsByName,
332342 required this .subscriptions,
343+ required this .channelFolders,
333344 required this .topicVisibility,
334345 });
335346
@@ -339,6 +350,8 @@ class ChannelStoreImpl extends HasUserStore with ChannelStore {
339350 final Map <String , ZulipStream > streamsByName;
340351 @override
341352 final Map <int , Subscription > subscriptions;
353+ @override
354+ final Map <int , ChannelFolder > channelFolders;
342355
343356 @override
344357 Map <int , TopicKeyedMap <UserTopicVisibilityPolicy >> get debugTopicVisibility => topicVisibility;
@@ -498,6 +511,33 @@ class ChannelStoreImpl extends HasUserStore with ChannelStore {
498511 }
499512 }
500513
514+ void handleChannelFolderEvent (ChannelFolderEvent event) {
515+ switch (event) {
516+ case ChannelFolderAddEvent ():
517+ final newChannelFolder = event.channelFolder;
518+ channelFolders[newChannelFolder.id] = newChannelFolder;
519+
520+ case ChannelFolderUpdateEvent ():
521+ final change = event.data;
522+ final channelFolder = channelFolders[event.channelFolderId];
523+ if (channelFolder == null ) return ; // TODO(log)
524+
525+ if (change.name != null ) channelFolder.name = change.name! ;
526+ if (change.description != null ) channelFolder.description = change.description! ;
527+ if (change.renderedDescription != null ) channelFolder.renderedDescription = change.renderedDescription! ;
528+ if (change.isArchived != null ) channelFolder.isArchived = change.isArchived! ;
529+
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+
501541 void handleUserTopicEvent (UserTopicEvent event) {
502542 UserTopicVisibilityPolicy visibilityPolicy = event.visibilityPolicy;
503543 if (_warnInvalidVisibilityPolicy (visibilityPolicy)) {
0 commit comments