From 22b8d145d99220e3c281e137a270b72c08125e91 Mon Sep 17 00:00:00 2001 From: sherlock Date: Mon, 2 Oct 2023 10:34:59 +0700 Subject: [PATCH] hot-fix: chat list out of order --- .../extensions/client_extension.dart | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/presentation/extensions/client_extension.dart b/lib/presentation/extensions/client_extension.dart index b6c9b473f9..89a599277b 100644 --- a/lib/presentation/extensions/client_extension.dart +++ b/lib/presentation/extensions/client_extension.dart @@ -3,27 +3,21 @@ import 'package:fluffychat/presentation/enum/chat_list/chat_list_enum.dart'; import 'package:matrix/matrix.dart'; extension ClientExtension on Client { - static const int _ascendingOrder = 1; + static const int newerChat = -1; - static const int _descendingOrder = -1; + static const int olderChat = 1; - int _sortListRomByTimeCreatedMessage(Room currentRoom, Room nextRoom) { - return nextRoom.timeCreated.compareTo(currentRoom.timeCreated); - } - - int _sortListRoomByPinMessage(Room currentRoom, Room nextRoom) { - if (nextRoom.isFavourite && !currentRoom.isFavourite) { - return _ascendingOrder; - } else { - return _descendingOrder; + int chatListItemComparator(Room room1, Room room2) { + if (room1.isFavourite ^ room2.isFavourite) { + return room1.isFavourite ? newerChat : olderChat; } + return room2.timeCreated.compareTo(room1.timeCreated); } List filteredRoomsForAll(ActiveFilter activeFilter) { return rooms .where(activeFilter.getRoomFilterByActiveFilter()) - .sorted(_sortListRomByTimeCreatedMessage) - .sorted(_sortListRoomByPinMessage) + .sorted(chatListItemComparator) .toList(); } }