Skip to content

Commit

Permalink
fix: Older state events overwrite newer ones on fetching history
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Feb 7, 2025
1 parent 41a9fbc commit 1a37f52
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2650,8 +2650,19 @@ class Client extends MatrixApi {
if (syncRoomUpdate is JoinedRoomUpdate) {
final state = syncRoomUpdate.state;

// If we are receiving states when fetching history we need to check if
// we are not overwriting a newer state.
if (direction == Direction.b) {
await room.postLoad();
state?.removeWhere((state) {
final existingState =
room.getState(state.type, state.stateKey ?? '');
if (existingState is! MatrixEvent) return false;
return existingState.originServerTs.isAfter(state.originServerTs);
});
}

if (state != null && state.isNotEmpty) {
// TODO: This method seems to be comperatively slow for some updates
await _handleRoomEvents(
room,
state,
Expand Down

0 comments on commit 1a37f52

Please sign in to comment.