Fixed miss-order of archived dialogs in forward box.

This commit is contained in:
23rd 2024-11-19 03:48:08 +03:00 committed by John Preston
parent 1438046dd4
commit 244696ae24

View file

@ -2157,28 +2157,20 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
not_null<Controller*> controller; not_null<Controller*> controller;
base::unique_qptr<Ui::PopupMenu> menu; base::unique_qptr<Ui::PopupMenu> menu;
}; };
const auto state = [&] {
auto controller = std::make_unique<Controller>(session); const auto applyFilter = [=](not_null<PeerListBox*> box, FilterId id) {
const auto controllerRaw = controller.get();
auto init = [=](not_null<PeerListBox*> box) {
controllerRaw->setSearchNoResultsText(
tr::lng_bot_chats_not_found(tr::now));
box->setSpecialTabMode(true);
auto applyFilter = [=](FilterId id) {
box->scrollToY(0); box->scrollToY(0);
auto &filters = session->data().chatsFilters(); auto &filters = session->data().chatsFilters();
const auto &list = filters.list(); const auto &list = filters.list();
if (list.size() <= 1) { if (list.size() <= 1) {
return; return;
} }
const auto pinned = [&] { const auto pinnedList = [&](
const auto &list = id not_null<Dialogs::MainList*> list,
? filters.chatsList(id) bool foundSelf) {
: session->data().chatsList(nullptr);
const auto pinned = list->pinned()->order(); const auto pinned = list->pinned()->order();
auto peers = std::vector<not_null<PeerData*>>(); auto peers = std::vector<not_null<PeerData*>>();
peers.reserve(pinned.size()); peers.reserve(pinned.size());
auto foundSelf = !!id;
for (const auto &pin : pinned) { for (const auto &pin : pinned) {
if (!foundSelf && pin.peer()->isSelf()) { if (!foundSelf && pin.peer()->isSelf()) {
peers.insert(peers.begin(), pin.peer()); peers.insert(peers.begin(), pin.peer());
@ -2191,12 +2183,34 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
peers.insert(peers.begin(), session->user()); peers.insert(peers.begin(), session->user());
} }
return peers; return peers;
}(); };
const auto folder = session->data().folderLoaded(
Data::Folder::kId);
const auto pinned = pinnedList(
id
? filters.chatsList(id)
: session->data().chatsList(nullptr),
!!id);
const auto pinnedInFolder = (!id && folder)
? pinnedList(folder->chatsList(), true)
: std::vector<not_null<PeerData*>>();
box->peerListSortRows([&]( box->peerListSortRows([&](
const PeerListRow &r1, const PeerListRow &r1,
const PeerListRow &r2) { const PeerListRow &r2) {
const auto it1 = ranges::find(pinned, r1.peer()); { // Pinned to top.
const auto it2 = ranges::find(pinned, r2.peer()); auto it1 = pinned.end();
auto it2 = pinned.end();
for (auto it = pinned.begin(); it != pinned.end(); ++it) {
if ((*it) == r1.peer()) {
it1 = it;
}
if ((*it) == r2.peer()) {
it2 = it;
}
if (it1 != pinned.end() && it2 != pinned.end()) {
break;
}
}
if (it1 == pinned.end() && it2 != pinned.end()) { if (it1 == pinned.end() && it2 != pinned.end()) {
return false; return false;
} else if (it2 == pinned.end() && it1 != pinned.end()) { } else if (it2 == pinned.end() && it1 != pinned.end()) {
@ -2204,6 +2218,71 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
} else if (it1 != pinned.end() && it2 != pinned.end()) { } else if (it1 != pinned.end() && it2 != pinned.end()) {
return it1 < it2; return it1 < it2;
} }
}
{ // Pinned to bottom.
const auto &indexed = session->data().contactsNoChatsList();
auto it1 = indexed->end();
auto it2 = indexed->end();
for (auto it = indexed->begin(); it != indexed->end(); ++it) {
if (it->get()->key().peer() == r1.peer()) {
it1 = it;
}
if (it->get()->key().peer() == r2.peer()) {
it2 = it;
}
if (it1 != indexed->end() && it2 != indexed->end()) {
break;
}
}
if (it1 == indexed->end() && it2 != indexed->end()) {
return true;
} else if (it2 == indexed->end() && it1 != indexed->end()) {
return false;
} else if (it1 != indexed->end() && it2 != indexed->end()) {
return it1 > it2;
}
}
if (folder) {
const auto pinned1 = ranges::find(pinnedInFolder, r1.peer());
const auto pinned2 = ranges::find(pinnedInFolder, r2.peer());
const auto isPinned1 = pinned1 != pinnedInFolder.end();
const auto isPinned2 = pinned2 != pinnedInFolder.end();
if (isPinned1 && isPinned2) {
return pinned1 < pinned2;
}
const auto &indexed = folder->chatsList()->indexed();
auto it1 = indexed->end();
auto it2 = indexed->end();
for (auto it = indexed->begin(); it != indexed->end(); ++it) {
if (it->get()->key().peer() == r1.peer()) {
it1 = it;
}
if (it->get()->key().peer() == r2.peer()) {
it2 = it;
}
if (it1 != indexed->end() && it2 != indexed->end()) {
break;
}
}
const auto isFoldered1 = it1 != indexed->end();
const auto isFoldered2 = it2 != indexed->end();
if (isPinned1 && !isPinned2) {
return isFoldered2;
}
if (isPinned2 && !isPinned1) {
return !isFoldered1;
}
if (!isPinned1 && !isPinned2) {
if (!isFoldered1 && isFoldered2) {
return true;
} else if (!isFoldered2 && isFoldered1) {
return false;
} else if (isFoldered1 && isFoldered2) {
return it1 < it2;
}
}
}
const auto history1 = session->data().history(r1.peer()); const auto history1 = session->data().history(r1.peer());
const auto history2 = session->data().history(r2.peer()); const auto history2 = session->data().history(r2.peer());
const auto date1 = history1->lastMessage() const auto date1 = history1->lastMessage()
@ -2234,10 +2313,18 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
}); });
box->peerListRefreshRows(); box->peerListRefreshRows();
}; };
const auto state = [&] {
auto controller = std::make_unique<Controller>(session);
const auto controllerRaw = controller.get();
auto init = [=](not_null<PeerListBox*> box) {
controllerRaw->setSearchNoResultsText(
tr::lng_bot_chats_not_found(tr::now));
box->setSpecialTabMode(true);
const auto chatsFilters = Ui::AddChatFiltersTabsStrip( const auto chatsFilters = Ui::AddChatFiltersTabsStrip(
box, box,
session, session,
std::move(applyFilter)); [=](FilterId id) { applyFilter(box, id); });
chatsFilters->lower(); chatsFilters->lower();
chatsFilters->heightValue() | rpl::start_with_next([box](int h) { chatsFilters->heightValue() | rpl::start_with_next([box](int h) {
box->setAddedTopScrollSkip(h); box->setAddedTopScrollSkip(h);