This commit is contained in:
Henry Hiles 2025-11-11 14:45:01 -05:00
commit aaeee8e355
No known key found for this signature in database
10 changed files with 527 additions and 164 deletions

View file

@ -1,7 +1,8 @@
import "package:flutter/widgets.dart";
import "package:matrix/matrix.dart";
import "package:collection/collection.dart";
import "package:flutter/material.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:nexus/controllers/client_controller.dart";
import "package:nexus/helpers/extension_helper.dart";
import "package:nexus/models/space.dart";
class SpacesController extends AsyncNotifier<List<Space>> {
@ -9,25 +10,60 @@ class SpacesController extends AsyncNotifier<List<Space>> {
Future<List<Space>> build() async {
final client = await ref.watch(ClientController.provider.future);
return Future.wait(
client.rooms.where((room) => room.isSpace).map((data) async {
final thumb = await data.avatar?.getThumbnailUri(
client,
width: 40,
height: 40,
);
return Space(
roomData: data,
avatar: thumb == null
? null
: Image.network(
thumb.toString(),
width: 40,
headers: {"authorization": "Bearer ${client.accessToken}"},
final topLevel = await Future.wait(
client.rooms
.where((room) => !room.isDirectChat)
.where(
(room) => client.rooms
.where((room) => room.isSpace)
.every(
(match) => match.spaceChildren.every(
(child) => child.roomId != room.id,
),
),
);
}),
)
.map((room) => room.fullRoom),
);
final topLevelSpaces = topLevel.where((r) => r.roomData.isSpace).toList();
final topLevelRooms = topLevel.where((r) => !r.roomData.isSpace).toList();
return [
Space(
title: "Home",
children: topLevelRooms,
avatar: Icon(Icons.home),
fake: true,
),
Space(
title: "Direct Messages",
children: await Future.wait(
client.rooms
.where((room) => room.isDirectChat)
.map((room) => room.fullRoom),
),
avatar: Icon(Icons.person),
fake: true,
),
...(await Future.wait(
topLevelSpaces.map(
(space) async => Space(
title: space.title,
avatar: space.avatar,
children: await Future.wait(
space.roomData.spaceChildren
.map(
(child) => client.rooms.firstWhereOrNull(
(room) => room.id == child.roomId,
),
)
.nonNulls
.map((room) => room.fullRoom),
),
),
),
)),
];
}
static final provider = AsyncNotifierProvider<SpacesController, List<Space>>(