diff --git a/lib/pages/chat_list.dart b/lib/pages/chat_list.dart index 575d2e97..bfdb7d0f 100644 --- a/lib/pages/chat_list.dart +++ b/lib/pages/chat_list.dart @@ -51,10 +51,14 @@ class ChatListController extends State { String _activeSpaceId; String get activeSpaceId => _activeSpaceId; + final _roomCheckCache = {}; void setActiveSpaceId(BuildContext context, String spaceId) { Scaffold.of(context).openEndDrawer(); - setState(() => _activeSpaceId = spaceId); + setState(() { + _activeSpaceId = spaceId; + _roomCheckCache.clear(); + }); } void editSpace(BuildContext context, String spaceId) async { @@ -189,26 +193,35 @@ class ChatListController extends State { } bool roomCheck(Room room) { - if (room.isSpace && room.membership == Membership.join) return false; + if (room.isSpace && room.membership == Membership.join) { + return false; + } if (activeSpaceId != null) { + if (_roomCheckCache.containsKey(room.id)) { + return _roomCheckCache[room.id]; + } + final retCache = (b) { + _roomCheckCache[room.id] = b; + return b; + }; final space = Matrix.of(context).client.getRoomById(activeSpaceId); if (space.spaceChildren?.any((child) => child.roomId == room.id) ?? false) { - return true; + return retCache(true); } if (room.spaceParents?.any((parent) => parent.roomId == activeSpaceId) ?? false) { - return true; + return retCache(true); } if (room.isDirectChat && room.summary?.mHeroes != null && room.summary.mHeroes.any((userId) { final user = space.getState(EventTypes.RoomMember, userId)?.asUser; - return user != null && user.membership == Membership.join; + return retCache(user != null && user.membership == Membership.join); })) { - return true; + return retCache(true); } - return false; + return retCache(false); } return true; } @@ -382,6 +395,7 @@ class ChatListController extends State { (space.summary?.mJoinedMemberCount ?? 0); if (localMembers < actualMembersCount) { await space.requestParticipants(); + _roomCheckCache.clear(); } } return true;