chore: Follow up fixes spaces

This commit is contained in:
Christian Pauly 2022-09-10 13:21:33 +02:00
parent 7f6c914fca
commit a4ee523849
2 changed files with 24 additions and 7 deletions

View File

@ -48,6 +48,7 @@ class ChatListView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final client = Matrix.of(context).client;
return StreamBuilder<Object?>(
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(

View File

@ -30,6 +30,8 @@ class SpaceView extends StatefulWidget {
class _SpaceViewState extends State<SpaceView> {
static final Map<String, Future<GetSpaceHierarchyResponse>> _requests = {};
String? prevBatch;
void _refresh() {
setState(() {
_requests.remove(widget.controller.activeSpaceId);
@ -37,8 +39,11 @@ class _SpaceViewState extends State<SpaceView> {
}
Future<GetSpaceHierarchyResponse> 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<SpaceView> {
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<SpaceView> {
);
}
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) {