From 4527c03c0d742ee646233e8c23e60b6e8b13f17f Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 22 Jan 2018 12:33:09 +0300 Subject: [PATCH] Use "Feed" name for chats list index and search. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/boxes/peer_list_box.cpp | 12 ++--- Telegram/SourceFiles/boxes/peer_list_box.h | 10 ++--- .../boxes/peer_list_controllers.cpp | 21 ++++----- Telegram/SourceFiles/boxes/share_box.cpp | 44 +++++++++---------- Telegram/SourceFiles/boxes/share_box.h | 6 +-- .../chat_helpers/field_autocomplete.cpp | 4 +- Telegram/SourceFiles/data/data_feed.cpp | 31 ++++++++++++- Telegram/SourceFiles/data/data_feed.h | 14 ++++++ Telegram/SourceFiles/data/data_peer.cpp | 10 ++--- Telegram/SourceFiles/data/data_peer.h | 12 +++-- Telegram/SourceFiles/dialogs/dialogs_entry.h | 3 ++ .../dialogs/dialogs_indexed_list.cpp | 32 +++++++------- .../dialogs/dialogs_indexed_list.h | 8 ++-- .../dialogs/dialogs_inner_widget.cpp | 29 ++++++------ .../dialogs/dialogs_inner_widget.h | 2 +- Telegram/SourceFiles/dialogs/dialogs_key.cpp | 20 +-------- Telegram/SourceFiles/dialogs/dialogs_key.h | 3 -- .../SourceFiles/dialogs/dialogs_layout.cpp | 3 +- Telegram/SourceFiles/dialogs/dialogs_list.cpp | 16 ++++--- Telegram/SourceFiles/dialogs/dialogs_row.h | 3 -- Telegram/SourceFiles/history/history.cpp | 12 +++++ Telegram/SourceFiles/history/history.h | 3 ++ Telegram/SourceFiles/observer_peer.cpp | 2 +- Telegram/SourceFiles/observer_peer.h | 2 +- .../profile/profile_channel_controllers.cpp | 11 ++--- 26 files changed, 178 insertions(+), 136 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 2e0b1890b..c04012cf2 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1415,6 +1415,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_admin_log_admin_pin_messages" = "Pin messages"; "lng_admin_log_admin_add_admins" = "Add new admins"; +"lng_feed_name" = "Feed"; "lng_feed_show_next" = "Show Next"; // Wnd specific diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 1621fa5f8..eb2240408 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -629,16 +629,16 @@ void PeerListContent::addToSearchIndex(not_null row) { } removeFromSearchIndex(row); - row->setNameFirstChars(row->peer()->nameFirstChars()); - for (auto ch : row->nameFirstChars()) { + row->setNameFirstLetters(row->peer()->nameFirstLetters()); + for (auto ch : row->nameFirstLetters()) { _searchIndex[ch].push_back(row); } } void PeerListContent::removeFromSearchIndex(not_null row) { - auto &nameFirstChars = row->nameFirstChars(); - if (!nameFirstChars.empty()) { - for (auto ch : row->nameFirstChars()) { + const auto &nameFirstLetters = row->nameFirstLetters(); + if (!nameFirstLetters.empty()) { + for (auto ch : row->nameFirstLetters()) { auto it = _searchIndex.find(ch); if (it != _searchIndex.cend()) { auto &entry = it->second; @@ -648,7 +648,7 @@ void PeerListContent::removeFromSearchIndex(not_null row) { } } } - row->setNameFirstChars({}); + row->setNameFirstLetters({}); } } diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index fd10d1da9..19a3ee7c9 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -177,11 +177,11 @@ public: int outerWidth); float64 checkedRatio(); - void setNameFirstChars(const base::flat_set &nameFirstChars) { - _nameFirstChars = nameFirstChars; + void setNameFirstLetters(const base::flat_set &firstLetters) { + _nameFirstLetters = firstLetters; } - const base::flat_set &nameFirstChars() const { - return _nameFirstChars; + const base::flat_set &nameFirstLetters() const { + return _nameFirstLetters; } virtual void lazyInitialize(const style::PeerListItem &st); @@ -218,7 +218,7 @@ private: Text _status; StatusType _statusType = StatusType::Online; TimeMs _statusValidTill = 0; - base::flat_set _nameFirstChars; + base::flat_set _nameFirstLetters; int _absoluteIndex = -1; State _disabledState = State::Active; bool _initialized : 1; diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp index 31bf0afa5..65da683df 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp @@ -243,10 +243,11 @@ void ChatsListBoxController::rebuildRows() { auto wasEmpty = !delegate()->peerListFullRowsCount(); auto appendList = [this](auto chats) { auto count = 0; - for_const (auto row, chats->all()) { - // #TODO feeds list - if (appendRow(row->history())) { - ++count; + for (const auto row : chats->all()) { + if (const auto history = row->history()) { + if (appendRow(history)) { + ++count; + } } } return count; @@ -328,12 +329,12 @@ void ContactsBoxController::prepare() { void ContactsBoxController::rebuildRows() { auto appendList = [this](auto chats) { auto count = 0; - for_const (auto row, chats->all()) { - // #TODO feeds list - auto history = row->history(); - if (auto user = history->peer->asUser()) { - if (appendRow(user)) { - ++count; + for (const auto row : chats->all()) { + if (const auto history = row->history()) { + if (const auto user = history->peer->asUser()) { + if (appendRow(user)) { + ++count; + } } } } diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index ae65c87ce..0dc36e3d3 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -281,9 +281,9 @@ ShareBox::Inner::Inner(QWidget *parent, ShareBox::FilterCallback &&filterCallbac } } for (const auto row : dialogs->all()) { - // #TODO feeds list if (const auto history = row->history()) { - if (!history->peer->isSelf() && _filterCallback(history->peer)) { + if (!history->peer->isSelf() + && _filterCallback(history->peer)) { _chatsIndexed->addToEnd(history); } } @@ -352,7 +352,7 @@ void ShareBox::Inner::notifyPeerUpdated(const Notify::PeerUpdate &update) { if (update.flags & Notify::PeerUpdate::Flag::NameChanged) { _chatsIndexed->peerNameChanged( update.peer, - update.oldNameFirstChars); + update.oldNameFirstLetters); } updateChat(update.peer); @@ -407,22 +407,24 @@ void ShareBox::Inner::repaintChat(not_null peer) { int ShareBox::Inner::chatIndex(not_null peer) const { int index = 0; if (_filter.isEmpty()) { - for_const (auto row, _chatsIndexed->all()) { - // #TODO feeds list - if (row->history()->peer == peer) { - return index; + for (const auto row : _chatsIndexed->all()) { + if (const auto history = row->history()) { + if (history->peer == peer) { + return index; + } } ++index; } } else { - for_const (auto row, _filtered) { - // #TODO feeds list - if (row->history()->peer == peer) { - return index; + for (const auto row : _filtered) { + if (const auto history = row->history()) { + if (history->peer == peer) { + return index; + } } ++index; } - for_const (auto row, d_byUsernameFiltered) { + for (const auto row : d_byUsernameFiltered) { if (row->peer == peer) { return index; } @@ -455,8 +457,7 @@ void ShareBox::Inner::loadProfilePhotos(int yFrom) { if (((*i)->pos() * _rowHeight) >= yTo) { break; } - // #TODO feeds list - (*i)->history()->peer->loadUserpic(); + (*i)->entry()->loadUserpic(); } } } else if (!_filtered.isEmpty()) { @@ -467,17 +468,17 @@ void ShareBox::Inner::loadProfilePhotos(int yFrom) { if (to > _filtered.size()) to = _filtered.size(); for (; from < to; ++from) { - // #TODO feeds list - _filtered[from]->history()->peer->loadUserpic(); + _filtered[from]->entry()->loadUserpic(); } } } } ShareBox::Inner::Chat *ShareBox::Inner::getChat(Dialogs::Row *row) { + Expects(row->history() != nullptr); + auto data = static_cast(row->attached); if (!data) { - // #TODO feeds list auto peer = row->history()->peer; auto i = _dataMap.constFind(peer); if (i == _dataMap.cend()) { @@ -565,7 +566,7 @@ void ShareBox::Inner::paintEvent(QPaintEvent *e) { p.setPen(st::noContactsColor); } } else { - if (_filtered.isEmpty() && _byUsernameFiltered.isEmpty()) { + if (_filtered.isEmpty() && _byUsernameFiltered.empty()) { // empty p.setFont(st::noContactsFont); p.setPen(st::noContactsColor); @@ -583,7 +584,7 @@ void ShareBox::Inner::paintEvent(QPaintEvent *e) { indexFrom -= filteredSize; indexTo -= filteredSize; } - if (!_byUsernameFiltered.isEmpty()) { + if (!_byUsernameFiltered.empty()) { if (indexFrom < 0) indexFrom = 0; while (indexFrom < indexTo) { if (indexFrom >= d_byUsernameFiltered.size()) { @@ -732,9 +733,8 @@ void ShareBox::Inner::updateFilter(QString filter) { } if (toFilter) { _filtered.reserve(toFilter->size()); - for_const (auto row, *toFilter) { - // #TODO feeds list - auto &nameWords = row->history()->peer->nameWords(); + for (const auto row : *toFilter) { + auto &nameWords = row->entry()->chatsListNameWords(); auto nb = nameWords.cbegin(), ne = nameWords.cend(), ni = nb; for (fi = fb; fi != fe; ++fi) { auto filterName = *fi; diff --git a/Telegram/SourceFiles/boxes/share_box.h b/Telegram/SourceFiles/boxes/share_box.h index b082980e2..1cd7e7756 100644 --- a/Telegram/SourceFiles/boxes/share_box.h +++ b/Telegram/SourceFiles/boxes/share_box.h @@ -202,9 +202,7 @@ private: bool _searching = false; QString _lastQuery; - using ByUsernameRows = QVector; - using ByUsernameDatas = QVector; - ByUsernameRows _byUsernameFiltered; - ByUsernameDatas d_byUsernameFiltered; + std::vector _byUsernameFiltered; + std::vector d_byUsernameFiltered; }; diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 73ad49271..9192defbb 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -159,8 +159,8 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) { } return true; }; - auto filterNotPassedByName = [this, &filterNotPassedByUsername](UserData *user) -> bool { - for (auto &nameWord : user->nameWords()) { + auto filterNotPassedByName = [&](UserData *user) -> bool { + for (const auto &nameWord : user->nameWords()) { if (nameWord.startsWith(_filter, Qt::CaseInsensitive)) { auto exactUsername = (user->username.compare(_filter, Qt::CaseInsensitive) == 0); return exactUsername; diff --git a/Telegram/SourceFiles/data/data_feed.cpp b/Telegram/SourceFiles/data/data_feed.cpp index a676c7b4d..badfe2380 100644 --- a/Telegram/SourceFiles/data/data_feed.cpp +++ b/Telegram/SourceFiles/data/data_feed.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "dialogs/dialogs_key.h" #include "history/history.h" #include "history/history_item.h" +#include "lang/lang_keys.h" namespace Data { @@ -24,7 +25,35 @@ MessagePosition FeedPositionFromMTP(const MTPFeedPosition &position) { Feed::Feed(FeedId id) : Entry(this) -, _id(id) { +, _id(id) +, _name(lang(lng_feed_name)) { + indexNameParts(); +} + +void Feed::indexNameParts() { + _nameWords.clear(); + _nameFirstLetters.clear(); + auto toIndexList = QStringList(); + auto appendToIndex = [&](const QString &value) { + if (!value.isEmpty()) { + toIndexList.push_back(TextUtilities::RemoveAccents(value)); + } + }; + + appendToIndex(_name); + const auto appendTranslit = !toIndexList.isEmpty() + && cRussianLetters().match(toIndexList.front()).hasMatch(); + if (appendTranslit) { + appendToIndex(translitRusEng(toIndexList.front())); + } + auto toIndex = toIndexList.join(' '); + toIndex += ' ' + rusKeyboardLayoutSwitch(toIndex); + + const auto namesList = TextUtilities::PrepareSearchWords(toIndex); + for (const auto &name : namesList) { + _nameWords.insert(name); + _nameFirstLetters.insert(name[0]); + } } void Feed::registerOne(not_null channel) { diff --git a/Telegram/SourceFiles/data/data_feed.h b/Telegram/SourceFiles/data/data_feed.h index ce171403b..f9145bc8f 100644 --- a/Telegram/SourceFiles/data/data_feed.h +++ b/Telegram/SourceFiles/data/data_feed.h @@ -53,6 +53,16 @@ public: HistoryItem *chatsListItem() const override { return _lastMessage; } + const QString &chatsListName() const override { + return _name; + } + const base::flat_set &chatsListNameWords() const override { + return _nameWords; + } + const base::flat_set &chatsListFirstLetters() const override { + return _nameFirstLetters; + } + void loadUserpic() override; void paintUserpic( Painter &p, @@ -61,12 +71,16 @@ public: int size) const override; private: + void indexNameParts(); void recountLastMessage(); bool justSetLastMessage(not_null item); FeedId _id = 0; std::vector> _channels; + QString _name; + base::flat_set _nameWords; + base::flat_set _nameFirstLetters; HistoryItem *_lastMessage = nullptr; rpl::variable _unreadPosition; diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index a7cf254f0..0b43831a4 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -121,7 +121,7 @@ void PeerData::updateNameDelayed( Notify::PeerUpdate update(this); update.flags |= UpdateFlag::NameChanged; - update.oldNameFirstChars = nameFirstChars(); + update.oldNameFirstLetters = nameFirstLetters(); if (isUser()) { if (asUser()->username != newUsername) { @@ -304,7 +304,7 @@ void PeerData::setUserpicChecked( void PeerData::fillNames() { _nameWords.clear(); - _nameFirstChars.clear(); + _nameFirstLetters.clear(); auto toIndexList = QStringList(); auto appendToIndex = [&](const QString &value) { if (!value.isEmpty()) { @@ -318,7 +318,7 @@ void PeerData::fillNames() { if (appendTranslit) { appendToIndex(translitRusEng(toIndexList.front())); } - if (auto user = asUser()) { + if (const auto user = asUser()) { if (user->nameOrPhone != name) { appendToIndex(user->nameOrPhone); } @@ -326,7 +326,7 @@ void PeerData::fillNames() { if (isSelf()) { appendToIndex(lang(lng_saved_messages)); } - } else if (auto channel = asChannel()) { + } else if (const auto channel = asChannel()) { appendToIndex(channel->username); } auto toIndex = toIndexList.join(' '); @@ -335,7 +335,7 @@ void PeerData::fillNames() { const auto namesList = TextUtilities::PrepareSearchWords(toIndex); for (const auto &name : namesList) { _nameWords.insert(name); - _nameFirstChars.insert(name[0]); + _nameFirstLetters.insert(name[0]); } } diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index 6b94a2fb7..c8bc7ea65 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -126,13 +126,11 @@ public: QString name; Text nameText; - using NameWords = base::flat_set; - using NameFirstChars = base::flat_set; - const NameWords &nameWords() const { + const base::flat_set &nameWords() const { return _nameWords; } - const NameFirstChars &nameFirstChars() const { - return _nameFirstChars; + const base::flat_set &nameFirstLetters() const { + return _nameFirstLetters; } enum LoadedStatus { @@ -243,8 +241,8 @@ private: Data::NotifySettings _notify; ClickHandlerPtr _openLink; - NameWords _nameWords; // for filtering - NameFirstChars _nameFirstChars; + base::flat_set _nameWords; // for filtering + base::flat_set _nameFirstLetters; TimeMs _lastFullUpdate = 0; diff --git a/Telegram/SourceFiles/dialogs/dialogs_entry.h b/Telegram/SourceFiles/dialogs/dialogs_entry.h index bcedaf436..261661782 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_entry.h +++ b/Telegram/SourceFiles/dialogs/dialogs_entry.h @@ -73,6 +73,9 @@ public: virtual int chatListUnreadCount() const = 0; virtual bool chatListMutedBadge() const = 0; virtual HistoryItem *chatsListItem() const = 0; + virtual const QString &chatsListName() const = 0; + virtual const base::flat_set &chatsListNameWords() const = 0; + virtual const base::flat_set &chatsListFirstLetters() const = 0; virtual void loadUserpic() = 0; virtual void paintUserpic( diff --git a/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp b/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp index a7bc336f1..784b80e49 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp @@ -23,7 +23,7 @@ RowsByLetter IndexedList::addToEnd(Key key) { RowsByLetter result; if (!_list.contains(key)) { result.emplace(0, _list.addToEnd(key)); - for (auto ch : key.nameFirstChars()) { + for (auto ch : key.entry()->chatsListFirstLetters()) { auto j = _index.find(ch); if (j == _index.cend()) { j = _index.emplace( @@ -42,7 +42,7 @@ Row *IndexedList::addByName(Key key) { } Row *result = _list.addByName(key); - for (auto ch : key.nameFirstChars()) { + for (auto ch : key.entry()->chatsListFirstLetters()) { auto j = _index.find(ch); if (j == _index.cend()) { j = _index.emplace( @@ -68,7 +68,7 @@ void IndexedList::adjustByPos(const RowsByLetter &links) { void IndexedList::moveToTop(Key key) { if (_list.moveToTop(key)) { - for (auto ch : key.nameFirstChars()) { + for (auto ch : key.entry()->chatsListFirstLetters()) { if (auto it = _index.find(ch); it != _index.cend()) { it->second->moveToTop(key); } @@ -92,14 +92,14 @@ void IndexedList::movePinned(Row *row, int deltaSign) { void IndexedList::peerNameChanged( not_null peer, - const PeerData::NameFirstChars &oldChars) { + const base::flat_set &oldLetters) { Expects(_sortMode != SortMode::Date); if (const auto history = App::historyLoaded(peer)) { if (_sortMode == SortMode::Name) { - adjustByName(history, oldChars); + adjustByName(history, oldLetters); } else { - adjustNames(Dialogs::Mode::All, history, oldChars); + adjustNames(Dialogs::Mode::All, history, oldLetters); } } } @@ -107,22 +107,23 @@ void IndexedList::peerNameChanged( void IndexedList::peerNameChanged( Mode list, not_null peer, - const PeerData::NameFirstChars &oldChars) { + const base::flat_set &oldLetters) { Expects(_sortMode == SortMode::Date); if (const auto history = App::historyLoaded(peer)) { - adjustNames(list, history, oldChars); + adjustNames(list, history, oldLetters); } } void IndexedList::adjustByName( Key key, - const PeerData::NameFirstChars &oldChars) { + const base::flat_set &oldLetters) { const auto mainRow = _list.adjustByName(key); if (!mainRow) return; - PeerData::NameFirstChars toRemove = oldChars, toAdd; - for (auto ch : key.nameFirstChars()) { + auto toRemove = oldLetters; + auto toAdd = base::flat_set(); + for (auto ch : key.entry()->chatsListFirstLetters()) { auto j = toRemove.find(ch); if (j == toRemove.cend()) { toAdd.insert(ch); @@ -154,13 +155,14 @@ void IndexedList::adjustByName( void IndexedList::adjustNames( Mode list, not_null history, - const PeerData::NameFirstChars &oldChars) { + const base::flat_set &oldLetters) { const auto key = Dialogs::Key(history); auto mainRow = _list.getRow(key); if (!mainRow) return; - PeerData::NameFirstChars toRemove = oldChars, toAdd; - for (auto ch : key.nameFirstChars()) { + auto toRemove = oldLetters; + auto toAdd = base::flat_set(); + for (auto ch : key.entry()->chatsListFirstLetters()) { auto j = toRemove.find(ch); if (j == toRemove.cend()) { toAdd.insert(ch); @@ -192,7 +194,7 @@ void IndexedList::adjustNames( void IndexedList::del(Key key, Row *replacedBy) { if (_list.del(key, replacedBy)) { - for (auto ch : key.nameFirstChars()) { + for (auto ch : key.entry()->chatsListFirstLetters()) { if (auto it = _index.find(ch); it != _index.cend()) { it->second->del(key, replacedBy); } diff --git a/Telegram/SourceFiles/dialogs/dialogs_indexed_list.h b/Telegram/SourceFiles/dialogs/dialogs_indexed_list.h index 5550f7c4b..1f951fce8 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_indexed_list.h +++ b/Telegram/SourceFiles/dialogs/dialogs_indexed_list.h @@ -29,13 +29,13 @@ public: // For sortMode != SortMode::Date void peerNameChanged( not_null peer, - const PeerData::NameFirstChars &oldChars); + const base::flat_set &oldChars); //For sortMode == SortMode::Date void peerNameChanged( Mode list, not_null peer, - const PeerData::NameFirstChars &oldChars); + const base::flat_set &oldChars); void del(Key key, Row *replacedBy = nullptr); void clear(); @@ -77,11 +77,11 @@ public: private: void adjustByName( Key key, - const PeerData::NameFirstChars &oldChars); + const base::flat_set &oldChars); void adjustNames( Mode list, not_null history, - const PeerData::NameFirstChars &oldChars); + const base::flat_set &oldChars); SortMode _sortMode; List _list, _empty; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 7ab40c99f..0ae0b9fa8 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -127,7 +127,7 @@ DialogsInner::DialogsInner(QWidget *parent, not_null contro stopReorderPinned(); } if (update.flags & UpdateFlag::NameChanged) { - handlePeerNameChange(update.peer, update.oldNameFirstChars); + handlePeerNameChange(update.peer, update.oldNameFirstLetters); } if (update.flags & UpdateFlag::PhotoChanged) { this->update(); @@ -1457,13 +1457,18 @@ void DialogsInner::onParentGeometryChanged() { } } -void DialogsInner::handlePeerNameChange(not_null peer, const PeerData::NameFirstChars &oldChars) { - _dialogs->peerNameChanged(Dialogs::Mode::All, peer, oldChars); +void DialogsInner::handlePeerNameChange( + not_null peer, + const base::flat_set &oldLetters) { + _dialogs->peerNameChanged(Dialogs::Mode::All, peer, oldLetters); if (_dialogsImportant) { - _dialogsImportant->peerNameChanged(Dialogs::Mode::Important, peer, oldChars); + _dialogsImportant->peerNameChanged( + Dialogs::Mode::Important, + peer, + oldLetters); } - _contactsNoDialogs->peerNameChanged(peer, oldChars); - _contacts->peerNameChanged(peer, oldChars); + _contactsNoDialogs->peerNameChanged(peer, oldLetters); + _contacts->peerNameChanged(peer, oldLetters); update(); } @@ -1513,10 +1518,8 @@ void DialogsInner::onFilterUpdate(QString newFilter, bool force) { _filterResults.reserve((toFilter ? toFilter->size() : 0) + (toFilterContacts ? toFilterContacts->size() : 0)); if (toFilter) { - for_const (auto row, *toFilter) { - if (!row->history()) continue; - // #TODO feeds name - const auto &nameWords = row->history()->peer->nameWords(); + for (const auto row : *toFilter) { + const auto &nameWords = row->entry()->chatsListNameWords(); auto nb = nameWords.cbegin(), ne = nameWords.cend(), ni = nb; for (fi = fb; fi != fe; ++fi) { auto filterWord = *fi; @@ -1535,10 +1538,8 @@ void DialogsInner::onFilterUpdate(QString newFilter, bool force) { } } if (toFilterContacts) { - for_const (auto row, *toFilterContacts) { - if (!row->history()) continue; - // #TODO feeds name - const auto &nameWords = row->history()->peer->nameWords(); + for (const auto row : *toFilterContacts) { + const auto &nameWords = row->entry()->chatsListNameWords(); auto nb = nameWords.cbegin(), ne = nameWords.cend(), ni = nb; for (fi = fb; fi != fe; ++fi) { auto filterWord = *fi; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index b770dcf27..5316671c5 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -183,7 +183,7 @@ private: } void handlePeerNameChange( not_null peer, - const PeerData::NameFirstChars &oldChars); + const base::flat_set &oldLetters); void applyDialog(const MTPDdialog &dialog); void applyFeedDialog(const MTPDdialogFeed &dialog); diff --git a/Telegram/SourceFiles/dialogs/dialogs_key.cpp b/Telegram/SourceFiles/dialogs/dialogs_key.cpp index bd7a2127c..1e0e2f35b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_key.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_key.cpp @@ -12,31 +12,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Dialogs { -const QString &Key::name() const { - if (const auto h = history()) { - return h->peer->name; - } - // #TODO feeds name - static const auto empty = QString(); - return empty; -} - -const PeerData::NameFirstChars &Key::nameFirstChars() const { - if (const auto h = history()) { - return h->peer->nameFirstChars(); - } - // #TODO feeds name - static const auto empty = PeerData::NameFirstChars(); - return empty; -} - not_null Key::entry() const { if (const auto p = base::get_if>(&_value)) { return *p; } else if (const auto p = base::get_if>(&_value)) { return *p; } - Unexpected("Dialogs entry() call on empty Key."); + Unexpected("Empty Dialogs::Key in Key::entry()."); } History *Key::history() const { diff --git a/Telegram/SourceFiles/dialogs/dialogs_key.h b/Telegram/SourceFiles/dialogs/dialogs_key.h index 202ad1cad..94c3517b9 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_key.h +++ b/Telegram/SourceFiles/dialogs/dialogs_key.h @@ -38,9 +38,6 @@ public: History *history() const; Data::Feed *feed() const; - const QString &name() const; - const PeerData::NameFirstChars &nameFirstChars() const; - inline bool operator<(const Key &other) const { return _value < other._value; } diff --git a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp index 298c14971..503e0fc40 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp @@ -228,9 +228,8 @@ void paintRow( } from->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); } else { - // TODO feeds name p.setFont(st::msgNameFont); - auto text = QString("Feed"); + auto text = entry->chatsListName(); // TODO feed name with emoji auto textWidth = st::msgNameFont->width(text); if (textWidth > rectForName.width()) { text = st::msgNameFont->elided(text, rectForName.width()); diff --git a/Telegram/SourceFiles/dialogs/dialogs_list.cpp b/Telegram/SourceFiles/dialogs/dialogs_list.cpp index e72e3b4bd..c95b6f8fa 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_list.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_list.cpp @@ -114,13 +114,15 @@ Row *List::adjustByName(Key key) { if (i == _rowByKey.cend()) return nullptr; const auto row = i->second; - const auto name = key.name(); + const auto name = key.entry()->chatsListName(); auto change = row; - while (change->_prev && change->_prev->name().compare(name, Qt::CaseInsensitive) < 0) { + while (change->_prev + && change->_prev->entry()->chatsListName().compare(name, Qt::CaseInsensitive) < 0) { change = change->_prev; } if (!insertBefore(row, change)) { - while (change->_next != _end && change->_next->name().compare(name, Qt::CaseInsensitive) < 0) { + while (change->_next != _end + && change->_next->entry()->chatsListName().compare(name, Qt::CaseInsensitive) < 0) { change = change->_next; } insertAfter(row, change); @@ -135,12 +137,14 @@ Row *List::addByName(Key key) { const auto row = addToEnd(key); auto change = row; - const auto name = key.name(); - while (change->_prev && change->_prev->name().compare(name, Qt::CaseInsensitive) > 0) { + const auto name = key.entry()->chatsListName(); + while (change->_prev + && change->_prev->entry()->chatsListName().compare(name, Qt::CaseInsensitive) > 0) { change = change->_prev; } if (!insertBefore(row, change)) { - while (change->_next != _end && change->_next->name().compare(name, Qt::CaseInsensitive) < 0) { + while (change->_next != _end + && change->_next->entry()->chatsListName().compare(name, Qt::CaseInsensitive) < 0) { change = change->_next; } insertAfter(row, change); diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.h b/Telegram/SourceFiles/dialogs/dialogs_row.h index d87b7a884..47a061e9e 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.h +++ b/Telegram/SourceFiles/dialogs/dialogs_row.h @@ -61,9 +61,6 @@ public: not_null entry() const { return _id.entry(); } - QString name() const { - return _id.name(); - } int pos() const { return _pos; } diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index ce7f0a7aa..86d337845 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -2104,6 +2104,18 @@ HistoryItem *History::chatsListItem() const { return lastMsg; } +const QString &History::chatsListName() const { + return peer->name; +} + +const base::flat_set &History::chatsListNameWords() const { + return peer->nameWords(); +} + +const base::flat_set &History::chatsListFirstLetters() const { + return peer->nameFirstLetters(); +} + void History::loadUserpic() { peer->loadUserpic(); } diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index 2d1c80b84..cdda66176 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -313,6 +313,9 @@ public: int chatListUnreadCount() const override; bool chatListMutedBadge() const override; HistoryItem *chatsListItem() const override; + const QString &chatsListName() const override; + const base::flat_set &chatsListNameWords() const override; + const base::flat_set &chatsListFirstLetters() const override; void loadUserpic() override; void paintUserpic( Painter &p, diff --git a/Telegram/SourceFiles/observer_peer.cpp b/Telegram/SourceFiles/observer_peer.cpp index 241eaa6b6..ff1d0f1cf 100644 --- a/Telegram/SourceFiles/observer_peer.cpp +++ b/Telegram/SourceFiles/observer_peer.cpp @@ -33,7 +33,7 @@ base::Observable PeerUpdatedObservable; void mergePeerUpdate(PeerUpdate &mergeTo, const PeerUpdate &mergeFrom) { if (!(mergeTo.flags & PeerUpdate::Flag::NameChanged)) { if (mergeFrom.flags & PeerUpdate::Flag::NameChanged) { - mergeTo.oldNameFirstChars = mergeFrom.oldNameFirstChars; + mergeTo.oldNameFirstLetters = mergeFrom.oldNameFirstLetters; } } mergeTo.flags |= mergeFrom.flags; diff --git a/Telegram/SourceFiles/observer_peer.h b/Telegram/SourceFiles/observer_peer.h index 51eaae58c..8fed8c5b0 100644 --- a/Telegram/SourceFiles/observer_peer.h +++ b/Telegram/SourceFiles/observer_peer.h @@ -71,7 +71,7 @@ struct PeerUpdate { Flags flags = 0; // NameChanged data - PeerData::NameFirstChars oldNameFirstChars; + base::flat_set oldNameFirstLetters; }; diff --git a/Telegram/SourceFiles/profile/profile_channel_controllers.cpp b/Telegram/SourceFiles/profile/profile_channel_controllers.cpp index 47d9cde2d..0f8f5f3a5 100644 --- a/Telegram/SourceFiles/profile/profile_channel_controllers.cpp +++ b/Telegram/SourceFiles/profile/profile_channel_controllers.cpp @@ -1935,11 +1935,12 @@ void AddParticipantBoxSearchController::addChatsContacts() { return; } - for_const (auto row, *list) { - // #TODO feeds list - if (auto user = row->history()->peer->asUser()) { - if (allWordsAreFound(user->nameWords())) { - delegate()->peerListSearchAddRow(user); + for (const auto row : *list) { + if (const auto history = row->history()) { + if (const auto user = history->peer->asUser()) { + if (allWordsAreFound(user->nameWords())) { + delegate()->peerListSearchAddRow(user); + } } } }