From af6b503656ad1095ba0d2a60ccc78da6d0e43c7e Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 19 Dec 2024 11:13:39 -0500 Subject: [PATCH] fix(search): order personal messages by lastMessageTimestamp --- .../main/app_search/location_menu_sub_item.nim | 6 ++++++ .../main/app_search/location_menu_sub_model.nim | 4 ++++ src/app/modules/main/app_search/module.nim | 8 +++++--- .../StatusQ/Popups/StatusSearchLocationMenu.qml | 14 ++++++++++---- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/app/modules/main/app_search/location_menu_sub_item.nim b/src/app/modules/main/app_search/location_menu_sub_item.nim index f812da7565..bb86cb5681 100644 --- a/src/app/modules/main/app_search/location_menu_sub_item.nim +++ b/src/app/modules/main/app_search/location_menu_sub_item.nim @@ -11,6 +11,7 @@ type colorId: int colorHash: color_hash_model.Model position: int + lastMessageTimestamp: int proc initSubItem*( value, @@ -30,6 +31,7 @@ proc initSubItem*( result.isUserIcon = isUserIcon result.isImage = isImage result.position = position + result.lastMessageTimestamp = lastMessageTimestamp result.colorId = colorId result.colorHash = color_hash_model.newModel() result.colorHash.setItems(map(colorHash, x => color_hash_item.initItem(x.len, x.colorIdx))) @@ -55,6 +57,7 @@ proc toJsonNode*(self: SubItem): JsonNode = "value": self.value, "text": self.text, "position": self.position, + "lastMessageTimestamp": self.lastMessageTimestamp, "imageSource": self.image, "iconName": self.icon, "iconColor": self.iconColor, @@ -67,6 +70,9 @@ proc toJsonNode*(self: SubItem): JsonNode = proc position*(self: SubItem): int = return self.position +proc lastMessageTimestamp*(self: SubItem): int = + return self.lastMessageTimestamp + proc isUserIcon*(self: SubItem): bool = return self.isUserIcon diff --git a/src/app/modules/main/app_search/location_menu_sub_model.nim b/src/app/modules/main/app_search/location_menu_sub_model.nim index 218e70752d..33dd9d01cd 100644 --- a/src/app/modules/main/app_search/location_menu_sub_model.nim +++ b/src/app/modules/main/app_search/location_menu_sub_model.nim @@ -12,6 +12,7 @@ type IsUserIcon IsImage Position + LastMessageTimestamp ColorId ColorHash @@ -61,6 +62,7 @@ QtObject: SubModelRole.IsUserIcon.int:"isUserIcon", SubModelRole.IsImage.int:"isImage", SubModelRole.Position.int:"position", + SubModelRole.LastMessageTimestamp.int:"lastMessageTimestamp", SubModelRole.ColorId.int:"colorId", SubModelRole.ColorHash.int:"colorHash" }.toTable @@ -92,6 +94,8 @@ QtObject: result = newQVariant(item.isImage) of SubModelRole.Position: result = newQVariant(item.position) + of SubModelRole.LastMessageTimestamp: + result = newQVariant(item.lastMessageTimestamp) of SubModelRole.ColorId: result = newQVariant(item.colorId) of SubModelRole.ColorHash: diff --git a/src/app/modules/main/app_search/module.nim b/src/app/modules/main/app_search/module.nim index c95c0b34e7..e76704995b 100644 --- a/src/app/modules/main/app_search/module.nim +++ b/src/app/modules/main/app_search/module.nim @@ -99,12 +99,13 @@ proc getChatSubItems(self: Module, chats: seq[ChatDto], categories: seq[Category let subItem = location_menu_sub_item.initSubItem( chatDto.id, chatName, - if (chatImage != ""): chatImage else: chatDto.emoji, - "", + image = if (chatImage != ""): chatImage else: chatDto.emoji, + icon = "", chatDto.color, isOneToOneChat, isImage = chatImage != "", chatDto.position, + chatDto.timestamp.int, colorId, colorHash, ) @@ -120,11 +121,12 @@ proc getChatSubItems(self: Module, chats: seq[ChatDto], categories: seq[Category chat.id, chat.name, chat.emoji, - "", + icon = "", chat.color, isUserIcon = false, isImage = false, chatPosition, + chat.timestamp.int, )) highestPosition += categoryChats[categoryPosition].len diff --git a/ui/StatusQ/src/StatusQ/Popups/StatusSearchLocationMenu.qml b/ui/StatusQ/src/StatusQ/Popups/StatusSearchLocationMenu.qml index 4e857a2596..9344708e1b 100644 --- a/ui/StatusQ/src/StatusQ/Popups/StatusSearchLocationMenu.qml +++ b/ui/StatusQ/src/StatusQ/Popups/StatusSearchLocationMenu.qml @@ -123,10 +123,16 @@ StatusMenu { menu: subMenuDelegate model: SortFilterProxyModel { sourceModel: subMenuDelegate.subItemsModel - sorters: RoleSorter { - roleName: "position" - sortOrder: Qt.AscendingOrder - } + sorters: [ + RoleSorter { + roleName: "position" + sortOrder: Qt.AscendingOrder + }, + RoleSorter { + roleName: "lastMessageTimestamp" + sortOrder: Qt.DescendingOrder + } + ] } delegate: StatusSearchPopupMenuItem {