add room directory support
This commit is contained in:
parent
033c7f9c05
commit
e382499a2a
1 changed files with 868 additions and 245 deletions
39
lib/controllers/room_directory.dart
Normal file
39
lib/controllers/room_directory.dart
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import "package:flutter_riverpod/experimental/mutation.dart";
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:nexus/controllers/client.dart";
|
||||
import "package:nexus/models/room_directory.dart";
|
||||
|
||||
/// The public room directory of a server, or of the user's own if null.
|
||||
class RoomDirectoryController(final String? server)
|
||||
extends AsyncNotifier<RoomDirectory> {
|
||||
@override
|
||||
Future<RoomDirectory> build() => ref
|
||||
.read(ClientController.provider.notifier)
|
||||
.getRoomDirectory(.new(server: server));
|
||||
|
||||
Future<void> loadMore() async {
|
||||
final current = await future;
|
||||
if (current.nextBatch == null) return;
|
||||
|
||||
final next = await ref
|
||||
.read(ClientController.provider.notifier)
|
||||
.getRoomDirectory(.new(server: server, since: current.nextBatch));
|
||||
|
||||
if (!ref.mounted) return;
|
||||
|
||||
state = AsyncData(
|
||||
current.copyWith(
|
||||
rooms: current.rooms.addAll(next.rooms),
|
||||
nextBatch: next.nextBatch,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Loading the next page of a directory, keyed by its server
|
||||
static final loadMoreMutation = Mutation<void>();
|
||||
|
||||
static final provider = AsyncNotifierProvider.family
|
||||
.autoDispose<RoomDirectoryController, RoomDirectory, String?>(
|
||||
RoomDirectoryController.new,
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue