Merge branch 'krille/limited-timeline-behavior' into 'main'
fix: Limited timeline clears too much events Closes #217 See merge request famedly/company/frontend/famedlysdk!907
This commit is contained in:
commit
64257735ac
|
|
@ -120,13 +120,12 @@ class Timeline {
|
||||||
this.onRemove,
|
this.onRemove,
|
||||||
}) : events = events ?? [] {
|
}) : events = events ?? [] {
|
||||||
sub = room.client.onEvent.stream.listen(_handleEventUpdate);
|
sub = room.client.onEvent.stream.listen(_handleEventUpdate);
|
||||||
|
|
||||||
// If the timeline is limited we want to clear our events cache
|
// If the timeline is limited we want to clear our events cache
|
||||||
roomSub = room.client.onSync.stream
|
roomSub = room.client.onSync.stream
|
||||||
.where((sync) => sync.rooms?.join?[room.id]?.timeline?.limited == true)
|
.where((sync) => sync.rooms?.join?[room.id]?.timeline?.limited == true)
|
||||||
.listen((_) {
|
.listen(_removeEventsNotInThisSync);
|
||||||
this.events.clear();
|
|
||||||
aggregatedEvents.clear();
|
|
||||||
});
|
|
||||||
sessionIdReceivedSub =
|
sessionIdReceivedSub =
|
||||||
room.onSessionKeyReceived.stream.listen(_sessionKeyReceived);
|
room.onSessionKeyReceived.stream.listen(_sessionKeyReceived);
|
||||||
|
|
||||||
|
|
@ -136,6 +135,13 @@ class Timeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Removes all entries from [events] which are not in this SyncUpdate.
|
||||||
|
void _removeEventsNotInThisSync(SyncUpdate sync) {
|
||||||
|
final newSyncEvents = sync.rooms?.join?[room.id]?.timeline?.events ?? [];
|
||||||
|
final keepEventIds = newSyncEvents.map((e) => e.eventId);
|
||||||
|
events.removeWhere((e) => !keepEventIds.contains(e.eventId));
|
||||||
|
}
|
||||||
|
|
||||||
/// Don't forget to call this before you dismiss this object!
|
/// Don't forget to call this before you dismiss this object!
|
||||||
void cancelSubscriptions() {
|
void cancelSubscriptions() {
|
||||||
sub?.cancel();
|
sub?.cancel();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue