From 269bea73505a822dd7355edcbff0ac16df294921 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 1 Oct 2019 09:39:15 +0000 Subject: [PATCH] [Lists] Add sort lock --- lib/src/RoomList.dart | 5 +++++ lib/src/Timeline.dart | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/src/RoomList.dart b/lib/src/RoomList.dart index e31031a..0803ea4 100644 --- a/lib/src/RoomList.dart +++ b/lib/src/RoomList.dart @@ -166,9 +166,14 @@ class RoomList { sortAndUpdate(); } + bool sortLock = false; + sort() { + if (sortLock) return; + sortLock = true; rooms?.sort((a, b) => b.timeCreated.toTimeStamp().compareTo(a.timeCreated.toTimeStamp())); + sortLock = false; } sortAndUpdate() { diff --git a/lib/src/Timeline.dart b/lib/src/Timeline.dart index f2a422b..f64597a 100644 --- a/lib/src/Timeline.dart +++ b/lib/src/Timeline.dart @@ -119,9 +119,18 @@ class Timeline { } } - sortAndUpdate() { + bool sortLock = false; + + sort() { + if (sortLock) return; + sortLock = true; events ?.sort((a, b) => b.time.toTimeStamp().compareTo(a.time.toTimeStamp())); + sortLock = false; + } + + sortAndUpdate() { + sort(); if (onUpdate != null) onUpdate(); } }