Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/src/models/timeline_chunk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ class TimelineChunk {
String nextBatch;

List<Event> events;
TimelineChunk({
required this.events,
this.prevBatch = '',
this.nextBatch = '',
});
TimelineChunk(
{required this.events, this.prevBatch = '', this.nextBatch = ''});

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other is! TimelineChunk) return false;

// Compare the lists of event ids regardless of order
final thisEventIds = events.map((e) => e.eventId).toSet();
final otherEventIds = other.events.map((e) => e.eventId).toSet();

return thisEventIds.length == otherEventIds.length &&
thisEventIds.containsAll(otherEventIds);
}
}
26 changes: 17 additions & 9 deletions lib/src/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,8 @@ class Room {
/// Is the room archived
bool get isArchived => membership == Membership.leave;

Timeline? _timeline;

/// Creates a timeline from the store. Returns a [Timeline] object. If you
/// just want to update the whole timeline on every change, use the [onUpdate]
/// callback. For updating only the parts that have changed, use the
Expand Down Expand Up @@ -1522,15 +1524,21 @@ class Room {
}
}

final timeline = Timeline(
room: this,
chunk: chunk,
onChange: onChange,
onRemove: onRemove,
onInsert: onInsert,
onNewEvent: onNewEvent,
onUpdate: onUpdate,
);
Timeline timeline;
if (_timeline != null && _timeline!.chunk == chunk) {
timeline = _timeline!;
chunk = _timeline!.chunk;
} else {
timeline = Timeline(
room: this,
chunk: chunk,
onChange: onChange,
onRemove: onRemove,
onInsert: onInsert,
onNewEvent: onNewEvent,
onUpdate: onUpdate);
_timeline = timeline;
}

// Fetch all users from database we have got here.
if (eventContextId == null) {
Expand Down