From 3a874902d3647d475ab312c9ef8baf1feaad5828 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 19 Jul 2024 15:03:12 -0400 Subject: [PATCH] added some comments with justification for changes to how space view is auto loaded --- lib/pages/chat_list/chat_list.dart | 15 +++++++-------- lib/pages/chat_list/space_view.dart | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 664876a42..696178a72 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -570,14 +570,13 @@ class ChatListController extends State } }); - _spaceChildSubscription ??= - pangeaController.matrixState.client.onRoomState.stream - .where( - (update) => - update.state.type == EventTypes.SpaceChild && - update.roomId != activeSpaceId, - ) - .listen((update) { + // listen for space child updates for any space that is not the active space + // so that when the user navigates to the space that was updated, it will + // reload any rooms that have been added / removed + final client = pangeaController.matrixState.client; + _spaceChildSubscription ??= client.onRoomState.stream.where((u) { + return u.state.type == EventTypes.SpaceChild && u.roomId != activeSpaceId; + }).listen((update) { hasUpdates.add(update.roomId); }); //Pangea# diff --git a/lib/pages/chat_list/space_view.dart b/lib/pages/chat_list/space_view.dart index 8c1407b5a..bdd19338d 100644 --- a/lib/pages/chat_list/space_view.dart +++ b/lib/pages/chat_list/space_view.dart @@ -59,19 +59,28 @@ class _SpaceViewState extends State { void initState() { // #Pangea // loadHierarchy(); + + // If, on launch, this room has had updates to its children, + // ensure the hierarchy is properly reloaded final bool hasUpdate = widget.controller.hasUpdates.contains( widget.controller.activeSpaceId, ); + loadHierarchy(hasUpdate: hasUpdate).then( + // remove this space ID from the set of space IDs with updates (_) => widget.controller.hasUpdates.remove( widget.controller.activeSpaceId, ), ); + loadChatCounts(); - _roomSubscription ??= - Matrix.of(context).client.onRoomState.stream.where((update) { - return update.state.type == EventTypes.SpaceChild && - update.roomId == widget.controller.activeSpaceId; + + // Listen for changes to the activeSpace's hierarchy, + // and reload the hierarchy when they come through + final client = Matrix.of(context).client; + _roomSubscription ??= client.onRoomState.stream.where((u) { + return u.state.type == EventTypes.SpaceChild && + u.roomId == widget.controller.activeSpaceId; }).listen((update) { loadHierarchy(hasUpdate: true); }); @@ -143,6 +152,7 @@ class _SpaceViewState extends State { /// spaceId, it will try to load the next batch and add the new rooms to the /// already loaded ones. Displays a loading indicator while loading, and an error /// message if an error occurs. + /// If hasUpdate is true, it will force the hierarchy to be reloaded. Future loadHierarchy({ String? spaceId, bool hasUpdate = false,