From 0e867402bc96900b5b57f55db0881d296364a119 Mon Sep 17 00:00:00 2001 From: Krille Date: Tue, 26 Mar 2024 13:30:06 +0100 Subject: [PATCH] chore: Sort archive by last activity --- lib/src/client.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/src/client.dart b/lib/src/client.dart index 60d54b21..fb7e8e1c 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -1037,6 +1037,15 @@ class Client extends MatrixApi { await _storeArchivedRoom(entry.key, entry.value); } } + + // Sort the archived rooms by last event originServerTs as this is the + // best indicator we have to sort them. For archived rooms where we don't + // have any, we move them to the bottom. + final beginningOfTime = DateTime.fromMillisecondsSinceEpoch(0); + _archivedRooms.sort((b, a) => + (a.room.lastEvent?.originServerTs ?? beginningOfTime) + .compareTo(b.room.lastEvent?.originServerTs ?? beginningOfTime)); + return _archivedRooms; }