mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Save info members list state to memento.
This commit is contained in:
@@ -20,10 +20,12 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "base/flat_map.h"
|
||||
|
||||
namespace Dialogs {
|
||||
|
||||
class Row;
|
||||
using RowsByLetter = QMap<QChar, Row*>;
|
||||
using RowsByLetter = base::flat_map<QChar, Row*>;
|
||||
|
||||
enum class SortMode {
|
||||
Date = 0x00,
|
||||
|
@@ -24,19 +24,22 @@ namespace Dialogs {
|
||||
|
||||
IndexedList::IndexedList(SortMode sortMode)
|
||||
: _sortMode(sortMode)
|
||||
, _list(sortMode) {
|
||||
, _list(sortMode)
|
||||
, _empty(sortMode) {
|
||||
}
|
||||
|
||||
RowsByLetter IndexedList::addToEnd(History *history) {
|
||||
RowsByLetter result;
|
||||
if (!_list.contains(history->peer->id)) {
|
||||
result.insert(0, _list.addToEnd(history));
|
||||
for_const (auto ch, history->peer->chars) {
|
||||
result.emplace(0, _list.addToEnd(history));
|
||||
for (auto ch : history->peer->nameFirstChars()) {
|
||||
auto j = _index.find(ch);
|
||||
if (j == _index.cend()) {
|
||||
j = _index.insert(ch, new List(_sortMode));
|
||||
j = _index.emplace(
|
||||
ch,
|
||||
std::make_unique<List>(_sortMode)).first;
|
||||
}
|
||||
result.insert(ch, j.value()->addToEnd(history));
|
||||
result.emplace(ch, j->second->addToEnd(history));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -48,33 +51,35 @@ Row *IndexedList::addByName(History *history) {
|
||||
}
|
||||
|
||||
Row *result = _list.addByName(history);
|
||||
for_const (auto ch, history->peer->chars) {
|
||||
for (auto ch : history->peer->nameFirstChars()) {
|
||||
auto j = _index.find(ch);
|
||||
if (j == _index.cend()) {
|
||||
j = _index.insert(ch, new List(_sortMode));
|
||||
j = _index.emplace(
|
||||
ch,
|
||||
std::make_unique<List>(_sortMode)).first;
|
||||
}
|
||||
j.value()->addByName(history);
|
||||
j->second->addByName(history);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void IndexedList::adjustByPos(const RowsByLetter &links) {
|
||||
for (auto i = links.cbegin(), e = links.cend(); i != e; ++i) {
|
||||
if (i.key() == QChar(0)) {
|
||||
_list.adjustByPos(i.value());
|
||||
for (auto [ch, row] : links) {
|
||||
if (ch == QChar(0)) {
|
||||
_list.adjustByPos(row);
|
||||
} else {
|
||||
if (auto list = _index.value(i.key())) {
|
||||
list->adjustByPos(i.value());
|
||||
if (auto it = _index.find(ch); it != _index.cend()) {
|
||||
it->second->adjustByPos(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IndexedList::moveToTop(PeerData *peer) {
|
||||
void IndexedList::moveToTop(not_null<PeerData*> peer) {
|
||||
if (_list.moveToTop(peer->id)) {
|
||||
for_const (auto ch, peer->chars) {
|
||||
if (auto list = _index.value(ch)) {
|
||||
list->moveToTop(peer->id);
|
||||
for (auto ch : peer->nameFirstChars()) {
|
||||
if (auto it = _index.find(ch); it != _index.cend()) {
|
||||
it->second->moveToTop(peer->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,62 +104,64 @@ void IndexedList::movePinned(Row *row, int deltaSign) {
|
||||
history2->setPinnedIndex(index1);
|
||||
}
|
||||
|
||||
void IndexedList::peerNameChanged(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars) {
|
||||
void IndexedList::peerNameChanged(not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars) {
|
||||
Assert(_sortMode != SortMode::Date);
|
||||
if (_sortMode == SortMode::Name) {
|
||||
adjustByName(peer, oldNames, oldChars);
|
||||
adjustByName(peer, oldChars);
|
||||
} else {
|
||||
adjustNames(Dialogs::Mode::All, peer, oldNames, oldChars);
|
||||
adjustNames(Dialogs::Mode::All, peer, oldChars);
|
||||
}
|
||||
}
|
||||
|
||||
void IndexedList::peerNameChanged(Mode list, PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars) {
|
||||
void IndexedList::peerNameChanged(Mode list, not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars) {
|
||||
Assert(_sortMode == SortMode::Date);
|
||||
adjustNames(list, peer, oldNames, oldChars);
|
||||
adjustNames(list, peer, oldChars);
|
||||
}
|
||||
|
||||
void IndexedList::adjustByName(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars) {
|
||||
void IndexedList::adjustByName(not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars) {
|
||||
Row *mainRow = _list.adjustByName(peer);
|
||||
if (!mainRow) return;
|
||||
|
||||
History *history = mainRow->history();
|
||||
|
||||
PeerData::NameFirstChars toRemove = oldChars, toAdd;
|
||||
for_const (auto ch, peer->chars) {
|
||||
for (auto ch : peer->nameFirstChars()) {
|
||||
auto j = toRemove.find(ch);
|
||||
if (j == toRemove.cend()) {
|
||||
toAdd.insert(ch);
|
||||
} else {
|
||||
toRemove.erase(j);
|
||||
if (auto list = _index.value(ch)) {
|
||||
list->adjustByName(peer);
|
||||
if (auto it = _index.find(ch); it != _index.cend()) {
|
||||
it->second->adjustByName(peer);
|
||||
}
|
||||
}
|
||||
}
|
||||
for_const (auto ch, toRemove) {
|
||||
if (auto list = _index.value(ch)) {
|
||||
list->del(peer->id, mainRow);
|
||||
for (auto ch : toRemove) {
|
||||
if (auto it = _index.find(ch); it != _index.cend()) {
|
||||
it->second->del(peer->id, mainRow);
|
||||
}
|
||||
}
|
||||
if (!toAdd.isEmpty()) {
|
||||
for_const (auto ch, toAdd) {
|
||||
if (!toAdd.empty()) {
|
||||
for (auto ch : toAdd) {
|
||||
auto j = _index.find(ch);
|
||||
if (j == _index.cend()) {
|
||||
j = _index.insert(ch, new List(_sortMode));
|
||||
j = _index.emplace(
|
||||
ch,
|
||||
std::make_unique<List>(_sortMode)).first;
|
||||
}
|
||||
j.value()->addByName(history);
|
||||
j->second->addByName(history);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IndexedList::adjustNames(Mode list, PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars) {
|
||||
void IndexedList::adjustNames(Mode list, not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars) {
|
||||
auto mainRow = _list.getRow(peer->id);
|
||||
if (!mainRow) return;
|
||||
|
||||
History *history = mainRow->history();
|
||||
auto history = mainRow->history();
|
||||
|
||||
PeerData::NameFirstChars toRemove = oldChars, toAdd;
|
||||
for_const (auto ch, peer->chars) {
|
||||
for (auto ch : peer->nameFirstChars()) {
|
||||
auto j = toRemove.find(ch);
|
||||
if (j == toRemove.cend()) {
|
||||
toAdd.insert(ch);
|
||||
@@ -162,40 +169,40 @@ void IndexedList::adjustNames(Mode list, PeerData *peer, const PeerData::Names &
|
||||
toRemove.erase(j);
|
||||
}
|
||||
}
|
||||
for_const (auto ch, toRemove) {
|
||||
for (auto ch : toRemove) {
|
||||
if (_sortMode == SortMode::Date) {
|
||||
history->removeChatListEntryByLetter(list, ch);
|
||||
}
|
||||
if (auto list = _index.value(ch)) {
|
||||
list->del(peer->id, mainRow);
|
||||
if (auto it = _index.find(ch); it != _index.cend()) {
|
||||
it->second->del(peer->id, mainRow);
|
||||
}
|
||||
}
|
||||
for_const (auto ch, toAdd) {
|
||||
for (auto ch : toAdd) {
|
||||
auto j = _index.find(ch);
|
||||
if (j == _index.cend()) {
|
||||
j = _index.insert(ch, new List(_sortMode));
|
||||
j = _index.emplace(
|
||||
ch,
|
||||
std::make_unique<List>(_sortMode)).first;
|
||||
}
|
||||
Row *row = j.value()->addToEnd(history);
|
||||
auto row = j->second->addToEnd(history);
|
||||
if (_sortMode == SortMode::Date) {
|
||||
history->addChatListEntryByLetter(list, ch, row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IndexedList::del(const PeerData *peer, Row *replacedBy) {
|
||||
void IndexedList::del(not_null<const PeerData*> peer, Row *replacedBy) {
|
||||
if (_list.del(peer->id, replacedBy)) {
|
||||
for_const (auto ch, peer->chars) {
|
||||
if (auto list = _index.value(ch)) {
|
||||
list->del(peer->id, replacedBy);
|
||||
for (auto ch : peer->nameFirstChars()) {
|
||||
if (auto it = _index.find(ch); it != _index.cend()) {
|
||||
it->second->del(peer->id, replacedBy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IndexedList::clear() {
|
||||
for_const (auto &list, _index) {
|
||||
delete list;
|
||||
}
|
||||
_index.clear();
|
||||
}
|
||||
|
||||
IndexedList::~IndexedList() {
|
||||
|
@@ -34,26 +34,28 @@ public:
|
||||
RowsByLetter addToEnd(History *history);
|
||||
Row *addByName(History *history);
|
||||
void adjustByPos(const RowsByLetter &links);
|
||||
void moveToTop(PeerData *peer);
|
||||
void moveToTop(not_null<PeerData*> peer);
|
||||
|
||||
// row must belong to this indexed list all().
|
||||
void movePinned(Row *row, int deltaSign);
|
||||
|
||||
// For sortMode != SortMode::Date
|
||||
void peerNameChanged(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars);
|
||||
void peerNameChanged(not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars);
|
||||
|
||||
//For sortMode == SortMode::Date
|
||||
void peerNameChanged(Mode list, PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars);
|
||||
void peerNameChanged(Mode list, not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars);
|
||||
|
||||
void del(const PeerData *peer, Row *replacedBy = nullptr);
|
||||
void del(not_null<const PeerData*> peer, Row *replacedBy = nullptr);
|
||||
void clear();
|
||||
|
||||
const List &all() const {
|
||||
return _list;
|
||||
}
|
||||
const List *filtered(QChar ch) const {
|
||||
static StaticNeverFreedPointer<List> empty(new List(SortMode::Add));
|
||||
return _index.value(ch, empty.data());
|
||||
if (auto it = _index.find(ch); it != _index.cend()) {
|
||||
return it->second.get();
|
||||
}
|
||||
return &_empty;
|
||||
}
|
||||
|
||||
~IndexedList();
|
||||
@@ -81,13 +83,12 @@ public:
|
||||
iterator find(int y, int h) { return all().find(y, h); }
|
||||
|
||||
private:
|
||||
void adjustByName(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars);
|
||||
void adjustNames(Mode list, PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars);
|
||||
void adjustByName(not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars);
|
||||
void adjustNames(Mode list, not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars);
|
||||
|
||||
SortMode _sortMode;
|
||||
List _list;
|
||||
using Index = QMap<QChar, List*>;
|
||||
Index _index;
|
||||
List _list, _empty;
|
||||
base::flat_map<QChar, std::unique_ptr<List>> _index;
|
||||
|
||||
};
|
||||
|
||||
|
@@ -122,7 +122,7 @@ DialogsInner::DialogsInner(QWidget *parent, not_null<Window::Controller*> contro
|
||||
stopReorderPinned();
|
||||
}
|
||||
if (update.flags & UpdateFlag::NameChanged) {
|
||||
handlePeerNameChange(update.peer, update.oldNames, update.oldNameFirstChars);
|
||||
handlePeerNameChange(update.peer, update.oldNameFirstChars);
|
||||
}
|
||||
if (update.flags & UpdateFlag::PhotoChanged) {
|
||||
this->update();
|
||||
@@ -1271,13 +1271,13 @@ void DialogsInner::onParentGeometryChanged() {
|
||||
}
|
||||
}
|
||||
|
||||
void DialogsInner::handlePeerNameChange(not_null<PeerData*> peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars) {
|
||||
_dialogs->peerNameChanged(Dialogs::Mode::All, peer, oldNames, oldChars);
|
||||
void DialogsInner::handlePeerNameChange(not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars) {
|
||||
_dialogs->peerNameChanged(Dialogs::Mode::All, peer, oldChars);
|
||||
if (_dialogsImportant) {
|
||||
_dialogsImportant->peerNameChanged(Dialogs::Mode::Important, peer, oldNames, oldChars);
|
||||
_dialogsImportant->peerNameChanged(Dialogs::Mode::Important, peer, oldChars);
|
||||
}
|
||||
_contactsNoDialogs->peerNameChanged(peer, oldNames, oldChars);
|
||||
_contacts->peerNameChanged(peer, oldNames, oldChars);
|
||||
_contactsNoDialogs->peerNameChanged(peer, oldChars);
|
||||
_contacts->peerNameChanged(peer, oldChars);
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -1323,12 +1323,12 @@ void DialogsInner::onFilterUpdate(QString newFilter, bool force) {
|
||||
_filterResults.reserve((toFilter ? toFilter->size() : 0) + (toFilterContacts ? toFilterContacts->size() : 0));
|
||||
if (toFilter) {
|
||||
for_const (auto row, *toFilter) {
|
||||
const PeerData::Names &names(row->history()->peer->names);
|
||||
PeerData::Names::const_iterator nb = names.cbegin(), ne = names.cend(), ni;
|
||||
const auto &nameWords = row->history()->peer->nameWords();
|
||||
auto nb = nameWords.cbegin(), ne = nameWords.cend(), ni = nb;
|
||||
for (fi = fb; fi != fe; ++fi) {
|
||||
QString filterName(*fi);
|
||||
auto filterWord = *fi;
|
||||
for (ni = nb; ni != ne; ++ni) {
|
||||
if (ni->startsWith(*fi)) {
|
||||
if (ni->startsWith(filterWord)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1343,12 +1343,12 @@ void DialogsInner::onFilterUpdate(QString newFilter, bool force) {
|
||||
}
|
||||
if (toFilterContacts) {
|
||||
for_const (auto row, *toFilterContacts) {
|
||||
const PeerData::Names &names(row->history()->peer->names);
|
||||
PeerData::Names::const_iterator nb = names.cbegin(), ne = names.cend(), ni;
|
||||
const auto &nameWords = row->history()->peer->nameWords();
|
||||
auto nb = nameWords.cbegin(), ne = nameWords.cend(), ni = nb;
|
||||
for (fi = fb; fi != fe; ++fi) {
|
||||
QString filterName(*fi);
|
||||
auto filterWord = *fi;
|
||||
for (ni = nb; ni != ne; ++ni) {
|
||||
if (ni->startsWith(*fi)) {
|
||||
if (ni->startsWith(filterWord)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -174,7 +174,7 @@ private:
|
||||
bool isSelected() const {
|
||||
return _importantSwitchSelected || _selected || (_hashtagSelected >= 0) || (_filteredSelected >= 0) || (_peerSearchSelected >= 0) || (_searchedSelected >= 0);
|
||||
}
|
||||
void handlePeerNameChange(not_null<PeerData*> peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars);
|
||||
void handlePeerNameChange(not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars);
|
||||
|
||||
void itemRemoved(not_null<const HistoryItem*> item);
|
||||
enum class UpdateRowSection {
|
||||
|
Reference in New Issue
Block a user