fix: Don't make space filter scrolling lag

This commit is contained in:
Sorunome 2021-08-14 18:09:34 +02:00
parent 91b29f7b70
commit 45c9321c70
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C

View File

@ -51,10 +51,14 @@ class ChatListController extends State<ChatList> {
String _activeSpaceId;
String get activeSpaceId => _activeSpaceId;
final _roomCheckCache = <String, bool>{};
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<ChatList> {
}
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<ChatList> {
(space.summary?.mJoinedMemberCount ?? 0);
if (localMembers < actualMembersCount) {
await space.requestParticipants();
_roomCheckCache.clear();
}
}
return true;