rate limited builds for unread room badge, don't call to load chat counts until it's needed for the UI

pull/1384/head
ggurdin 1 year ago
parent 280915fc96
commit c9e023e684

@ -451,9 +451,22 @@ class _SpaceViewState extends State<SpaceView> {
// #Pangea
Future<void> loadChatCounts() async {
for (final Room room in Matrix.of(context).client.rooms) {
if (room.isSpace && !chatCounts.containsKey(room.id)) {
await loadHierarchy(null, room.id);
// if not in the call spaces view, don't load chat count yet
if (widget.controller.activeSpaceId != null) return;
final List<Room> allSpaces =
Matrix.of(context).client.rooms.where((room) => room.isSpace).toList();
for (final Room space in allSpaces) {
// check if the space is visible in the all spaces list
final bool isRootSpace = !allSpaces.any(
(parentSpace) =>
parentSpace.spaceChildren.any((child) => child.roomId == space.id),
);
// if it's visible, and it hasn't been loaded yet, load chat count
if (isRootSpace && !chatCounts.containsKey(space.id)) {
await loadHierarchy(null, space.id);
}
}
}
@ -479,6 +492,7 @@ class _SpaceViewState extends State<SpaceView> {
event.isSpaceChildUpdate(
widget.controller.activeSpaceId!,
)) {
debugPrint("refresh on update");
await loadHierarchy();
}
setState(() => refreshing = false);

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:badges/badges.dart' as b;
import 'package:fluffychat/utils/stream_extension.dart';
import 'package:flutter/material.dart';
import 'package:matrix/matrix.dart';
import 'matrix.dart';
@ -24,7 +24,10 @@ class UnreadRoomsBadge extends StatelessWidget {
.client
.onSync
.stream
.where((syncUpdate) => syncUpdate.hasRoomUpdate),
.where((syncUpdate) => syncUpdate.hasRoomUpdate)
// #Pangea
.rateLimit(const Duration(seconds: 1)),
// Pangea#
builder: (context, _) {
// #Pangea
// final unreadCount = Matrix.of(context)

Loading…
Cancel
Save