From 70c03250fe4084d7c80797915937aefb68cacdad Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 30 Sep 2019 09:21:57 +0000 Subject: [PATCH] [Timeline] Fix requesthistory --- lib/src/Timeline.dart | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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); }