mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Use "Feed" name for chats list index and search.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user