diff --git a/lib/src/Timeline.dart b/lib/src/Timeline.dart index 2db6cdf..f2a422b 100644 --- a/lib/src/Timeline.dart +++ b/lib/src/Timeline.dart @@ -42,13 +42,20 @@ class Timeline { final onTimelineInsertCallback onInsert; StreamSubscription sub; + bool _requestingHistoryLock = false; - Future requestHistory({int historyCount = Room.DefaultHistoryCount}) { - return room.requestHistory( + Future requestHistory( + {int historyCount = Room.DefaultHistoryCount}) async { + if (!_requestingHistoryLock) { + _requestingHistoryLock = true; + await room.requestHistory( historyCount: historyCount, onHistoryReceived: () { if (room.prev_batch.isEmpty || room.prev_batch == null) events = []; - }); + }, + ); + _requestingHistoryLock = false; + } } Timeline({this.room, this.events, this.onUpdate, this.onInsert}) { @@ -95,6 +102,11 @@ class Timeline { newEvent = Event.fromJson(eventUpdate.content, room); + if (eventUpdate.type == "history" && + events.indexWhere( + (e) => e.eventId == eventUpdate.content["event_id"]) != + -1) return; + events.insert(0, newEvent); if (onInsert != null) onInsert(0); }