fix: Do not set old events as state events
Previously we had a check which uses the old sortOrder value. This check has been removed with the refactoring which leads to bug #209. This fixes it by checking if the event is already known in the database. I am not 100% happy with this solution as this database api is impossible to be implemented with a sqlite db. Once we start to refactor the whole sync update logic we maybe could find a better way, but only the fox god knows.
This commit is contained in:
parent
1e2ccabe85
commit
00cc439122
|
|
@ -69,6 +69,8 @@ abstract class DatabaseApi {
|
||||||
|
|
||||||
Future<Event?> getEventById(int clientId, String eventId, Room room);
|
Future<Event?> getEventById(int clientId, String eventId, Room room);
|
||||||
|
|
||||||
|
bool eventIsKnown(int clientId, String eventId, String roomId);
|
||||||
|
|
||||||
Future<void> forgetRoom(int clientId, String roomId);
|
Future<void> forgetRoom(int clientId, String roomId);
|
||||||
|
|
||||||
Future<void> clearCache(int clientId);
|
Future<void> clearCache(int clientId);
|
||||||
|
|
|
||||||
|
|
@ -344,6 +344,10 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
return Event.fromJson(convertToJson(raw), room);
|
return Event.fromJson(convertToJson(raw), room);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool eventIsKnown(int clientId, 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
|
||||||
|
|
|
||||||
|
|
@ -336,6 +336,15 @@ class Room {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do not set old events as state events
|
||||||
|
final prevEvent = getState(state.type, state.stateKey);
|
||||||
|
if (prevEvent != null &&
|
||||||
|
prevEvent.eventId != state.eventId &&
|
||||||
|
client.database != null &&
|
||||||
|
client.database.eventIsKnown(client.id, state.eventId, state.roomId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
states[state.type] ??= {};
|
states[state.type] ??= {};
|
||||||
states[state.type][state.stateKey ?? ''] = state;
|
states[state.type][state.stateKey ?? ''] = state;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue