Merge branch 'timeline-fix-requesthistory' into 'master'

[Timeline] Fix requesthistory

See merge request famedly/famedlysdk!90
This commit is contained in:
Christian Pauly 2019-09-30 09:21:57 +00:00
commit cbba4c47b2

View file

@ -42,13 +42,20 @@ class Timeline {
final onTimelineInsertCallback onInsert;
StreamSubscription<EventUpdate> sub;
bool _requestingHistoryLock = false;
Future<void> requestHistory({int historyCount = Room.DefaultHistoryCount}) {
return room.requestHistory(
Future<void> 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);
}