diff --git a/lib/pages/chat_list/chat_list_view.dart b/lib/pages/chat_list/chat_list_view.dart index ee6743f7..9bd110e2 100644 --- a/lib/pages/chat_list/chat_list_view.dart +++ b/lib/pages/chat_list/chat_list_view.dart @@ -48,6 +48,7 @@ class ChatListView extends StatelessWidget { @override Widget build(BuildContext context) { + final client = Matrix.of(context).client; return StreamBuilder( stream: Matrix.of(context).onShareContentChanged.stream, builder: (_, __) { @@ -61,9 +62,9 @@ class ChatListView extends StatelessWidget { child: Row( children: [ if (FluffyThemes.isColumnMode(context) && - FluffyThemes.getDisplayNavigationRail(context)) ...[ + FluffyThemes.getDisplayNavigationRail(context) && + controller.waitForFirstSync) ...[ Builder(builder: (context) { - final client = Matrix.of(context).client; final allSpaces = client.rooms.where((room) => room.isSpace); final rootSpaces = allSpaces .where( @@ -74,6 +75,7 @@ class ChatListView extends StatelessWidget { ) .toList(); final destinations = getNavigationDestinations(context); + return SizedBox( width: 64, child: ListView.builder( diff --git a/lib/pages/chat_list/space_view.dart b/lib/pages/chat_list/space_view.dart index 12755849..e49beea4 100644 --- a/lib/pages/chat_list/space_view.dart +++ b/lib/pages/chat_list/space_view.dart @@ -30,6 +30,8 @@ class SpaceView extends StatefulWidget { class _SpaceViewState extends State { static final Map> _requests = {}; + String? prevBatch; + void _refresh() { setState(() { _requests.remove(widget.controller.activeSpaceId); @@ -37,8 +39,11 @@ class _SpaceViewState extends State { } Future getFuture(String activeSpaceId) => - _requests[activeSpaceId] ??= - Matrix.of(context).client.getSpaceHierarchy(activeSpaceId); + _requests[activeSpaceId] ??= Matrix.of(context).client.getSpaceHierarchy( + activeSpaceId, + maxDepth: 1, + from: prevBatch, + ); void _onJoinSpaceChild(SpaceRoomsChunk spaceChild) async { final client = Matrix.of(context).client; @@ -186,10 +191,10 @@ class _SpaceViewState extends State { final parentSpace = allSpaces.firstWhereOrNull((space) => space .spaceChildren .any((child) => child.roomId == activeSpaceId)); - final spaceChildren = response.rooms - ..sort((a, b) => a.roomType == 'm.space' ? -1 : 1); + final spaceChildren = response.rooms; + final canLoadMore = response.nextBatch != null; return ListView.builder( - itemCount: spaceChildren.length + 1, + itemCount: spaceChildren.length + 1 + (canLoadMore ? 1 : 0), controller: widget.scrollController, itemBuilder: (context, i) { if (i == 0) { @@ -213,6 +218,16 @@ class _SpaceViewState extends State { ); } i--; + if (canLoadMore && i == spaceChildren.length) { + return ListTile( + title: Text(L10n.of(context)!.loadMore), + trailing: const Icon(Icons.chevron_right_outlined), + onTap: () { + prevBatch = response.nextBatch; + _refresh(); + }, + ); + } final spaceChild = spaceChildren[i]; final room = client.getRoomById(spaceChild.roomId); if (room != null && !room.isSpace) {