Correctly move histories between chat lists.

This commit is contained in:
John Preston 2019-04-17 17:22:37 +04:00
parent 0367319934
commit c58f097535
14 changed files with 115 additions and 193 deletions

View File

@ -853,6 +853,7 @@ auto ApiWrap::dialogsLoadState(FolderId folderId) -> DialogsLoadState* {
void ApiWrap::dialogsLoadFinish(FolderId folderId) { void ApiWrap::dialogsLoadFinish(FolderId folderId) {
if (folderId) { if (folderId) {
_session->data().folder(folderId)->setChatsListLoaded(true);
_foldersLoadState.remove(folderId); _foldersLoadState.remove(folderId);
} else { } else {
_dialogsLoadState = nullptr; _dialogsLoadState = nullptr;

View File

@ -258,12 +258,12 @@ void ChatsListBoxController::rebuildRows() {
++added; ++added;
} }
} }
added += appendList(Auth().data().chatsList()); added += appendList(Auth().data().chatsList(Dialogs::Mode::All));
added += appendList(Auth().data().contactsNoChatsList()); added += appendList(Auth().data().contactsNoChatsList());
if (!wasEmpty && added > 0) { if (!wasEmpty && added > 0) {
// Place dialogs list before contactsNoDialogs list. // Place dialogs list before contactsNoDialogs list.
delegate()->peerListPartitionRows([](const PeerListRow &a) { delegate()->peerListPartitionRows([](const PeerListRow &a) {
auto history = static_cast<const Row&>(a).history(); const auto history = static_cast<const Row&>(a).history();
return history->inChatList(Dialogs::Mode::All); return history->inChatList(Dialogs::Mode::All);
}); });
if (respectSavedMessagesChat()) { if (respectSavedMessagesChat()) {

View File

@ -1079,7 +1079,8 @@ void AddSpecialBoxSearchController::addChatsContacts() {
} }
return result; return result;
}; };
const auto dialogsIndex = getSmallestIndex(_peer->owner().chatsList()); const auto dialogsIndex = getSmallestIndex(
_peer->owner().chatsList(Dialogs::Mode::All));
const auto contactsIndex = getSmallestIndex( const auto contactsIndex = getSmallestIndex(
_peer->owner().contactsNoChatsList()); _peer->owner().contactsNoChatsList());

View File

@ -489,7 +489,7 @@ ShareBox::Inner::Inner(
_rowHeight = st::shareRowHeight; _rowHeight = st::shareRowHeight;
setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_OpaquePaintEvent);
const auto dialogs = Auth().data().chatsList(); const auto dialogs = Auth().data().chatsList(Dialogs::Mode::All);
const auto self = Auth().user(); const auto self = Auth().user();
if (_filterCallback(self)) { if (_filterCallback(self)) {
_chatsIndexed->addToEnd(self->owner().history(self)); _chatsIndexed->addToEnd(self->owner().history(self));

View File

@ -41,6 +41,7 @@ Folder::Folder(not_null<Data::Session*> owner, FolderId id)
: Entry(owner, this) : Entry(owner, this)
, _id(id) , _id(id)
, _chatsList(Dialogs::SortMode::Date) , _chatsList(Dialogs::SortMode::Date)
, _importantChatsList(Dialogs::SortMode::Date)
, _name(lang(lng_archived_chats)) { , _name(lang(lng_archived_chats)) {
indexNameParts(); indexNameParts();
} }
@ -76,23 +77,9 @@ void Folder::indexNameParts() {
} }
void Folder::registerOne(not_null<History*> history) { void Folder::registerOne(not_null<History*> history) {
if (_chatsList.contains(history)) {
return;
}
const auto invisible = _chatsList.empty();
_chatsList.addToEnd(history);
//session().storage().invalidate( // #feed //session().storage().invalidate( // #feed
// Storage::FeedMessagesInvalidate(_id)); // Storage::FeedMessagesInvalidate(_id));
if (history->chatListMessageKnown()) {
if (const auto last = history->chatListMessage()) {
if (justUpdateChatListMessage(last)) {
updateChatListEntry();
}
}
} else if (chatListMessageKnown()) {
history->requestChatListMessage();
}
if (unreadCountKnown()) { if (unreadCountKnown()) {
if (history->unreadCountKnown()) { if (history->unreadCountKnown()) {
// If history unreadCount is known that means that we've // If history unreadCount is known that means that we've
@ -102,36 +89,20 @@ void Folder::registerOne(not_null<History*> history) {
if (const auto count = history->unreadCount()) { if (const auto count = history->unreadCount()) {
unreadCountChanged(count, history->mute() ? count : 0); unreadCountChanged(count, history->mute() ? count : 0);
} }
} else if (!_settingHistories) { } else {
session().api().requestDialogEntry(this); session().api().requestDialogEntry(this);
} }
} }
if (invisible && !_chatsList.empty()) { if (_chatsList.size() == 1) {
updateChatListExistence(); updateChatListExistence();
//for (const auto history : _histories) { // #TODO archived
// history->updateChatListExistence();
//}
} else {
history->updateChatListExistence();
} }
owner().notifyFolderUpdated(this, FolderUpdateFlag::List); owner().notifyFolderUpdated(this, FolderUpdateFlag::List);
} }
void Folder::unregisterOne(not_null<History*> history) { void Folder::unregisterOne(not_null<History*> history) {
if (!_chatsList.contains(history)) {
return;
}
_chatsList.del(history);
//session().storage().remove( // #feed //session().storage().remove( // #feed
// Storage::FeedMessagesRemoveAll(_id, channel->bareId())); // Storage::FeedMessagesRemoveAll(_id, channel->bareId()));
if (chatListMessageKnown()) {
if (const auto last = chatListMessage()) {
if (last->history() == history) {
recountChatListMessage();
}
}
}
if (unreadCountKnown()) { if (unreadCountKnown()) {
if (history->unreadCountKnown()) { if (history->unreadCountKnown()) {
if (const auto delta = -history->unreadCount()) { if (const auto delta = -history->unreadCount()) {
@ -143,25 +114,14 @@ void Folder::unregisterOne(not_null<History*> history) {
} }
if (_chatsList.empty()) { if (_chatsList.empty()) {
updateChatListExistence(); updateChatListExistence();
//for (const auto history : _histories) { // #TODO archive
// history->updateChatListExistence();
//}
} else {
history->updateChatListExistence();
} }
owner().notifyFolderUpdated(this, FolderUpdateFlag::List); owner().notifyFolderUpdated(this, FolderUpdateFlag::List);
} }
not_null<Dialogs::IndexedList*> Folder::chatsList() { not_null<Dialogs::IndexedList*> Folder::chatsList(Dialogs::Mode list) {
return &_chatsList; return (list == Dialogs::Mode::All)
} ? &_chatsList
: &_importantChatsList;
void Folder::updateChatListMessage(not_null<HistoryItem*> item) {
if (justUpdateChatListMessage(item)) {
if (_chatListMessage && *_chatListMessage) {
setChatListTimeId((*_chatListMessage)->date());
}
}
} }
void Folder::loadUserpic() { void Folder::loadUserpic() {
@ -201,13 +161,13 @@ void Folder::paintUserpic(
//} //}
} }
bool Folder::historiesLoaded() const { bool Folder::chatsListLoaded() const {
return _historiesLoaded; return _chatsListLoaded;
} }
void Folder::setHistoriesLoaded(bool loaded) { void Folder::setChatsListLoaded(bool loaded) {
if (_historiesLoaded != loaded) { if (_chatsListLoaded != loaded) {
_historiesLoaded = loaded; _chatsListLoaded = loaded;
owner().notifyFolderUpdated(this, FolderUpdateFlag::List); owner().notifyFolderUpdated(this, FolderUpdateFlag::List);
} }
} }
@ -268,66 +228,12 @@ void Folder::setHistoriesLoaded(bool loaded) {
// _chatListMessage = oldChatListMessage; // _chatListMessage = oldChatListMessage;
//} //}
bool Folder::justUpdateChatListMessage(not_null<HistoryItem*> item) {
if (!_chatListMessage) {
return false;
} else if (*_chatListMessage
&& item->position() <= (*_chatListMessage)->position()) {
return false;
}
_chatListMessage = item;
return true;
}
void Folder::messageRemoved(not_null<HistoryItem*> item) {
if (chatListMessage() == item) {
recountChatListMessage();
}
}
void Folder::historyCleared(not_null<History*> history) {
if (const auto last = chatListMessage()) {
if (last->history() == history) {
messageRemoved(last);
}
}
}
void Folder::requestChatListMessage() { void Folder::requestChatListMessage() {
if (!chatListMessageKnown()) { if (!chatListMessageKnown()) {
session().api().requestDialogEntry(this); session().api().requestDialogEntry(this);
} }
} }
void Folder::recountChatListMessage() {
_chatListMessage = std::nullopt;
for (const auto entry : _chatsList) {
if (entry->history() && !entry->history()->chatListMessageKnown()) {
requestChatListMessage();
return;
}
}
setChatListMessageFromChannels();
}
void Folder::setChatListMessageFromChannels() {
_chatListMessage = nullptr;
for (const auto entry : _chatsList) {
if (entry->history()) {
if (const auto last = entry->history()->chatListMessage()) {
justUpdateChatListMessage(last);
}
}
}
updateChatListDate();
}
void Folder::updateChatListDate() {
if (_chatListMessage && *_chatListMessage) {
setChatListTimeId((*_chatListMessage)->date());
}
}
int Folder::unreadCount() const { int Folder::unreadCount() const {
return _unreadCount ? *_unreadCount : 0; return _unreadCount ? *_unreadCount : 0;
} }
@ -352,17 +258,17 @@ void Folder::applyDialog(const MTPDdialogFolder &data) {
// addChannel(channelId.v); // addChannel(channelId.v);
//} //}
_chatListMessage = nullptr;
if (const auto peerId = peerFromMTP(data.vpeer)) { if (const auto peerId = peerFromMTP(data.vpeer)) {
owner().history(peerId)->setFolder(this); const auto history = owner().history(peerId);
const auto fullId = FullMsgId( const auto fullId = FullMsgId(
peerToChannel(peerId), peerToChannel(peerId),
data.vtop_message.v); data.vtop_message.v);
if (const auto item = App::histItemById(fullId)) { history->setFolder(this, App::histItemById(fullId));
justUpdateChatListMessage(item); } else {
} _chatsList.clear();
_importantChatsList.clear();
updateChatListExistence();
} }
updateChatListDate();
setUnreadCounts( setUnreadCounts(
data.vunread_unmuted_messages_count.v, data.vunread_unmuted_messages_count.v,
data.vunread_muted_messages_count.v); data.vunread_muted_messages_count.v);
@ -511,7 +417,7 @@ void Folder::unreadCountChanged(int unreadCountDelta, int mutedCountDelta) {
//} //}
bool Folder::toImportant() const { bool Folder::toImportant() const {
return false; // TODO feeds workmode return !_importantChatsList.empty();
} }
bool Folder::useProxyPromotion() const { bool Folder::useProxyPromotion() const {
@ -535,11 +441,14 @@ bool Folder::chatListMutedBadge() const {
} }
HistoryItem *Folder::chatListMessage() const { HistoryItem *Folder::chatListMessage() const {
return _chatListMessage ? *_chatListMessage : nullptr; return _chatsList.empty()
? nullptr
: (*_chatsList.begin())->key().entry()->chatListMessage();
} }
bool Folder::chatListMessageKnown() const { bool Folder::chatListMessageKnown() const {
return _chatListMessage.has_value(); return _chatsList.empty()
|| (*_chatsList.begin())->key().entry()->chatListMessageKnown();
} }
const QString &Folder::chatListName() const { const QString &Folder::chatListName() const {

View File

@ -42,11 +42,7 @@ public:
void registerOne(not_null<History*> history); void registerOne(not_null<History*> history);
void unregisterOne(not_null<History*> history); void unregisterOne(not_null<History*> history);
not_null<Dialogs::IndexedList*> chatsList(); not_null<Dialogs::IndexedList*> chatsList(Dialogs::Mode list);
void updateChatListMessage(not_null<HistoryItem*> item);
void messageRemoved(not_null<HistoryItem*> item);
void historyCleared(not_null<History*> history);
void applyDialog(const MTPDdialogFolder &data); void applyDialog(const MTPDdialogFolder &data);
void setUnreadCounts(int unreadNonMutedCount, int unreadMutedCount); void setUnreadCounts(int unreadNonMutedCount, int unreadMutedCount);
@ -86,17 +82,13 @@ public:
int y, int y,
int size) const override; int size) const override;
bool historiesLoaded() const; bool chatsListLoaded() const;
void setHistoriesLoaded(bool loaded); void setChatsListLoaded(bool loaded);
//int32 chatsHash() const; //int32 chatsHash() const;
//void setChats(std::vector<not_null<PeerData*>> chats); // #feed //void setChats(std::vector<not_null<PeerData*>> chats); // #feed
private: private:
void indexNameParts(); void indexNameParts();
void recountChatListMessage();
void setChatListMessageFromChannels();
bool justUpdateChatListMessage(not_null<HistoryItem*> item);
void updateChatListDate();
//void changeChatsList( //void changeChatsList(
// const std::vector<not_null<PeerData*>> &add, // const std::vector<not_null<PeerData*>> &add,
// const std::vector<not_null<PeerData*>> &remove); // const std::vector<not_null<PeerData*>> &remove);
@ -106,15 +98,14 @@ private:
FolderId _id = 0; FolderId _id = 0;
Dialogs::IndexedList _chatsList; Dialogs::IndexedList _chatsList;
bool _settingHistories = false; Dialogs::IndexedList _importantChatsList;
bool _historiesLoaded = false; bool _chatsListLoaded = false;
QString _name; QString _name;
base::flat_set<QString> _nameWords; base::flat_set<QString> _nameWords;
base::flat_set<QChar> _nameFirstLetters; base::flat_set<QChar> _nameFirstLetters;
std::optional<HistoryItem*> _chatListMessage;
rpl::variable<MessagePosition> _unreadPosition; //rpl::variable<MessagePosition> _unreadPosition;
std::optional<int> _unreadCount; std::optional<int> _unreadCount;
rpl::event_stream<int> _unreadCountChanges; rpl::event_stream<int> _unreadCountChanges;
int _unreadMutedCount = 0; int _unreadMutedCount = 0;

View File

@ -2949,12 +2949,10 @@ not_null<Folder*> Session::processFolder(const MTPDfolder &data) {
// return _defaultFeedId.value(); // return _defaultFeedId.value();
//} //}
not_null<Dialogs::IndexedList*> Session::chatsList() { not_null<Dialogs::IndexedList*> Session::chatsList(Dialogs::Mode list) {
return &_chatsList; return (list == Dialogs::Mode::All)
} ? &_chatsList
: &_importantChatsList;
not_null<Dialogs::IndexedList*> Session::importantChatsList() {
return &_importantChatsList;
} }
not_null<Dialogs::IndexedList*> Session::contactsList() { not_null<Dialogs::IndexedList*> Session::contactsList() {
@ -2973,25 +2971,22 @@ auto Session::refreshChatListEntry(Dialogs::Key key)
auto result = RefreshChatListEntryResult(); auto result = RefreshChatListEntryResult();
result.changed = !entry->inChatList(Mode::All); result.changed = !entry->inChatList(Mode::All);
if (result.changed) { if (result.changed) {
const auto mainRow = entry->addToChatList(Mode::All, &_chatsList); const auto mainRow = entry->addToChatList(Mode::All);
_contactsNoChatsList.del(key, mainRow); _contactsNoChatsList.del(key, mainRow);
} else { } else {
result.moved = entry->adjustByPosInChatList( result.moved = entry->adjustByPosInChatList(Mode::All);
Mode::All,
&_chatsList);
} }
if (Global::DialogsModeEnabled()) { if (Global::DialogsModeEnabled()) {
if (entry->toImportant()) { if (entry->toImportant()) {
result.importantChanged = !entry->inChatList(Mode::Important); result.importantChanged = !entry->inChatList(Mode::Important);
if (result.importantChanged) { if (result.importantChanged) {
entry->addToChatList(Mode::Important, &_importantChatsList); entry->addToChatList(Mode::Important);
} else { } else {
result.importantMoved = entry->adjustByPosInChatList( result.importantMoved = entry->adjustByPosInChatList(
Mode::Important, Mode::Important);
&_importantChatsList);
} }
} else if (entry->inChatList(Mode::Important)) { } else if (entry->inChatList(Mode::Important)) {
entry->removeFromChatList(Mode::Important, &_importantChatsList); entry->removeFromChatList(Mode::Important);
result.importantChanged = true; result.importantChanged = true;
} }
} }
@ -3002,9 +2997,9 @@ void Session::removeChatListEntry(Dialogs::Key key) {
using namespace Dialogs; using namespace Dialogs;
const auto entry = key.entry(); const auto entry = key.entry();
entry->removeFromChatList(Mode::All, &_chatsList); entry->removeFromChatList(Mode::All);
if (Global::DialogsModeEnabled()) { if (Global::DialogsModeEnabled()) {
entry->removeFromChatList(Mode::Important, &_importantChatsList); entry->removeFromChatList(Mode::Important);
} }
if (_contactsList.contains(key)) { if (_contactsList.contains(key)) {
if (!_contactsNoChatsList.contains(key)) { if (!_contactsNoChatsList.contains(key)) {

View File

@ -516,8 +516,7 @@ public:
//FeedId defaultFeedId() const; //FeedId defaultFeedId() const;
//rpl::producer<FeedId> defaultFeedIdValue() const; //rpl::producer<FeedId> defaultFeedIdValue() const;
not_null<Dialogs::IndexedList*> chatsList(); not_null<Dialogs::IndexedList*> chatsList(Dialogs::Mode list);
not_null<Dialogs::IndexedList*> importantChatsList();
not_null<Dialogs::IndexedList*> contactsList(); not_null<Dialogs::IndexedList*> contactsList();
not_null<Dialogs::IndexedList*> contactsNoChatsList(); not_null<Dialogs::IndexedList*> contactsNoChatsList();

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/dialogs_key.h" #include "dialogs/dialogs_key.h"
#include "dialogs/dialogs_indexed_list.h" #include "dialogs/dialogs_indexed_list.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_folder.h"
#include "mainwidget.h" #include "mainwidget.h"
#include "auth_session.h" #include "auth_session.h"
#include "history/history_item.h" #include "history/history_item.h"
@ -135,12 +136,10 @@ Row *Entry::mainChatListLink(Mode list) const {
return it->second; return it->second;
} }
PositionChange Entry::adjustByPosInChatList( PositionChange Entry::adjustByPosInChatList(Mode list) {
Mode list,
not_null<IndexedList*> indexed) {
const auto lnk = mainChatListLink(list); const auto lnk = mainChatListLink(list);
const auto from = lnk->pos(); const auto from = lnk->pos();
indexed->adjustByDate(chatListLinks(list)); myChatsList(list)->adjustByDate(chatListLinks(list));
const auto to = lnk->pos(); const auto to = lnk->pos();
return { from, to }; return { from, to };
} }
@ -159,21 +158,17 @@ int Entry::posInChatList(Dialogs::Mode list) const {
return mainChatListLink(list)->pos(); return mainChatListLink(list)->pos();
} }
not_null<Row*> Entry::addToChatList( not_null<Row*> Entry::addToChatList(Mode list) {
Mode list,
not_null<IndexedList*> indexed) {
if (!inChatList(list)) { if (!inChatList(list)) {
chatListLinks(list) = indexed->addToEnd(_key); chatListLinks(list) = myChatsList(list)->addToEnd(_key);
changedInChatListHook(list, true); changedInChatListHook(list, true);
} }
return mainChatListLink(list); return mainChatListLink(list);
} }
void Entry::removeFromChatList( void Entry::removeFromChatList(Dialogs::Mode list) {
Dialogs::Mode list,
not_null<Dialogs::IndexedList*> indexed) {
if (inChatList(list)) { if (inChatList(list)) {
indexed->del(_key); myChatsList(list)->del(_key);
chatListLinks(list).clear(); chatListLinks(list).clear();
changedInChatListHook(list, false); changedInChatListHook(list, false);
} }
@ -217,4 +212,11 @@ void Entry::updateChatListEntry() const {
} }
} }
not_null<IndexedList*> Entry::myChatsList(Mode list) const {
if (const auto current = folder()) {
return current->chatsList(list);
}
return owner().chatsList(list);
}
} // namespace Dialogs } // namespace Dialogs

View File

@ -15,6 +15,7 @@ class AuthSession;
namespace Data { namespace Data {
class Session; class Session;
class Folder;
} // namespace Data } // namespace Data
namespace Dialogs { namespace Dialogs {
@ -49,15 +50,13 @@ public:
Data::Session &owner() const; Data::Session &owner() const;
AuthSession &session() const; AuthSession &session() const;
PositionChange adjustByPosInChatList( PositionChange adjustByPosInChatList(Mode list);
Mode list,
not_null<IndexedList*> indexed);
bool inChatList(Mode list) const { bool inChatList(Mode list) const {
return !chatListLinks(list).empty(); return !chatListLinks(list).empty();
} }
int posInChatList(Mode list) const; int posInChatList(Mode list) const;
not_null<Row*> addToChatList(Mode list, not_null<IndexedList*> indexed); not_null<Row*> addToChatList(Mode list);
void removeFromChatList(Mode list, not_null<IndexedList*> indexed); void removeFromChatList(Mode list);
void removeChatListEntryByLetter(Mode list, QChar letter); void removeChatListEntryByLetter(Mode list, QChar letter);
void addChatListEntryByLetter( void addChatListEntryByLetter(
Mode list, Mode list,
@ -93,6 +92,10 @@ public:
virtual const base::flat_set<QString> &chatListNameWords() const = 0; virtual const base::flat_set<QString> &chatListNameWords() const = 0;
virtual const base::flat_set<QChar> &chatListFirstLetters() const = 0; virtual const base::flat_set<QChar> &chatListFirstLetters() const = 0;
virtual Data::Folder *folder() const {
return nullptr;
}
virtual void loadUserpic() = 0; virtual void loadUserpic() = 0;
virtual void paintUserpic( virtual void paintUserpic(
Painter &p, Painter &p,
@ -117,7 +120,7 @@ public:
private: private:
virtual TimeId adjustChatListTimeId() const; virtual TimeId adjustChatListTimeId() const;
virtual void changedInChatListHook(Dialogs::Mode list, bool added); virtual void changedInChatListHook(Mode list, bool added);
virtual void changedChatListPinHook(); virtual void changedChatListPinHook();
void setChatListExistence(bool exists); void setChatListExistence(bool exists);
@ -125,6 +128,8 @@ private:
const RowsByLetter &chatListLinks(Mode list) const; const RowsByLetter &chatListLinks(Mode list) const;
Row *mainChatListLink(Mode list) const; Row *mainChatListLink(Mode list) const;
not_null<IndexedList*> myChatsList(Mode list) const;
not_null<Data::Session*> _owner; not_null<Data::Session*> _owner;
Dialogs::Key _key; Dialogs::Key _key;
RowsByLetter _chatListLinks[2]; RowsByLetter _chatListLinks[2];

View File

@ -249,11 +249,11 @@ int DialogsInner::searchInChatSkip() const {
} }
bool DialogsInner::cancelFolder() { bool DialogsInner::cancelFolder() {
if (!_folderChatsList) { if (!_openedFolder) {
return false; return false;
} }
clearSelection(); clearSelection();
_folderChatsList = nullptr; _openedFolder = nullptr;
refresh(); refresh();
return true; return true;
} }
@ -1471,11 +1471,9 @@ void DialogsInner::updateSelectedRow(Dialogs::Key key) {
} }
not_null<Dialogs::IndexedList*> DialogsInner::shownDialogs() const { not_null<Dialogs::IndexedList*> DialogsInner::shownDialogs() const {
return _folderChatsList return _openedFolder
? _folderChatsList ? _openedFolder->chatsList(Global::DialogsMode())
: (Global::DialogsMode() == Dialogs::Mode::Important) : session().data().chatsList(Global::DialogsMode());
? session().data().importantChatsList().get()
: session().data().chatsList().get();
} }
void DialogsInner::leaveEventHook(QEvent *e) { void DialogsInner::leaveEventHook(QEvent *e) {
@ -1609,7 +1607,7 @@ void DialogsInner::applyFilterUpdate(QString newFilter, bool force) {
_filterResultsGlobal.clear(); _filterResultsGlobal.clear();
if (!_searchInChat && !words.isEmpty()) { if (!_searchInChat && !words.isEmpty()) {
const Dialogs::List *toFilter = nullptr; const Dialogs::List *toFilter = nullptr;
if (const auto list = session().data().chatsList(); !list->empty()) { if (const auto list = session().data().chatsList(Dialogs::Mode::All); !list->empty()) {
for (fi = fb; fi != fe; ++fi) { for (fi = fb; fi != fe; ++fi) {
const auto found = list->filtered(fi->at(0)); const auto found = list->filtered(fi->at(0));
if (!found || found->empty()) { if (!found || found->empty()) {
@ -2409,7 +2407,7 @@ bool DialogsInner::chooseRow() {
: chosen.message.fullId.msg)); : chosen.message.fullId.msg));
} else if (const auto folder = chosen.key.folder()) { } else if (const auto folder = chosen.key.folder()) {
clearSelection(); clearSelection();
_folderChatsList = folder->chatsList(); _openedFolder = folder;
refresh(); refresh();
} }
if (openSearchResult && !session().supportMode()) { if (openSearchResult && !session().supportMode()) {

View File

@ -282,7 +282,7 @@ private:
std::optional<QPoint> _lastMousePosition; std::optional<QPoint> _lastMousePosition;
Qt::MouseButton _pressButton = Qt::LeftButton; Qt::MouseButton _pressButton = Qt::LeftButton;
Dialogs::IndexedList *_folderChatsList = nullptr; Data::Folder *_openedFolder = nullptr;
std::unique_ptr<ImportantSwitch> _importantSwitch; std::unique_ptr<ImportantSwitch> _importantSwitch;
bool _importantSwitchSelected = false; bool _importantSwitchSelected = false;
bool _importantSwitchPressed = false; bool _importantSwitchPressed = false;

View File

@ -1810,8 +1810,13 @@ Data::Folder *History::folder() const {
return _folder; return _folder;
} }
void History::setFolder(not_null<Data::Folder*> folder) { void History::setFolder(
not_null<Data::Folder*> folder,
HistoryItem *folderDialogItem) {
setFolderPointer(folder); setFolderPointer(folder);
if (folderDialogItem && _lastMessage != folderDialogItem) {
setLastMessage(folderDialogItem);
}
} }
void History::clearFolder() { void History::clearFolder() {
@ -1819,16 +1824,30 @@ void History::clearFolder() {
} }
void History::setFolderPointer(Data::Folder *folder) { void History::setFolderPointer(Data::Folder *folder) {
if (_folder != folder) { if (_folder == folder) {
const auto was = _folder; return;
_folder = folder; }
if (was) { using Mode = Dialogs::Mode;
was->unregisterOne(this); const auto wasAll = inChatList(Mode::All);
} const auto wasImportant = inChatList(Mode::Important);
if (_folder) { if (wasAll) {
_folder->registerOne(this); removeFromChatList(Mode::All);
} }
updateChatListSortPosition(); if (wasImportant) {
removeFromChatList(Mode::Important);
}
const auto was = std::exchange(_folder, folder);
if (was) {
was->unregisterOne(this);
}
if (wasAll) {
addToChatList(Mode::All);
}
if (wasImportant) {
addToChatList(Mode::Important);
}
if (_folder) {
_folder->registerOne(this);
} }
} }

View File

@ -323,8 +323,10 @@ public:
std::shared_ptr<AdminLog::LocalIdManager> adminLogIdManager(); std::shared_ptr<AdminLog::LocalIdManager> adminLogIdManager();
Data::Folder *folder() const; Data::Folder *folder() const override;
void setFolder(not_null<Data::Folder*> folder); void setFolder(
not_null<Data::Folder*> folder,
HistoryItem *folderDialogItem = nullptr);
void clearFolder(); void clearFolder();
// Still public data. // Still public data.