mirror of
https://github.com/vale981/tdesktop
synced 2025-03-05 17:51:41 -05:00
Use "Feed" name for chats list index and search.
This commit is contained in:
parent
89941a8e83
commit
4527c03c0d
26 changed files with 178 additions and 136 deletions
|
@ -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
|
||||
|
|
|
@ -629,16 +629,16 @@ void PeerListContent::addToSearchIndex(not_null<PeerListRow*> 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<PeerListRow*> 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<PeerListRow*> row) {
|
|||
}
|
||||
}
|
||||
}
|
||||
row->setNameFirstChars({});
|
||||
row->setNameFirstLetters({});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -177,11 +177,11 @@ public:
|
|||
int outerWidth);
|
||||
float64 checkedRatio();
|
||||
|
||||
void setNameFirstChars(const base::flat_set<QChar> &nameFirstChars) {
|
||||
_nameFirstChars = nameFirstChars;
|
||||
void setNameFirstLetters(const base::flat_set<QChar> &firstLetters) {
|
||||
_nameFirstLetters = firstLetters;
|
||||
}
|
||||
const base::flat_set<QChar> &nameFirstChars() const {
|
||||
return _nameFirstChars;
|
||||
const base::flat_set<QChar> &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<QChar> _nameFirstChars;
|
||||
base::flat_set<QChar> _nameFirstLetters;
|
||||
int _absoluteIndex = -1;
|
||||
State _disabledState = State::Active;
|
||||
bool _initialized : 1;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<PeerData*> peer) {
|
|||
int ShareBox::Inner::chatIndex(not_null<PeerData*> 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<Chat*>(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;
|
||||
|
|
|
@ -202,9 +202,7 @@ private:
|
|||
|
||||
bool _searching = false;
|
||||
QString _lastQuery;
|
||||
using ByUsernameRows = QVector<PeerData*>;
|
||||
using ByUsernameDatas = QVector<Chat*>;
|
||||
ByUsernameRows _byUsernameFiltered;
|
||||
ByUsernameDatas d_byUsernameFiltered;
|
||||
std::vector<PeerData*> _byUsernameFiltered;
|
||||
std::vector<Chat*> d_byUsernameFiltered;
|
||||
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<ChannelData*> channel) {
|
||||
|
|
|
@ -53,6 +53,16 @@ public:
|
|||
HistoryItem *chatsListItem() const override {
|
||||
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 paintUserpic(
|
||||
Painter &p,
|
||||
|
@ -61,12 +71,16 @@ public:
|
|||
int size) const override;
|
||||
|
||||
private:
|
||||
void indexNameParts();
|
||||
void recountLastMessage();
|
||||
bool justSetLastMessage(not_null<HistoryItem*> item);
|
||||
|
||||
FeedId _id = 0;
|
||||
std::vector<not_null<History*>> _channels;
|
||||
|
||||
QString _name;
|
||||
base::flat_set<QString> _nameWords;
|
||||
base::flat_set<QChar> _nameFirstLetters;
|
||||
HistoryItem *_lastMessage = nullptr;
|
||||
|
||||
rpl::variable<MessagePosition> _unreadPosition;
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,13 +126,11 @@ public:
|
|||
QString name;
|
||||
Text nameText;
|
||||
|
||||
using NameWords = base::flat_set<QString>;
|
||||
using NameFirstChars = base::flat_set<QChar>;
|
||||
const NameWords &nameWords() const {
|
||||
const base::flat_set<QString> &nameWords() const {
|
||||
return _nameWords;
|
||||
}
|
||||
const NameFirstChars &nameFirstChars() const {
|
||||
return _nameFirstChars;
|
||||
const base::flat_set<QChar> &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<QString> _nameWords; // for filtering
|
||||
base::flat_set<QChar> _nameFirstLetters;
|
||||
|
||||
TimeMs _lastFullUpdate = 0;
|
||||
|
||||
|
|
|
@ -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<QString> &chatsListNameWords() const = 0;
|
||||
virtual const base::flat_set<QChar> &chatsListFirstLetters() const = 0;
|
||||
|
||||
virtual void loadUserpic() = 0;
|
||||
virtual void paintUserpic(
|
||||
|
|
|
@ -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<PeerData*> peer,
|
||||
const PeerData::NameFirstChars &oldChars) {
|
||||
const base::flat_set<QChar> &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<PeerData*> peer,
|
||||
const PeerData::NameFirstChars &oldChars) {
|
||||
const base::flat_set<QChar> &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<QChar> &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<QChar>();
|
||||
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*> history,
|
||||
const PeerData::NameFirstChars &oldChars) {
|
||||
const base::flat_set<QChar> &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<QChar>();
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -29,13 +29,13 @@ public:
|
|||
// For sortMode != SortMode::Date
|
||||
void peerNameChanged(
|
||||
not_null<PeerData*> peer,
|
||||
const PeerData::NameFirstChars &oldChars);
|
||||
const base::flat_set<QChar> &oldChars);
|
||||
|
||||
//For sortMode == SortMode::Date
|
||||
void peerNameChanged(
|
||||
Mode list,
|
||||
not_null<PeerData*> peer,
|
||||
const PeerData::NameFirstChars &oldChars);
|
||||
const base::flat_set<QChar> &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<QChar> &oldChars);
|
||||
void adjustNames(
|
||||
Mode list,
|
||||
not_null<History*> history,
|
||||
const PeerData::NameFirstChars &oldChars);
|
||||
const base::flat_set<QChar> &oldChars);
|
||||
|
||||
SortMode _sortMode;
|
||||
List _list, _empty;
|
||||
|
|
|
@ -127,7 +127,7 @@ DialogsInner::DialogsInner(QWidget *parent, not_null<Window::Controller*> 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<PeerData*> peer, const PeerData::NameFirstChars &oldChars) {
|
||||
_dialogs->peerNameChanged(Dialogs::Mode::All, peer, oldChars);
|
||||
void DialogsInner::handlePeerNameChange(
|
||||
not_null<PeerData*> peer,
|
||||
const base::flat_set<QChar> &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;
|
||||
|
|
|
@ -183,7 +183,7 @@ private:
|
|||
}
|
||||
void handlePeerNameChange(
|
||||
not_null<PeerData*> peer,
|
||||
const PeerData::NameFirstChars &oldChars);
|
||||
const base::flat_set<QChar> &oldLetters);
|
||||
|
||||
void applyDialog(const MTPDdialog &dialog);
|
||||
void applyFeedDialog(const MTPDdialogFeed &dialog);
|
||||
|
|
|
@ -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<Entry*> Key::entry() const {
|
||||
if (const auto p = base::get_if<not_null<History*>>(&_value)) {
|
||||
return *p;
|
||||
} else if (const auto p = base::get_if<not_null<Data::Feed*>>(&_value)) {
|
||||
return *p;
|
||||
}
|
||||
Unexpected("Dialogs entry() call on empty Key.");
|
||||
Unexpected("Empty Dialogs::Key in Key::entry().");
|
||||
}
|
||||
|
||||
History *Key::history() const {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -61,9 +61,6 @@ public:
|
|||
not_null<Entry*> entry() const {
|
||||
return _id.entry();
|
||||
}
|
||||
QString name() const {
|
||||
return _id.name();
|
||||
}
|
||||
int pos() const {
|
||||
return _pos;
|
||||
}
|
||||
|
|
|
@ -2104,6 +2104,18 @@ HistoryItem *History::chatsListItem() const {
|
|||
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() {
|
||||
peer->loadUserpic();
|
||||
}
|
||||
|
|
|
@ -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<QString> &chatsListNameWords() const override;
|
||||
const base::flat_set<QChar> &chatsListFirstLetters() const override;
|
||||
void loadUserpic() override;
|
||||
void paintUserpic(
|
||||
Painter &p,
|
||||
|
|
|
@ -33,7 +33,7 @@ base::Observable<PeerUpdate, PeerUpdatedHandler> 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;
|
||||
|
|
|
@ -71,7 +71,7 @@ struct PeerUpdate {
|
|||
Flags flags = 0;
|
||||
|
||||
// NameChanged data
|
||||
PeerData::NameFirstChars oldNameFirstChars;
|
||||
base::flat_set<QChar> oldNameFirstLetters;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue