From b06dbd1c00113f93e8fa2ffa4926f277209012d9 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 1 Nov 2024 17:56:06 +0300 Subject: [PATCH] Added support of pinned chats from filters to forward box. --- .../SourceFiles/window/window_peer_menu.cpp | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index cf2244689..c93c9fecc 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -2056,7 +2056,40 @@ QPointer ShowForwardMessagesBox( box->setIgnoreHiddenRowsOnSearch(true); auto applyFilter = [=](FilterId id) { box->scrollToY(0); - const auto &list = session->data().chatsFilters().list(); + auto &filters = session->data().chatsFilters(); + const auto &list = filters.list(); + if (list.size() <= 1) { + return; + } + const auto pinned = filters.chatsList(id)->pinned()->order(); + box->peerListSortRows([&]( + const PeerListRow &r1, + const PeerListRow &r2) { + const auto it1 = ranges::find_if(pinned, [&]( + const Dialogs::Key &k) { + return k.peer() == r1.peer(); + }); + const auto it2 = ranges::find_if(pinned, [&]( + const Dialogs::Key &k) { + return k.peer() == r2.peer(); + }); + if (it1 == pinned.end() && it2 != pinned.end()) { + return false; + } else if (it2 == pinned.end() && it1 != pinned.end()) { + return true; + } else if (it1 != pinned.end() && it2 != pinned.end()) { + return it1 < it2; + } + const auto history1 = session->data().history(r1.peer()); + const auto history2 = session->data().history(r2.peer()); + const auto date1 = history1->lastMessage() + ? history1->lastMessage()->date() + : TimeId(0); + const auto date2 = history2->lastMessage() + ? history2->lastMessage()->date() + : TimeId(0); + return date1 > date2; + }); const auto filter = ranges::find( list, id,