small cleanups
This commit is contained in:
parent
004c3bcd0d
commit
721727d48c
3 changed files with 21 additions and 12 deletions
|
|
@ -21,7 +21,7 @@ See [Effective Dart: Style](https://dart.dev/effective-dart/style) for general r
|
|||
Controllers live in `lib/controllers/` and provide a source that exposes data and logic via Riverpod providers, allowing other parts of the code to watch state changes with ref.watch (`ref.watch(MyController.provider)`), access the current value with ref.read (`ref.read(MyController.provider)`), and run helper methods on those classes using the notifier:
|
||||
|
||||
```dart
|
||||
ref.watch(MyController.provider.notifier).helperMethod()
|
||||
ref.read(MyController.provider.notifier).helperMethod()
|
||||
```
|
||||
|
||||
We use an object oriented style for controllers, where `provider` is a static member on the controller class. E.g.
|
||||
|
|
|
|||
|
|
@ -91,19 +91,25 @@ class ClientController extends AsyncNotifier<int> {
|
|||
callback,
|
||||
) async {
|
||||
final bufferPointer = data.toGomuksBufferPtr();
|
||||
|
||||
try {
|
||||
final handle = await future;
|
||||
|
||||
final response = await Isolate.run(
|
||||
() => callback(handle, bufferPointer.ref),
|
||||
);
|
||||
|
||||
calloc.free(bufferPointer);
|
||||
|
||||
final json = response.buf.toJson();
|
||||
|
||||
if (response.command.cast<Utf8>().toDartString() == "error") {
|
||||
throw json;
|
||||
}
|
||||
|
||||
return json;
|
||||
} finally {
|
||||
calloc.free(bufferPointer.ref.base);
|
||||
calloc.free(bufferPointer);
|
||||
}
|
||||
}
|
||||
|
||||
Future<(Event, RoomMetadata)> handlePush(Map<String, dynamic> data) async {
|
||||
|
|
@ -250,9 +256,11 @@ class ClientController extends AsyncNotifier<int> {
|
|||
Future<void> logout() => _sendCommand("logout");
|
||||
|
||||
Future<void> markRead(Room room) async {
|
||||
if (room.timeline.isEmpty || room.metadata == null) return;
|
||||
final eventRowId = room.timeline[room.timeline.keys.reduce(max)];
|
||||
final event = eventRowId == null ? null : room.events[eventRowId];
|
||||
if (event == null || room.metadata == null) return;
|
||||
|
||||
if (event == null) return;
|
||||
|
||||
await _sendCommand("mark_read", {
|
||||
"room_id": room.metadata!.id,
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ class RoomChatController(final String roomId)
|
|||
if (state.isLoading) return;
|
||||
|
||||
state = .loading();
|
||||
|
||||
final timelineKeys = ref
|
||||
.read(RoomsController.provider.select((value) => value[roomId]))
|
||||
?.timeline
|
||||
|
|
|
|||
Loading…
Reference in a new issue