From 6b36d6bd79f8ee5607df6dc648b16dc202a43f5c Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Thu, 24 Mar 2022 14:10:41 +0100 Subject: [PATCH] feat: Get event in a room faster by searching in database --- lib/src/room.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index aa03cb1c..e224dd69 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1411,9 +1411,12 @@ class Room { return user; } - /// Searches for the event on the server. Returns null if not found. + /// Searches for the event in the local cache and then on the server if not + /// found. Returns null if not found anywhere. Future getEventById(String eventID) async { try { + final dbEvent = await client.database?.getEventById(eventID, this); + if (dbEvent != null) return dbEvent; final matrixEvent = await client.getOneRoomEvent(id, eventID); final event = Event.fromMatrixEvent(matrixEvent, this); if (event.type == EventTypes.Encrypted && client.encryptionEnabled) {