From b4d5aaadaf50781a25f996026afd660b86aa866f Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Tue, 29 Sep 2026 17:00:17 -0400 Subject: [PATCH] add fetched individual events to RoomsController --- lib/controllers/event.dart | 27 ++++++++++++++++++++++----- lib/controllers/gomuks_listener.dart | 1 - lib/controllers/notifications.dart | 2 -- lib/controllers/room_chat.dart | 4 ---- lib/controllers/rooms.dart | 5 ++++- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/controllers/event.dart b/lib/controllers/event.dart index 7a1e5dc..5c6513b 100644 --- a/lib/controllers/event.dart +++ b/lib/controllers/event.dart @@ -16,11 +16,28 @@ class EventController(final GetEventRequest request) (event) => event.eventId == request.eventId, ); - return event ?? - await ref - .watch(ClientController.provider.notifier) - .getEvent(request) - .onError((_, _) => null); + if (event != null) return event; + + final fetchedEvent = await ref + .watch(ClientController.provider.notifier) + .getEvent(request) + .onError((_, _) => null); + + if (fetchedEvent != null) { + ref + .watch(RoomsController.provider.notifier) + .update( + .new({ + request.roomId: .new( + events: .new({fetchedEvent.rowId: fetchedEvent}), + ), + }), + ); + + return fetchedEvent; + } + + return null; } static final provider = AsyncNotifierProvider.family diff --git a/lib/controllers/gomuks_listener.dart b/lib/controllers/gomuks_listener.dart index dd75cf3..489af72 100644 --- a/lib/controllers/gomuks_listener.dart +++ b/lib/controllers/gomuks_listener.dart @@ -59,7 +59,6 @@ class GomuksListenerController extends AsyncNotifier { .new({ event.roomId: .new(events: .new({event.rowId: event})), }), - .new(), ); break; diff --git a/lib/controllers/notifications.dart b/lib/controllers/notifications.dart index 33e1cb3..43d9b7a 100644 --- a/lib/controllers/notifications.dart +++ b/lib/controllers/notifications.dart @@ -35,7 +35,6 @@ class NotificationsController([final NotificationsRequest? request]) ), ), }), - .new(), ); return .new(mentions.map((event) => (event.rowId, event.roomId))); @@ -79,7 +78,6 @@ class NotificationsController([final NotificationsRequest? request]) ), ), }), - .new(), ); return currentNotifications.addAll( diff --git a/lib/controllers/room_chat.dart b/lib/controllers/room_chat.dart index a2d9590..7150206 100644 --- a/lib/controllers/room_chat.dart +++ b/lib/controllers/room_chat.dart @@ -77,7 +77,6 @@ class RoomChatController(final ChatParams info) ), ), }), - .new(), ); return .new( timeline: .new(events.map((element) => element.rowId)), @@ -149,7 +148,6 @@ class RoomChatController(final ChatParams info) ), ), }), - .new(), ); } else { final paginationResponse = await client.paginateManual( @@ -173,7 +171,6 @@ class RoomChatController(final ChatParams info) ), ), }), - .new(), ); final eventRowIds = paginationResponse.events @@ -274,7 +271,6 @@ class RoomChatController(final ChatParams info) clientSticky: .new({event.rowId}), ), }), - .new(), ); } diff --git a/lib/controllers/rooms.dart b/lib/controllers/rooms.dart index 2e8c2a9..034f2f8 100644 --- a/lib/controllers/rooms.dart +++ b/lib/controllers/rooms.dart @@ -33,7 +33,10 @@ class RoomsController extends Notifier> { .new(), ); - void update(IMap rooms, ISet leftRooms) { + void update( + IMap rooms, [ + ISet leftRooms = const ISet.empty(), + ]) { final merged = rooms.entries.fold(state, (acc, entry) { final roomId = entry.key; final incoming = entry.value;