fix: use originServerTs to check if state event is old

Due to server bugs or whatever it sometimes
happens that old state events appear
in the setState method in the room class.
Previously we checked if we already know
this event ID, but for this we needed to
check the timeline which is very fluid.
Also this is a database operation in a
non-async method which works in Hive but
not in Sembast.
Using originServerTs is not 100% safe as
well but should be more stable because
the chance that servers have veeery wrong
time (which is necessary here) is much
lower than the risk that the timeline
is not long enough to know the
old event.
This commit is contained in:
Krille Fear 2021-11-15 10:57:55 +01:00
parent 77d7249699
commit b7565af56f
3 changed files with 2 additions and 7 deletions

View File

@ -67,8 +67,6 @@ abstract class DatabaseApi {
Future<Event?> getEventById(String eventId, Room room); Future<Event?> getEventById(String eventId, Room room);
bool eventIsKnown(String eventId, String roomId);
Future<void> forgetRoom(String roomId); Future<void> forgetRoom(String roomId);
Future<void> clearCache(); Future<void> clearCache();

View File

@ -371,10 +371,6 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
return Event.fromJson(convertToJson(raw), room); return Event.fromJson(convertToJson(raw), room);
} }
@override
bool eventIsKnown(String eventId, String roomId) =>
_eventsBox.keys.contains(MultiKey(roomId, eventId).toString());
/// Loads a whole list of events at once from the store for a specific room /// Loads a whole list of events at once from the store for a specific room
Future<List<Event>> _getEventsByIds(List<String> eventIds, Room room) => Future<List<Event>> _getEventsByIds(List<String> eventIds, Room room) =>
Future.wait(eventIds Future.wait(eventIds

View File

@ -203,7 +203,8 @@ class Room {
final prevEvent = getState(state.type, stateKey); final prevEvent = getState(state.type, stateKey);
if (prevEvent != null && if (prevEvent != null &&
prevEvent.eventId != state.eventId && prevEvent.eventId != state.eventId &&
client.database?.eventIsKnown(state.eventId, roomId) == true) { prevEvent.originServerTs.millisecondsSinceEpoch >
state.originServerTs.millisecondsSinceEpoch) {
return; return;
} }