Subspace support
This commit is contained in:
parent
67ddc528a4
commit
50c56206db
3 changed files with 29 additions and 12 deletions
|
|
@ -1,9 +1,9 @@
|
|||
import "package:collection/collection.dart";
|
||||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/client_controller.dart";
|
||||
import "package:nexus/helpers/extensions/get_full_room.dart";
|
||||
import "package:nexus/helpers/extensions/room_to_children.dart";
|
||||
import "package:nexus/models/space.dart";
|
||||
|
||||
class SpacesController extends AsyncNotifier<IList<Space>> {
|
||||
|
|
@ -60,16 +60,7 @@ class SpacesController extends AsyncNotifier<IList<Space>> {
|
|||
avatar: space.avatar,
|
||||
id: space.roomData.id,
|
||||
roomData: space.roomData,
|
||||
children: await Future.wait(
|
||||
space.roomData.spaceChildren
|
||||
.map(
|
||||
(child) => client.rooms.firstWhereOrNull(
|
||||
(room) => room.id == child.roomId,
|
||||
),
|
||||
)
|
||||
.nonNulls
|
||||
.map((room) => room.fullRoom),
|
||||
),
|
||||
children: await space.roomData.getAllChildren(client),
|
||||
),
|
||||
),
|
||||
)),
|
||||
|
|
|
|||
26
lib/helpers/extensions/room_to_children.dart
Normal file
26
lib/helpers/extensions/room_to_children.dart
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import "package:collection/collection.dart";
|
||||
import "package:matrix/matrix.dart";
|
||||
import "package:nexus/helpers/extensions/get_full_room.dart";
|
||||
import "package:nexus/models/full_room.dart";
|
||||
|
||||
extension RoomToChildren on Room {
|
||||
Future<List<FullRoom>> getAllChildren(Client client) async {
|
||||
final direct = await Future.wait(
|
||||
spaceChildren
|
||||
.map(
|
||||
(child) => client.rooms
|
||||
.firstWhereOrNull((r) => r.id == child.roomId)
|
||||
?.fullRoom,
|
||||
)
|
||||
.nonNulls,
|
||||
);
|
||||
|
||||
return (await Future.wait(
|
||||
direct.map(
|
||||
(child) async => child.roomData.isSpace
|
||||
? await child.roomData.getAllChildren(client)
|
||||
: [child],
|
||||
),
|
||||
)).expand((list) => list).toList();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue