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(); } }