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,
|
||||
}) : events = events ?? [] {
|
||||
sub = room.client.onEvent.stream.listen(_handleEventUpdate);
|
||||
|
||||
// If the timeline is limited we want to clear our events cache
|
||||
roomSub = room.client.onSync.stream
|
||||
.where((sync) => sync.rooms?.join?[room.id]?.timeline?.limited == true)
|
||||
.listen((_) {
|
||||
this.events.clear();
|
||||
aggregatedEvents.clear();
|
||||
});
|
||||
.listen(_removeEventsNotInThisSync);
|
||||
|
||||
sessionIdReceivedSub =
|
||||
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!
|
||||
void cancelSubscriptions() {
|
||||
sub?.cancel();
|
||||
|
|
|
|||
Loading…
Reference in New Issue