diff --git a/lib/src/database/hive_collections_database.dart b/lib/src/database/hive_collections_database.dart index b3dd839c..cab11485 100644 --- a/lib/src/database/hive_collections_database.dart +++ b/lib/src/database/hive_collections_database.dart @@ -990,7 +990,8 @@ class HiveCollectionsDatabase extends DatabaseApi { Future storeEventUpdate(EventUpdate eventUpdate, Client client) async { // Ephemerals should not be stored if (eventUpdate.type == EventUpdateType.ephemeral) return; - final tmpRoom = Room(id: eventUpdate.roomID, client: client); + final tmpRoom = client.getRoomById(eventUpdate.roomID) ?? + Room(id: eventUpdate.roomID, client: client); // In case of this is a redaction event if (eventUpdate.content['type'] == EventTypes.Redaction) { @@ -1002,6 +1003,13 @@ class HiveCollectionsDatabase extends DatabaseApi { await _eventsBox.put( TupleKey(eventUpdate.roomID, event.eventId).toString(), event.toJson()); + + if (tmpRoom.lastEvent?.eventId == event.eventId) { + await _roomStateBox.put( + TupleKey(eventUpdate.roomID, event.type).toString(), + {'': event.toJson()}, + ); + } } } diff --git a/lib/src/database/hive_database.dart b/lib/src/database/hive_database.dart index 6135700a..5f6da7e6 100644 --- a/lib/src/database/hive_database.dart +++ b/lib/src/database/hive_database.dart @@ -935,7 +935,8 @@ class FamedlySdkHiveDatabase extends DatabaseApi { // In case of this is a redaction event if (eventUpdate.content['type'] == EventTypes.Redaction) { - final tmpRoom = Room(id: eventUpdate.roomID, client: client); + final tmpRoom = client.getRoomById(eventUpdate.roomID) ?? + Room(id: eventUpdate.roomID, client: client); final eventId = eventUpdate.content.tryGet('redacts'); final event = eventId != null ? await getEventById(eventId, tmpRoom) : null; @@ -944,6 +945,13 @@ class FamedlySdkHiveDatabase extends DatabaseApi { await _eventsBox.put( MultiKey(eventUpdate.roomID, event.eventId).toString(), event.toJson()); + + if (tmpRoom.lastEvent?.eventId == event.eventId) { + await _roomStateBox.put( + MultiKey(eventUpdate.roomID, event.type).toString(), + {'': event.toJson()}, + ); + } } }