Merge branch 'krille/get-event' into 'main'

feat: Get event in a room faster by searching in database

See merge request famedly/company/frontend/famedlysdk!988
This commit is contained in:
The one with the Braid 2022-03-24 13:16:51 +00:00
commit 27f3a7ec6d
1 changed files with 4 additions and 1 deletions

View File

@ -1411,9 +1411,12 @@ class Room {
return user; 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<Event?> getEventById(String eventID) async { Future<Event?> getEventById(String eventID) async {
try { try {
final dbEvent = await client.database?.getEventById(eventID, this);
if (dbEvent != null) return dbEvent;
final matrixEvent = await client.getOneRoomEvent(id, eventID); final matrixEvent = await client.getOneRoomEvent(id, eventID);
final event = Event.fromMatrixEvent(matrixEvent, this); final event = Event.fromMatrixEvent(matrixEvent, this);
if (event.type == EventTypes.Encrypted && client.encryptionEnabled) { if (event.type == EventTypes.Encrypted && client.encryptionEnabled) {