Use "Feed" name for chats list index and search.

This commit is contained in:
John Preston 2018-01-22 12:33:09 +03:00
parent 89941a8e83
commit 4527c03c0d
26 changed files with 178 additions and 136 deletions

View file

@ -1415,6 +1415,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_admin_log_admin_pin_messages" = "Pin messages"; "lng_admin_log_admin_pin_messages" = "Pin messages";
"lng_admin_log_admin_add_admins" = "Add new admins"; "lng_admin_log_admin_add_admins" = "Add new admins";
"lng_feed_name" = "Feed";
"lng_feed_show_next" = "Show Next"; "lng_feed_show_next" = "Show Next";
// Wnd specific // Wnd specific

View file

@ -629,16 +629,16 @@ void PeerListContent::addToSearchIndex(not_null<PeerListRow*> row) {
} }
removeFromSearchIndex(row); removeFromSearchIndex(row);
row->setNameFirstChars(row->peer()->nameFirstChars()); row->setNameFirstLetters(row->peer()->nameFirstLetters());
for (auto ch : row->nameFirstChars()) { for (auto ch : row->nameFirstLetters()) {
_searchIndex[ch].push_back(row); _searchIndex[ch].push_back(row);
} }
} }
void PeerListContent::removeFromSearchIndex(not_null<PeerListRow*> row) { void PeerListContent::removeFromSearchIndex(not_null<PeerListRow*> row) {
auto &nameFirstChars = row->nameFirstChars(); const auto &nameFirstLetters = row->nameFirstLetters();
if (!nameFirstChars.empty()) { if (!nameFirstLetters.empty()) {
for (auto ch : row->nameFirstChars()) { for (auto ch : row->nameFirstLetters()) {
auto it = _searchIndex.find(ch); auto it = _searchIndex.find(ch);
if (it != _searchIndex.cend()) { if (it != _searchIndex.cend()) {
auto &entry = it->second; auto &entry = it->second;
@ -648,7 +648,7 @@ void PeerListContent::removeFromSearchIndex(not_null<PeerListRow*> row) {
} }
} }
} }
row->setNameFirstChars({}); row->setNameFirstLetters({});
} }
} }

View file

@ -177,11 +177,11 @@ public:
int outerWidth); int outerWidth);
float64 checkedRatio(); float64 checkedRatio();
void setNameFirstChars(const base::flat_set<QChar> &nameFirstChars) { void setNameFirstLetters(const base::flat_set<QChar> &firstLetters) {
_nameFirstChars = nameFirstChars; _nameFirstLetters = firstLetters;
} }
const base::flat_set<QChar> &nameFirstChars() const { const base::flat_set<QChar> &nameFirstLetters() const {
return _nameFirstChars; return _nameFirstLetters;
} }
virtual void lazyInitialize(const style::PeerListItem &st); virtual void lazyInitialize(const style::PeerListItem &st);
@ -218,7 +218,7 @@ private:
Text _status; Text _status;
StatusType _statusType = StatusType::Online; StatusType _statusType = StatusType::Online;
TimeMs _statusValidTill = 0; TimeMs _statusValidTill = 0;
base::flat_set<QChar> _nameFirstChars; base::flat_set<QChar> _nameFirstLetters;
int _absoluteIndex = -1; int _absoluteIndex = -1;
State _disabledState = State::Active; State _disabledState = State::Active;
bool _initialized : 1; bool _initialized : 1;

View file

@ -243,10 +243,11 @@ void ChatsListBoxController::rebuildRows() {
auto wasEmpty = !delegate()->peerListFullRowsCount(); auto wasEmpty = !delegate()->peerListFullRowsCount();
auto appendList = [this](auto chats) { auto appendList = [this](auto chats) {
auto count = 0; auto count = 0;
for_const (auto row, chats->all()) { for (const auto row : chats->all()) {
// #TODO feeds list if (const auto history = row->history()) {
if (appendRow(row->history())) { if (appendRow(history)) {
++count; ++count;
}
} }
} }
return count; return count;
@ -328,12 +329,12 @@ void ContactsBoxController::prepare() {
void ContactsBoxController::rebuildRows() { void ContactsBoxController::rebuildRows() {
auto appendList = [this](auto chats) { auto appendList = [this](auto chats) {
auto count = 0; auto count = 0;
for_const (auto row, chats->all()) { for (const auto row : chats->all()) {
// #TODO feeds list if (const auto history = row->history()) {
auto history = row->history(); if (const auto user = history->peer->asUser()) {
if (auto user = history->peer->asUser()) { if (appendRow(user)) {
if (appendRow(user)) { ++count;
++count; }
} }
} }
} }

View file

@ -281,9 +281,9 @@ ShareBox::Inner::Inner(QWidget *parent, ShareBox::FilterCallback &&filterCallbac
} }
} }
for (const auto row : dialogs->all()) { for (const auto row : dialogs->all()) {
// #TODO feeds list
if (const auto history = row->history()) { if (const auto history = row->history()) {
if (!history->peer->isSelf() && _filterCallback(history->peer)) { if (!history->peer->isSelf()
&& _filterCallback(history->peer)) {
_chatsIndexed->addToEnd(history); _chatsIndexed->addToEnd(history);
} }
} }
@ -352,7 +352,7 @@ void ShareBox::Inner::notifyPeerUpdated(const Notify::PeerUpdate &update) {
if (update.flags & Notify::PeerUpdate::Flag::NameChanged) { if (update.flags & Notify::PeerUpdate::Flag::NameChanged) {
_chatsIndexed->peerNameChanged( _chatsIndexed->peerNameChanged(
update.peer, update.peer,
update.oldNameFirstChars); update.oldNameFirstLetters);
} }
updateChat(update.peer); updateChat(update.peer);
@ -407,22 +407,24 @@ void ShareBox::Inner::repaintChat(not_null<PeerData*> peer) {
int ShareBox::Inner::chatIndex(not_null<PeerData*> peer) const { int ShareBox::Inner::chatIndex(not_null<PeerData*> peer) const {
int index = 0; int index = 0;
if (_filter.isEmpty()) { if (_filter.isEmpty()) {
for_const (auto row, _chatsIndexed->all()) { for (const auto row : _chatsIndexed->all()) {
// #TODO feeds list if (const auto history = row->history()) {
if (row->history()->peer == peer) { if (history->peer == peer) {
return index; return index;
}
} }
++index; ++index;
} }
} else { } else {
for_const (auto row, _filtered) { for (const auto row : _filtered) {
// #TODO feeds list if (const auto history = row->history()) {
if (row->history()->peer == peer) { if (history->peer == peer) {
return index; return index;
}
} }
++index; ++index;
} }
for_const (auto row, d_byUsernameFiltered) { for (const auto row : d_byUsernameFiltered) {
if (row->peer == peer) { if (row->peer == peer) {
return index; return index;
} }
@ -455,8 +457,7 @@ void ShareBox::Inner::loadProfilePhotos(int yFrom) {
if (((*i)->pos() * _rowHeight) >= yTo) { if (((*i)->pos() * _rowHeight) >= yTo) {
break; break;
} }
// #TODO feeds list (*i)->entry()->loadUserpic();
(*i)->history()->peer->loadUserpic();
} }
} }
} else if (!_filtered.isEmpty()) { } else if (!_filtered.isEmpty()) {
@ -467,17 +468,17 @@ void ShareBox::Inner::loadProfilePhotos(int yFrom) {
if (to > _filtered.size()) to = _filtered.size(); if (to > _filtered.size()) to = _filtered.size();
for (; from < to; ++from) { for (; from < to; ++from) {
// #TODO feeds list _filtered[from]->entry()->loadUserpic();
_filtered[from]->history()->peer->loadUserpic();
} }
} }
} }
} }
ShareBox::Inner::Chat *ShareBox::Inner::getChat(Dialogs::Row *row) { ShareBox::Inner::Chat *ShareBox::Inner::getChat(Dialogs::Row *row) {
Expects(row->history() != nullptr);
auto data = static_cast<Chat*>(row->attached); auto data = static_cast<Chat*>(row->attached);
if (!data) { if (!data) {
// #TODO feeds list
auto peer = row->history()->peer; auto peer = row->history()->peer;
auto i = _dataMap.constFind(peer); auto i = _dataMap.constFind(peer);
if (i == _dataMap.cend()) { if (i == _dataMap.cend()) {
@ -565,7 +566,7 @@ void ShareBox::Inner::paintEvent(QPaintEvent *e) {
p.setPen(st::noContactsColor); p.setPen(st::noContactsColor);
} }
} else { } else {
if (_filtered.isEmpty() && _byUsernameFiltered.isEmpty()) { if (_filtered.isEmpty() && _byUsernameFiltered.empty()) {
// empty // empty
p.setFont(st::noContactsFont); p.setFont(st::noContactsFont);
p.setPen(st::noContactsColor); p.setPen(st::noContactsColor);
@ -583,7 +584,7 @@ void ShareBox::Inner::paintEvent(QPaintEvent *e) {
indexFrom -= filteredSize; indexFrom -= filteredSize;
indexTo -= filteredSize; indexTo -= filteredSize;
} }
if (!_byUsernameFiltered.isEmpty()) { if (!_byUsernameFiltered.empty()) {
if (indexFrom < 0) indexFrom = 0; if (indexFrom < 0) indexFrom = 0;
while (indexFrom < indexTo) { while (indexFrom < indexTo) {
if (indexFrom >= d_byUsernameFiltered.size()) { if (indexFrom >= d_byUsernameFiltered.size()) {
@ -732,9 +733,8 @@ void ShareBox::Inner::updateFilter(QString filter) {
} }
if (toFilter) { if (toFilter) {
_filtered.reserve(toFilter->size()); _filtered.reserve(toFilter->size());
for_const (auto row, *toFilter) { for (const auto row : *toFilter) {
// #TODO feeds list auto &nameWords = row->entry()->chatsListNameWords();
auto &nameWords = row->history()->peer->nameWords();
auto nb = nameWords.cbegin(), ne = nameWords.cend(), ni = nb; auto nb = nameWords.cbegin(), ne = nameWords.cend(), ni = nb;
for (fi = fb; fi != fe; ++fi) { for (fi = fb; fi != fe; ++fi) {
auto filterName = *fi; auto filterName = *fi;

View file

@ -202,9 +202,7 @@ private:
bool _searching = false; bool _searching = false;
QString _lastQuery; QString _lastQuery;
using ByUsernameRows = QVector<PeerData*>; std::vector<PeerData*> _byUsernameFiltered;
using ByUsernameDatas = QVector<Chat*>; std::vector<Chat*> d_byUsernameFiltered;
ByUsernameRows _byUsernameFiltered;
ByUsernameDatas d_byUsernameFiltered;
}; };

View file

@ -159,8 +159,8 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
} }
return true; return true;
}; };
auto filterNotPassedByName = [this, &filterNotPassedByUsername](UserData *user) -> bool { auto filterNotPassedByName = [&](UserData *user) -> bool {
for (auto &nameWord : user->nameWords()) { for (const auto &nameWord : user->nameWords()) {
if (nameWord.startsWith(_filter, Qt::CaseInsensitive)) { if (nameWord.startsWith(_filter, Qt::CaseInsensitive)) {
auto exactUsername = (user->username.compare(_filter, Qt::CaseInsensitive) == 0); auto exactUsername = (user->username.compare(_filter, Qt::CaseInsensitive) == 0);
return exactUsername; return exactUsername;

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 "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "lang/lang_keys.h"
namespace Data { namespace Data {
@ -24,7 +25,35 @@ MessagePosition FeedPositionFromMTP(const MTPFeedPosition &position) {
Feed::Feed(FeedId id) Feed::Feed(FeedId id)
: Entry(this) : 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<ChannelData*> channel) { void Feed::registerOne(not_null<ChannelData*> channel) {

View file

@ -53,6 +53,16 @@ public:
HistoryItem *chatsListItem() const override { HistoryItem *chatsListItem() const override {
return _lastMessage; return _lastMessage;
} }
const QString &chatsListName() const override {
return _name;
}
const base::flat_set<QString> &chatsListNameWords() const override {
return _nameWords;
}
const base::flat_set<QChar> &chatsListFirstLetters() const override {
return _nameFirstLetters;
}
void loadUserpic() override; void loadUserpic() override;
void paintUserpic( void paintUserpic(
Painter &p, Painter &p,
@ -61,12 +71,16 @@ public:
int size) const override; int size) const override;
private: private:
void indexNameParts();
void recountLastMessage(); void recountLastMessage();
bool justSetLastMessage(not_null<HistoryItem*> item); bool justSetLastMessage(not_null<HistoryItem*> item);
FeedId _id = 0; FeedId _id = 0;
std::vector<not_null<History*>> _channels; std::vector<not_null<History*>> _channels;
QString _name;
base::flat_set<QString> _nameWords;
base::flat_set<QChar> _nameFirstLetters;
HistoryItem *_lastMessage = nullptr; HistoryItem *_lastMessage = nullptr;
rpl::variable<MessagePosition> _unreadPosition; rpl::variable<MessagePosition> _unreadPosition;

View file

@ -121,7 +121,7 @@ void PeerData::updateNameDelayed(
Notify::PeerUpdate update(this); Notify::PeerUpdate update(this);
update.flags |= UpdateFlag::NameChanged; update.flags |= UpdateFlag::NameChanged;
update.oldNameFirstChars = nameFirstChars(); update.oldNameFirstLetters = nameFirstLetters();
if (isUser()) { if (isUser()) {
if (asUser()->username != newUsername) { if (asUser()->username != newUsername) {
@ -304,7 +304,7 @@ void PeerData::setUserpicChecked(
void PeerData::fillNames() { void PeerData::fillNames() {
_nameWords.clear(); _nameWords.clear();
_nameFirstChars.clear(); _nameFirstLetters.clear();
auto toIndexList = QStringList(); auto toIndexList = QStringList();
auto appendToIndex = [&](const QString &value) { auto appendToIndex = [&](const QString &value) {
if (!value.isEmpty()) { if (!value.isEmpty()) {
@ -318,7 +318,7 @@ void PeerData::fillNames() {
if (appendTranslit) { if (appendTranslit) {
appendToIndex(translitRusEng(toIndexList.front())); appendToIndex(translitRusEng(toIndexList.front()));
} }
if (auto user = asUser()) { if (const auto user = asUser()) {
if (user->nameOrPhone != name) { if (user->nameOrPhone != name) {
appendToIndex(user->nameOrPhone); appendToIndex(user->nameOrPhone);
} }
@ -326,7 +326,7 @@ void PeerData::fillNames() {
if (isSelf()) { if (isSelf()) {
appendToIndex(lang(lng_saved_messages)); appendToIndex(lang(lng_saved_messages));
} }
} else if (auto channel = asChannel()) { } else if (const auto channel = asChannel()) {
appendToIndex(channel->username); appendToIndex(channel->username);
} }
auto toIndex = toIndexList.join(' '); auto toIndex = toIndexList.join(' ');
@ -335,7 +335,7 @@ void PeerData::fillNames() {
const auto namesList = TextUtilities::PrepareSearchWords(toIndex); const auto namesList = TextUtilities::PrepareSearchWords(toIndex);
for (const auto &name : namesList) { for (const auto &name : namesList) {
_nameWords.insert(name); _nameWords.insert(name);
_nameFirstChars.insert(name[0]); _nameFirstLetters.insert(name[0]);
} }
} }

View file

@ -126,13 +126,11 @@ public:
QString name; QString name;
Text nameText; Text nameText;
using NameWords = base::flat_set<QString>; const base::flat_set<QString> &nameWords() const {
using NameFirstChars = base::flat_set<QChar>;
const NameWords &nameWords() const {
return _nameWords; return _nameWords;
} }
const NameFirstChars &nameFirstChars() const { const base::flat_set<QChar> &nameFirstLetters() const {
return _nameFirstChars; return _nameFirstLetters;
} }
enum LoadedStatus { enum LoadedStatus {
@ -243,8 +241,8 @@ private:
Data::NotifySettings _notify; Data::NotifySettings _notify;
ClickHandlerPtr _openLink; ClickHandlerPtr _openLink;
NameWords _nameWords; // for filtering base::flat_set<QString> _nameWords; // for filtering
NameFirstChars _nameFirstChars; base::flat_set<QChar> _nameFirstLetters;
TimeMs _lastFullUpdate = 0; TimeMs _lastFullUpdate = 0;

View file

@ -73,6 +73,9 @@ public:
virtual int chatListUnreadCount() const = 0; virtual int chatListUnreadCount() const = 0;
virtual bool chatListMutedBadge() const = 0; virtual bool chatListMutedBadge() const = 0;
virtual HistoryItem *chatsListItem() const = 0; virtual HistoryItem *chatsListItem() const = 0;
virtual const QString &chatsListName() const = 0;
virtual const base::flat_set<QString> &chatsListNameWords() const = 0;
virtual const base::flat_set<QChar> &chatsListFirstLetters() const = 0;
virtual void loadUserpic() = 0; virtual void loadUserpic() = 0;
virtual void paintUserpic( virtual void paintUserpic(

View file

@ -23,7 +23,7 @@ RowsByLetter IndexedList::addToEnd(Key key) {
RowsByLetter result; RowsByLetter result;
if (!_list.contains(key)) { if (!_list.contains(key)) {
result.emplace(0, _list.addToEnd(key)); result.emplace(0, _list.addToEnd(key));
for (auto ch : key.nameFirstChars()) { for (auto ch : key.entry()->chatsListFirstLetters()) {
auto j = _index.find(ch); auto j = _index.find(ch);
if (j == _index.cend()) { if (j == _index.cend()) {
j = _index.emplace( j = _index.emplace(
@ -42,7 +42,7 @@ Row *IndexedList::addByName(Key key) {
} }
Row *result = _list.addByName(key); Row *result = _list.addByName(key);
for (auto ch : key.nameFirstChars()) { for (auto ch : key.entry()->chatsListFirstLetters()) {
auto j = _index.find(ch); auto j = _index.find(ch);
if (j == _index.cend()) { if (j == _index.cend()) {
j = _index.emplace( j = _index.emplace(
@ -68,7 +68,7 @@ void IndexedList::adjustByPos(const RowsByLetter &links) {
void IndexedList::moveToTop(Key key) { void IndexedList::moveToTop(Key key) {
if (_list.moveToTop(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()) { if (auto it = _index.find(ch); it != _index.cend()) {
it->second->moveToTop(key); it->second->moveToTop(key);
} }
@ -92,14 +92,14 @@ void IndexedList::movePinned(Row *row, int deltaSign) {
void IndexedList::peerNameChanged( void IndexedList::peerNameChanged(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const PeerData::NameFirstChars &oldChars) { const base::flat_set<QChar> &oldLetters) {
Expects(_sortMode != SortMode::Date); Expects(_sortMode != SortMode::Date);
if (const auto history = App::historyLoaded(peer)) { if (const auto history = App::historyLoaded(peer)) {
if (_sortMode == SortMode::Name) { if (_sortMode == SortMode::Name) {
adjustByName(history, oldChars); adjustByName(history, oldLetters);
} else { } else {
adjustNames(Dialogs::Mode::All, history, oldChars); adjustNames(Dialogs::Mode::All, history, oldLetters);
} }
} }
} }
@ -107,22 +107,23 @@ void IndexedList::peerNameChanged(
void IndexedList::peerNameChanged( void IndexedList::peerNameChanged(
Mode list, Mode list,
not_null<PeerData*> peer, not_null<PeerData*> peer,
const PeerData::NameFirstChars &oldChars) { const base::flat_set<QChar> &oldLetters) {
Expects(_sortMode == SortMode::Date); Expects(_sortMode == SortMode::Date);
if (const auto history = App::historyLoaded(peer)) { if (const auto history = App::historyLoaded(peer)) {
adjustNames(list, history, oldChars); adjustNames(list, history, oldLetters);
} }
} }
void IndexedList::adjustByName( void IndexedList::adjustByName(
Key key, Key key,
const PeerData::NameFirstChars &oldChars) { const base::flat_set<QChar> &oldLetters) {
const auto mainRow = _list.adjustByName(key); const auto mainRow = _list.adjustByName(key);
if (!mainRow) return; if (!mainRow) return;
PeerData::NameFirstChars toRemove = oldChars, toAdd; auto toRemove = oldLetters;
for (auto ch : key.nameFirstChars()) { auto toAdd = base::flat_set<QChar>();
for (auto ch : key.entry()->chatsListFirstLetters()) {
auto j = toRemove.find(ch); auto j = toRemove.find(ch);
if (j == toRemove.cend()) { if (j == toRemove.cend()) {
toAdd.insert(ch); toAdd.insert(ch);
@ -154,13 +155,14 @@ void IndexedList::adjustByName(
void IndexedList::adjustNames( void IndexedList::adjustNames(
Mode list, Mode list,
not_null<History*> history, not_null<History*> history,
const PeerData::NameFirstChars &oldChars) { const base::flat_set<QChar> &oldLetters) {
const auto key = Dialogs::Key(history); const auto key = Dialogs::Key(history);
auto mainRow = _list.getRow(key); auto mainRow = _list.getRow(key);
if (!mainRow) return; if (!mainRow) return;
PeerData::NameFirstChars toRemove = oldChars, toAdd; auto toRemove = oldLetters;
for (auto ch : key.nameFirstChars()) { auto toAdd = base::flat_set<QChar>();
for (auto ch : key.entry()->chatsListFirstLetters()) {
auto j = toRemove.find(ch); auto j = toRemove.find(ch);
if (j == toRemove.cend()) { if (j == toRemove.cend()) {
toAdd.insert(ch); toAdd.insert(ch);
@ -192,7 +194,7 @@ void IndexedList::adjustNames(
void IndexedList::del(Key key, Row *replacedBy) { void IndexedList::del(Key key, Row *replacedBy) {
if (_list.del(key, 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()) { if (auto it = _index.find(ch); it != _index.cend()) {
it->second->del(key, replacedBy); it->second->del(key, replacedBy);
} }

View file

@ -29,13 +29,13 @@ public:
// For sortMode != SortMode::Date // For sortMode != SortMode::Date
void peerNameChanged( void peerNameChanged(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const PeerData::NameFirstChars &oldChars); const base::flat_set<QChar> &oldChars);
//For sortMode == SortMode::Date //For sortMode == SortMode::Date
void peerNameChanged( void peerNameChanged(
Mode list, Mode list,
not_null<PeerData*> peer, not_null<PeerData*> peer,
const PeerData::NameFirstChars &oldChars); const base::flat_set<QChar> &oldChars);
void del(Key key, Row *replacedBy = nullptr); void del(Key key, Row *replacedBy = nullptr);
void clear(); void clear();
@ -77,11 +77,11 @@ public:
private: private:
void adjustByName( void adjustByName(
Key key, Key key,
const PeerData::NameFirstChars &oldChars); const base::flat_set<QChar> &oldChars);
void adjustNames( void adjustNames(
Mode list, Mode list,
not_null<History*> history, not_null<History*> history,
const PeerData::NameFirstChars &oldChars); const base::flat_set<QChar> &oldChars);
SortMode _sortMode; SortMode _sortMode;
List _list, _empty; List _list, _empty;

View file

@ -127,7 +127,7 @@ DialogsInner::DialogsInner(QWidget *parent, not_null<Window::Controller*> contro
stopReorderPinned(); stopReorderPinned();
} }
if (update.flags & UpdateFlag::NameChanged) { if (update.flags & UpdateFlag::NameChanged) {
handlePeerNameChange(update.peer, update.oldNameFirstChars); handlePeerNameChange(update.peer, update.oldNameFirstLetters);
} }
if (update.flags & UpdateFlag::PhotoChanged) { if (update.flags & UpdateFlag::PhotoChanged) {
this->update(); this->update();
@ -1457,13 +1457,18 @@ void DialogsInner::onParentGeometryChanged() {
} }
} }
void DialogsInner::handlePeerNameChange(not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars) { void DialogsInner::handlePeerNameChange(
_dialogs->peerNameChanged(Dialogs::Mode::All, peer, oldChars); not_null<PeerData*> peer,
const base::flat_set<QChar> &oldLetters) {
_dialogs->peerNameChanged(Dialogs::Mode::All, peer, oldLetters);
if (_dialogsImportant) { if (_dialogsImportant) {
_dialogsImportant->peerNameChanged(Dialogs::Mode::Important, peer, oldChars); _dialogsImportant->peerNameChanged(
Dialogs::Mode::Important,
peer,
oldLetters);
} }
_contactsNoDialogs->peerNameChanged(peer, oldChars); _contactsNoDialogs->peerNameChanged(peer, oldLetters);
_contacts->peerNameChanged(peer, oldChars); _contacts->peerNameChanged(peer, oldLetters);
update(); update();
} }
@ -1513,10 +1518,8 @@ void DialogsInner::onFilterUpdate(QString newFilter, bool force) {
_filterResults.reserve((toFilter ? toFilter->size() : 0) _filterResults.reserve((toFilter ? toFilter->size() : 0)
+ (toFilterContacts ? toFilterContacts->size() : 0)); + (toFilterContacts ? toFilterContacts->size() : 0));
if (toFilter) { if (toFilter) {
for_const (auto row, *toFilter) { for (const auto row : *toFilter) {
if (!row->history()) continue; const auto &nameWords = row->entry()->chatsListNameWords();
// #TODO feeds name
const auto &nameWords = row->history()->peer->nameWords();
auto nb = nameWords.cbegin(), ne = nameWords.cend(), ni = nb; auto nb = nameWords.cbegin(), ne = nameWords.cend(), ni = nb;
for (fi = fb; fi != fe; ++fi) { for (fi = fb; fi != fe; ++fi) {
auto filterWord = *fi; auto filterWord = *fi;
@ -1535,10 +1538,8 @@ void DialogsInner::onFilterUpdate(QString newFilter, bool force) {
} }
} }
if (toFilterContacts) { if (toFilterContacts) {
for_const (auto row, *toFilterContacts) { for (const auto row : *toFilterContacts) {
if (!row->history()) continue; const auto &nameWords = row->entry()->chatsListNameWords();
// #TODO feeds name
const auto &nameWords = row->history()->peer->nameWords();
auto nb = nameWords.cbegin(), ne = nameWords.cend(), ni = nb; auto nb = nameWords.cbegin(), ne = nameWords.cend(), ni = nb;
for (fi = fb; fi != fe; ++fi) { for (fi = fb; fi != fe; ++fi) {
auto filterWord = *fi; auto filterWord = *fi;

View file

@ -183,7 +183,7 @@ private:
} }
void handlePeerNameChange( void handlePeerNameChange(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const PeerData::NameFirstChars &oldChars); const base::flat_set<QChar> &oldLetters);
void applyDialog(const MTPDdialog &dialog); void applyDialog(const MTPDdialog &dialog);
void applyFeedDialog(const MTPDdialogFeed &dialog); void applyFeedDialog(const MTPDdialogFeed &dialog);

View file

@ -12,31 +12,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Dialogs { 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<Entry*> Key::entry() const { not_null<Entry*> Key::entry() const {
if (const auto p = base::get_if<not_null<History*>>(&_value)) { if (const auto p = base::get_if<not_null<History*>>(&_value)) {
return *p; return *p;
} else if (const auto p = base::get_if<not_null<Data::Feed*>>(&_value)) { } else if (const auto p = base::get_if<not_null<Data::Feed*>>(&_value)) {
return *p; return *p;
} }
Unexpected("Dialogs entry() call on empty Key."); Unexpected("Empty Dialogs::Key in Key::entry().");
} }
History *Key::history() const { History *Key::history() const {

View file

@ -38,9 +38,6 @@ public:
History *history() const; History *history() const;
Data::Feed *feed() const; Data::Feed *feed() const;
const QString &name() const;
const PeerData::NameFirstChars &nameFirstChars() const;
inline bool operator<(const Key &other) const { inline bool operator<(const Key &other) const {
return _value < other._value; return _value < other._value;
} }

View file

@ -228,9 +228,8 @@ void paintRow(
} }
from->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); from->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
} else { } else {
// TODO feeds name
p.setFont(st::msgNameFont); p.setFont(st::msgNameFont);
auto text = QString("Feed"); auto text = entry->chatsListName(); // TODO feed name with emoji
auto textWidth = st::msgNameFont->width(text); auto textWidth = st::msgNameFont->width(text);
if (textWidth > rectForName.width()) { if (textWidth > rectForName.width()) {
text = st::msgNameFont->elided(text, rectForName.width()); text = st::msgNameFont->elided(text, rectForName.width());

View file

@ -114,13 +114,15 @@ Row *List::adjustByName(Key key) {
if (i == _rowByKey.cend()) return nullptr; if (i == _rowByKey.cend()) return nullptr;
const auto row = i->second; const auto row = i->second;
const auto name = key.name(); const auto name = key.entry()->chatsListName();
auto change = row; 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; change = change->_prev;
} }
if (!insertBefore(row, change)) { 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; change = change->_next;
} }
insertAfter(row, change); insertAfter(row, change);
@ -135,12 +137,14 @@ Row *List::addByName(Key key) {
const auto row = addToEnd(key); const auto row = addToEnd(key);
auto change = row; auto change = row;
const auto name = key.name(); const auto name = key.entry()->chatsListName();
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; change = change->_prev;
} }
if (!insertBefore(row, change)) { 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; change = change->_next;
} }
insertAfter(row, change); insertAfter(row, change);

View file

@ -61,9 +61,6 @@ public:
not_null<Entry*> entry() const { not_null<Entry*> entry() const {
return _id.entry(); return _id.entry();
} }
QString name() const {
return _id.name();
}
int pos() const { int pos() const {
return _pos; return _pos;
} }

View file

@ -2104,6 +2104,18 @@ HistoryItem *History::chatsListItem() const {
return lastMsg; return lastMsg;
} }
const QString &History::chatsListName() const {
return peer->name;
}
const base::flat_set<QString> &History::chatsListNameWords() const {
return peer->nameWords();
}
const base::flat_set<QChar> &History::chatsListFirstLetters() const {
return peer->nameFirstLetters();
}
void History::loadUserpic() { void History::loadUserpic() {
peer->loadUserpic(); peer->loadUserpic();
} }

View file

@ -313,6 +313,9 @@ public:
int chatListUnreadCount() const override; int chatListUnreadCount() const override;
bool chatListMutedBadge() const override; bool chatListMutedBadge() const override;
HistoryItem *chatsListItem() const override; HistoryItem *chatsListItem() const override;
const QString &chatsListName() const override;
const base::flat_set<QString> &chatsListNameWords() const override;
const base::flat_set<QChar> &chatsListFirstLetters() const override;
void loadUserpic() override; void loadUserpic() override;
void paintUserpic( void paintUserpic(
Painter &p, Painter &p,

View file

@ -33,7 +33,7 @@ base::Observable<PeerUpdate, PeerUpdatedHandler> PeerUpdatedObservable;
void mergePeerUpdate(PeerUpdate &mergeTo, const PeerUpdate &mergeFrom) { void mergePeerUpdate(PeerUpdate &mergeTo, const PeerUpdate &mergeFrom) {
if (!(mergeTo.flags & PeerUpdate::Flag::NameChanged)) { if (!(mergeTo.flags & PeerUpdate::Flag::NameChanged)) {
if (mergeFrom.flags & PeerUpdate::Flag::NameChanged) { if (mergeFrom.flags & PeerUpdate::Flag::NameChanged) {
mergeTo.oldNameFirstChars = mergeFrom.oldNameFirstChars; mergeTo.oldNameFirstLetters = mergeFrom.oldNameFirstLetters;
} }
} }
mergeTo.flags |= mergeFrom.flags; mergeTo.flags |= mergeFrom.flags;

View file

@ -71,7 +71,7 @@ struct PeerUpdate {
Flags flags = 0; Flags flags = 0;
// NameChanged data // NameChanged data
PeerData::NameFirstChars oldNameFirstChars; base::flat_set<QChar> oldNameFirstLetters;
}; };

View file

@ -1935,11 +1935,12 @@ void AddParticipantBoxSearchController::addChatsContacts() {
return; return;
} }
for_const (auto row, *list) { for (const auto row : *list) {
// #TODO feeds list if (const auto history = row->history()) {
if (auto user = row->history()->peer->asUser()) { if (const auto user = history->peer->asUser()) {
if (allWordsAreFound(user->nameWords())) { if (allWordsAreFound(user->nameWords())) {
delegate()->peerListSearchAddRow(user); delegate()->peerListSearchAddRow(user);
}
} }
} }
} }