From c79aa267c3add0ad63932b2914f03c6005f10488 Mon Sep 17 00:00:00 2001
From: Maxime Naturel <maxime.naturel@niji.fr>
Date: Wed, 9 Feb 2022 10:10:23 +0100
Subject: [PATCH] Fix switching space use case

---
 .../features/home/room/list/RoomListSectionBuilderSpace.kt  | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt
index cd055c2e4a..4839612afc 100644
--- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt
+++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt
@@ -399,13 +399,15 @@ class RoomListSectionBuilderSpace(
                                         .flowOn(Dispatchers.Default)
                                         .launchIn(viewModelScope)
 
+                                val itemCountFlow = livePagedList.asFlow()
+                                        .flatMapLatest { session.getRoomCountFlow(roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId())) }
+
                                 sections.add(
                                         RoomsSection(
                                                 sectionName = name,
                                                 livePages = livePagedList,
                                                 notifyOfLocalEcho = notifyOfLocalEcho,
-                                                // TODO not working when switching spaces, how does the query is updated in this case?
-                                                itemCount = session.getRoomCountFlow(roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()))
+                                                itemCount = itemCountFlow
                                         )
                                 )
                             }