Prepare dialogs to hold a history or a feed.

This commit is contained in:
John Preston 2018-01-04 20:15:04 +03:00
parent 6a9556d42c
commit a2891807f8
24 changed files with 727 additions and 419 deletions

View File

@ -441,7 +441,7 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
h->clear(true); h->clear(true);
} }
if (hto->inChatList(Dialogs::Mode::All) && h->inChatList(Dialogs::Mode::All)) { if (hto->inChatList(Dialogs::Mode::All) && h->inChatList(Dialogs::Mode::All)) {
App::removeDialog(h); App::main()->removeDialog(h);
} }
} }
} }

View File

@ -482,7 +482,7 @@ namespace {
h->clear(true); h->clear(true);
} }
if (hto->inChatList(Dialogs::Mode::All) && h->inChatList(Dialogs::Mode::All)) { if (hto->inChatList(Dialogs::Mode::All) && h->inChatList(Dialogs::Mode::All)) {
App::removeDialog(h); App::main()->removeDialog(h);
} }
} }
} }
@ -1047,7 +1047,9 @@ namespace {
if (auto history = App::historyLoaded(peer)) { if (auto history = App::historyLoaded(peer)) {
history->outboxRead(upTo); history->outboxRead(upTo);
if (history->lastMsg && history->lastMsg->out() && history->lastMsg->id <= upTo) { if (history->lastMsg && history->lastMsg->out() && history->lastMsg->id <= upTo) {
if (App::main()) App::main()->dlgUpdated(history->peer, history->lastMsg->id); if (App::main()) {
App::main()->dlgUpdated(history, history->lastMsg->id);
}
} }
history->updateChatListEntry(); history->updateChatListEntry();
@ -1801,7 +1803,7 @@ namespace {
return ::histories.findOrInsert(peer); return ::histories.findOrInsert(peer);
} }
History *historyFromDialog(const PeerId &peer, int32 unreadCnt, int32 maxInboxRead, int32 maxOutboxRead) { not_null<History*> historyFromDialog(const PeerId &peer, int32 unreadCnt, int32 maxInboxRead, int32 maxOutboxRead) {
return ::histories.findOrInsert(peer, unreadCnt, maxInboxRead, maxOutboxRead); return ::histories.findOrInsert(peer, unreadCnt, maxInboxRead, maxOutboxRead);
} }

View File

@ -173,7 +173,7 @@ namespace App {
Histories &histories(); Histories &histories();
not_null<History*> history(const PeerId &peer); not_null<History*> history(const PeerId &peer);
History *historyFromDialog(const PeerId &peer, int32 unreadCnt, int32 maxInboxRead, int32 maxOutboxRead); not_null<History*> historyFromDialog(const PeerId &peer, int32 unreadCnt, int32 maxInboxRead, int32 maxOutboxRead);
History *historyLoaded(const PeerId &peer); History *historyLoaded(const PeerId &peer);
HistoryItem *histItemById(ChannelId channelId, MsgId itemId); HistoryItem *histItemById(ChannelId channelId, MsgId itemId);
inline not_null<History*> history(const PeerData *peer) { inline not_null<History*> history(const PeerData *peer) {

View File

@ -238,6 +238,7 @@ void ChatsListBoxController::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 (appendRow(row->history())) { if (appendRow(row->history())) {
++count; ++count;
} }
@ -322,6 +323,7 @@ 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
auto history = row->history(); auto history = row->history();
if (auto user = history->peer->asUser()) { if (auto user = history->peer->asUser()) {
if (appendRow(user)) { if (appendRow(user)) {

View File

@ -280,7 +280,7 @@ ShareBox::Inner::Inner(QWidget *parent, ShareBox::FilterCallback &&filterCallbac
} }
} }
for (const auto row : dialogs->all()) { for (const auto row : dialogs->all()) {
// #TODO dialogs // #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);
@ -349,7 +349,9 @@ void ShareBox::Inner::activateSkipPage(int pageHeight, int direction) {
void ShareBox::Inner::notifyPeerUpdated(const Notify::PeerUpdate &update) { void ShareBox::Inner::notifyPeerUpdated(const Notify::PeerUpdate &update) {
if (update.flags & Notify::PeerUpdate::Flag::NameChanged) { if (update.flags & Notify::PeerUpdate::Flag::NameChanged) {
_chatsIndexed->peerNameChanged(update.peer, update.oldNameFirstChars); _chatsIndexed->peerNameChanged(
update.peer,
update.oldNameFirstChars);
} }
updateChat(update.peer); updateChat(update.peer);
@ -405,6 +407,7 @@ 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 (row->history()->peer == peer) { if (row->history()->peer == peer) {
return index; return index;
} }
@ -412,6 +415,7 @@ int ShareBox::Inner::chatIndex(not_null<PeerData*> peer) const {
} }
} else { } else {
for_const (auto row, _filtered) { for_const (auto row, _filtered) {
// #TODO feeds list
if (row->history()->peer == peer) { if (row->history()->peer == peer) {
return index; return index;
} }
@ -450,6 +454,7 @@ void ShareBox::Inner::loadProfilePhotos(int yFrom) {
if (((*i)->pos() * _rowHeight) >= yTo) { if (((*i)->pos() * _rowHeight) >= yTo) {
break; break;
} }
// #TODO feeds list
(*i)->history()->peer->loadUserpic(); (*i)->history()->peer->loadUserpic();
} }
} }
@ -461,6 +466,7 @@ 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]->history()->peer->loadUserpic(); _filtered[from]->history()->peer->loadUserpic();
} }
} }
@ -470,6 +476,7 @@ void ShareBox::Inner::loadProfilePhotos(int yFrom) {
ShareBox::Inner::Chat *ShareBox::Inner::getChat(Dialogs::Row *row) { ShareBox::Inner::Chat *ShareBox::Inner::getChat(Dialogs::Row *row) {
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()) {
@ -640,17 +647,17 @@ void ShareBox::Inner::changeCheckState(Chat *chat) {
if (!chat) return; if (!chat) return;
if (!_filter.isEmpty()) { if (!_filter.isEmpty()) {
auto row = _chatsIndexed->getRow(chat->peer->id); const auto history = App::history(chat->peer);
auto row = _chatsIndexed->getRow(history);
if (!row) { if (!row) {
const auto rowsByLetter = _chatsIndexed->addToEnd( const auto rowsByLetter = _chatsIndexed->addToEnd(history);
App::history(chat->peer));
const auto it = rowsByLetter.find(0); const auto it = rowsByLetter.find(0);
Assert(it != rowsByLetter.cend()); Assert(it != rowsByLetter.cend());
row = it->second; row = it->second;
} }
chat = getChat(row); chat = getChat(row);
if (!chat->checkbox.checked()) { if (!chat->checkbox.checked()) {
_chatsIndexed->moveToTop(chat->peer); _chatsIndexed->moveToTop(history);
} }
} }
@ -725,6 +732,7 @@ 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->history()->peer->nameWords(); 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) {
@ -768,15 +776,16 @@ void ShareBox::Inner::peopleReceived(const QString &query, const QVector<MTPPeer
if (_byUsernameFiltered[j]->id == peerId) break; if (_byUsernameFiltered[j]->id == peerId) break;
} }
if (j == already) { if (j == already) {
auto *peer = App::peer(peerId); const auto peer = App::peer(peerId);
if (!peer || !_filterCallback(peer)) continue; const auto history = App::historyLoaded(peer);
if (!peer || !_filterCallback(peer)) {
auto chat = new Chat(peer, [this, peer] { repaintChat(peer); }); continue;
updateChatName(chat, peer); } else if (history && _chatsIndexed->getRow(history)) {
if (auto row = _chatsIndexed->getRow(peer->id)) {
continue; continue;
} }
auto chat = new Chat(peer, [this, peer] { repaintChat(peer); });
updateChatName(chat, peer);
_byUsernameFiltered.push_back(peer); _byUsernameFiltered.push_back(peer);
d_byUsernameFiltered.push_back(chat); d_byUsernameFiltered.push_back(chat);
} }

View File

@ -15,37 +15,37 @@ IndexedList::IndexedList(SortMode sortMode)
, _empty(sortMode) { , _empty(sortMode) {
} }
RowsByLetter IndexedList::addToEnd(not_null<History*> history) { RowsByLetter IndexedList::addToEnd(Key key) {
RowsByLetter result; RowsByLetter result;
if (!_list.contains(history->peer->id)) { if (!_list.contains(key)) {
result.emplace(0, _list.addToEnd(history)); result.emplace(0, _list.addToEnd(key));
for (auto ch : history->peer->nameFirstChars()) { for (auto ch : key.nameFirstChars()) {
auto j = _index.find(ch); auto j = _index.find(ch);
if (j == _index.cend()) { if (j == _index.cend()) {
j = _index.emplace( j = _index.emplace(
ch, ch,
std::make_unique<List>(_sortMode)).first; std::make_unique<List>(_sortMode)).first;
} }
result.emplace(ch, j->second->addToEnd(history)); result.emplace(ch, j->second->addToEnd(key));
} }
} }
return result; return result;
} }
Row *IndexedList::addByName(not_null<History*> history) { Row *IndexedList::addByName(Key key) {
if (const auto row = _list.getRow(history->peer->id)) { if (const auto row = _list.getRow(key)) {
return row; return row;
} }
Row *result = _list.addByName(history); Row *result = _list.addByName(key);
for (auto ch : history->peer->nameFirstChars()) { for (auto ch : key.nameFirstChars()) {
auto j = _index.find(ch); auto j = _index.find(ch);
if (j == _index.cend()) { if (j == _index.cend()) {
j = _index.emplace( j = _index.emplace(
ch, ch,
std::make_unique<List>(_sortMode)).first; std::make_unique<List>(_sortMode)).first;
} }
j->second->addByName(history); j->second->addByName(key);
} }
return result; return result;
} }
@ -62,11 +62,11 @@ void IndexedList::adjustByPos(const RowsByLetter &links) {
} }
} }
void IndexedList::moveToTop(not_null<PeerData*> peer) { void IndexedList::moveToTop(Key key) {
if (_list.moveToTop(peer->id)) { if (_list.moveToTop(key)) {
for (auto ch : peer->nameFirstChars()) { for (auto ch : key.nameFirstChars()) {
if (auto it = _index.find(ch); it != _index.cend()) { if (auto it = _index.find(ch); it != _index.cend()) {
it->second->moveToTop(peer->id); it->second->moveToTop(key);
} }
} }
} }
@ -81,6 +81,7 @@ void IndexedList::movePinned(Row *row, int deltaSign) {
Assert(swapPinnedIndexWith != cbegin()); Assert(swapPinnedIndexWith != cbegin());
--swapPinnedIndexWith; --swapPinnedIndexWith;
} }
// #TODO feeds pinned
auto history1 = row->history(); auto history1 = row->history();
auto history2 = (*swapPinnedIndexWith)->history(); auto history2 = (*swapPinnedIndexWith)->history();
Assert(history1->isPinnedDialog()); Assert(history1->isPinnedDialog());
@ -91,44 +92,52 @@ void IndexedList::movePinned(Row *row, int deltaSign) {
history2->setPinnedIndex(index1); history2->setPinnedIndex(index1);
} }
void IndexedList::peerNameChanged(not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars) { void IndexedList::peerNameChanged(
Assert(_sortMode != SortMode::Date); not_null<PeerData*> peer,
const PeerData::NameFirstChars &oldChars) {
Expects(_sortMode != SortMode::Date);
if (const auto history = App::historyLoaded(peer)) {
if (_sortMode == SortMode::Name) { if (_sortMode == SortMode::Name) {
adjustByName(peer, oldChars); adjustByName(history, oldChars);
} else { } else {
adjustNames(Dialogs::Mode::All, peer, oldChars); adjustNames(Dialogs::Mode::All, history, oldChars);
}
} }
} }
void IndexedList::peerNameChanged(Mode list, not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars) { void IndexedList::peerNameChanged(
Assert(_sortMode == SortMode::Date); Mode list,
adjustNames(list, peer, oldChars); not_null<PeerData*> peer,
const PeerData::NameFirstChars &oldChars) {
Expects(_sortMode == SortMode::Date);
if (const auto history = App::historyLoaded(peer)) {
adjustNames(list, history, oldChars);
}
} }
void IndexedList::adjustByName( void IndexedList::adjustByName(
not_null<PeerData*> peer, Key key,
const PeerData::NameFirstChars &oldChars) { const PeerData::NameFirstChars &oldChars) {
const auto mainRow = _list.adjustByName(peer); const auto mainRow = _list.adjustByName(key);
if (!mainRow) return; if (!mainRow) return;
// #TODO dialogs
const auto history = mainRow->history();
PeerData::NameFirstChars toRemove = oldChars, toAdd; PeerData::NameFirstChars toRemove = oldChars, toAdd;
for (auto ch : peer->nameFirstChars()) { for (auto ch : key.nameFirstChars()) {
auto j = toRemove.find(ch); auto j = toRemove.find(ch);
if (j == toRemove.cend()) { if (j == toRemove.cend()) {
toAdd.insert(ch); toAdd.insert(ch);
} else { } else {
toRemove.erase(j); toRemove.erase(j);
if (auto it = _index.find(ch); it != _index.cend()) { if (auto it = _index.find(ch); it != _index.cend()) {
it->second->adjustByName(peer); it->second->adjustByName(key);
} }
} }
} }
for (auto ch : toRemove) { for (auto ch : toRemove) {
if (auto it = _index.find(ch); it != _index.cend()) { if (auto it = _index.find(ch); it != _index.cend()) {
it->second->del(peer->id, mainRow); it->second->del(key, mainRow);
} }
} }
if (!toAdd.empty()) { if (!toAdd.empty()) {
@ -139,20 +148,23 @@ void IndexedList::adjustByName(
ch, ch,
std::make_unique<List>(_sortMode)).first; std::make_unique<List>(_sortMode)).first;
} }
j->second->addByName(history); j->second->addByName(key);
} }
} }
} }
void IndexedList::adjustNames(Mode list, not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars) { void IndexedList::adjustNames(
auto mainRow = _list.getRow(peer->id); Mode list,
Key key,
const PeerData::NameFirstChars &oldChars) {
auto mainRow = _list.getRow(key);
if (!mainRow) return; if (!mainRow) return;
// #TODO dialogs // #TODO feeds dialogs
auto history = mainRow->history(); auto history = mainRow->history();
PeerData::NameFirstChars toRemove = oldChars, toAdd; PeerData::NameFirstChars toRemove = oldChars, toAdd;
for (auto ch : peer->nameFirstChars()) { for (auto ch : key.nameFirstChars()) {
auto j = toRemove.find(ch); auto j = toRemove.find(ch);
if (j == toRemove.cend()) { if (j == toRemove.cend()) {
toAdd.insert(ch); toAdd.insert(ch);
@ -165,7 +177,7 @@ void IndexedList::adjustNames(Mode list, not_null<PeerData*> peer, const PeerDat
history->removeChatListEntryByLetter(list, ch); history->removeChatListEntryByLetter(list, ch);
} }
if (auto it = _index.find(ch); it != _index.cend()) { if (auto it = _index.find(ch); it != _index.cend()) {
it->second->del(peer->id, mainRow); it->second->del(key, mainRow);
} }
} }
for (auto ch : toAdd) { for (auto ch : toAdd) {
@ -175,18 +187,18 @@ void IndexedList::adjustNames(Mode list, not_null<PeerData*> peer, const PeerDat
ch, ch,
std::make_unique<List>(_sortMode)).first; std::make_unique<List>(_sortMode)).first;
} }
auto row = j->second->addToEnd(history); auto row = j->second->addToEnd(key);
if (_sortMode == SortMode::Date) { if (_sortMode == SortMode::Date) {
history->addChatListEntryByLetter(list, ch, row); history->addChatListEntryByLetter(list, ch, row);
} }
} }
} }
void IndexedList::del(not_null<const PeerData*> peer, Row *replacedBy) { void IndexedList::del(Key key, Row *replacedBy) {
if (_list.del(peer->id, replacedBy)) { if (_list.del(key, replacedBy)) {
for (auto ch : peer->nameFirstChars()) { for (auto ch : key.nameFirstChars()) {
if (auto it = _index.find(ch); it != _index.cend()) { if (auto it = _index.find(ch); it != _index.cend()) {
it->second->del(peer->id, replacedBy); it->second->del(key, replacedBy);
} }
} }
} }

View File

@ -18,21 +18,26 @@ class IndexedList {
public: public:
IndexedList(SortMode sortMode); IndexedList(SortMode sortMode);
RowsByLetter addToEnd(not_null<History*> history); RowsByLetter addToEnd(Key key);
Row *addByName(not_null<History*> history); Row *addByName(Key key);
void adjustByPos(const RowsByLetter &links); void adjustByPos(const RowsByLetter &links);
void moveToTop(not_null<PeerData*> peer); void moveToTop(Key key);
// row must belong to this indexed list all(). // row must belong to this indexed list all().
void movePinned(Row *row, int deltaSign); void movePinned(Row *row, int deltaSign);
// For sortMode != SortMode::Date // For sortMode != SortMode::Date
void peerNameChanged(not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars); void peerNameChanged(
not_null<PeerData*> peer,
const PeerData::NameFirstChars &oldChars);
//For sortMode == SortMode::Date //For sortMode == SortMode::Date
void peerNameChanged(Mode list, not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars); void peerNameChanged(
Mode list,
not_null<PeerData*> peer,
const PeerData::NameFirstChars &oldChars);
void del(not_null<const PeerData*> peer, Row *replacedBy = nullptr); void del(Key key, Row *replacedBy = nullptr);
void clear(); void clear();
const List &all() const { const List &all() const {
@ -50,8 +55,8 @@ public:
// Part of List interface is duplicated here for all() list. // Part of List interface is duplicated here for all() list.
int size() const { return all().size(); } int size() const { return all().size(); }
bool isEmpty() const { return all().isEmpty(); } bool isEmpty() const { return all().isEmpty(); }
bool contains(PeerId peerId) const { return all().contains(peerId); } bool contains(Key key) const { return all().contains(key); }
Row *getRow(PeerId peerId) const { return all().getRow(peerId); } Row *getRow(Key key) const { return all().getRow(key); }
Row *rowAtY(int32 y, int32 h) const { return all().rowAtY(y, h); } Row *rowAtY(int32 y, int32 h) const { return all().rowAtY(y, h); }
using iterator = List::iterator; using iterator = List::iterator;
@ -70,8 +75,13 @@ public:
iterator find(int y, int h) { return all().find(y, h); } iterator find(int y, int h) { return all().find(y, h); }
private: private:
void adjustByName(not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars); void adjustByName(
void adjustNames(Mode list, not_null<PeerData*> peer, const PeerData::NameFirstChars &oldChars); Key key,
const PeerData::NameFirstChars &oldChars);
void adjustNames(
Mode list,
Key key,
const PeerData::NameFirstChars &oldChars);
SortMode _sortMode; SortMode _sortMode;
List _list, _empty; List _list, _empty;

View File

@ -53,9 +53,9 @@ struct DialogsInner::HashtagResult {
}; };
struct DialogsInner::PeerSearchResult { struct DialogsInner::PeerSearchResult {
PeerSearchResult(PeerData *peer) : peer(peer) { PeerSearchResult(not_null<PeerData*> peer) : peer(peer) {
} }
PeerData *peer; not_null<PeerData*> peer;
Dialogs::RippleRow row; Dialogs::RippleRow row;
}; };
@ -99,7 +99,7 @@ DialogsInner::DialogsInner(QWidget *parent, not_null<Window::Controller*> contro
}, lifetime()); }, lifetime());
subscribe(App::histories().sendActionAnimationUpdated(), [this](const Histories::SendActionAnimationUpdate &update) { subscribe(App::histories().sendActionAnimationUpdated(), [this](const Histories::SendActionAnimationUpdate &update) {
auto updateRect = Dialogs::Layout::RowPainter::sendActionAnimationRect(update.width, update.height, getFullWidth(), update.textUpdated); auto updateRect = Dialogs::Layout::RowPainter::sendActionAnimationRect(update.width, update.height, getFullWidth(), update.textUpdated);
updateDialogRow(update.history->peer, MsgId(0), updateRect, UpdateRowSection::Default | UpdateRowSection::Filtered); updateDialogRow(update.history, MsgId(0), updateRect, UpdateRowSection::Default | UpdateRowSection::Filtered);
}); });
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) { subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) {
@ -187,7 +187,16 @@ void DialogsInner::paintRegion(Painter &p, const QRegion &region, bool paintingO
} }
auto otherStart = rows->size() * st::dialogsRowHeight; auto otherStart = rows->size() * st::dialogsRowHeight;
auto active = App::main()->activePeer(); auto active = App::main()->activePeer();
auto selected = _menuPeer ? _menuPeer : (isPressed() ? (_pressed ? _pressed->history()->peer : nullptr) : (_selected ? _selected->history()->peer : nullptr)); // #TODO feeds dialogs
auto selected = _menuPeer
? _menuPeer
: (isPressed()
? (_pressed
? _pressed->history()->peer
: nullptr)
: (_selected
? _selected->history()->peer
: nullptr));
if (otherStart) { if (otherStart) {
auto reorderingPinned = (_aboveIndex >= 0 && !_pinnedRows.empty()); auto reorderingPinned = (_aboveIndex >= 0 && !_pinnedRows.empty());
auto &list = rows->all(); auto &list = rows->all();
@ -297,8 +306,11 @@ void DialogsInner::paintRegion(Painter &p, const QRegion &region, bool paintingO
auto activeMsgId = App::main()->activeMsgId(); auto activeMsgId = App::main()->activeMsgId();
for (; from < to; ++from) { for (; from < to; ++from) {
auto row = _filterResults[from]; auto row = _filterResults[from];
// #TODO feeds dialogs
auto peer = row->history()->peer; auto peer = row->history()->peer;
auto active = ((peer == activePeer) || (peer->migrateTo() && peer->migrateTo() == activePeer)) && !activeMsgId; auto active = !activeMsgId && ((peer == activePeer)
|| (peer->migrateTo()
&& peer->migrateTo() == activePeer));
auto selected = _menuPeer ? (peer == _menuPeer) : (from == (isPressed() ? _filteredPressed : _filteredSelected)); auto selected = _menuPeer ? (peer == _menuPeer) : (from == (isPressed() ? _filteredPressed : _filteredSelected));
Dialogs::Layout::RowPainter::paint(p, _filterResults[from], fullWidth, active, selected, paintingOther, ms); Dialogs::Layout::RowPainter::paint(p, _filterResults[from], fullWidth, active, selected, paintingOther, ms);
p.translate(0, st::dialogsRowHeight); p.translate(0, st::dialogsRowHeight);
@ -378,20 +390,44 @@ void DialogsInner::paintRegion(Painter &p, const QRegion &region, bool paintingO
} }
} }
void DialogsInner::paintDialog(Painter &p, Dialogs::Row *row, int fullWidth, PeerData *active, PeerData *selected, bool onlyBackground, TimeMs ms) { void DialogsInner::paintDialog(
Painter &p,
not_null<Dialogs::Row*> row,
int fullWidth,
PeerData *active,
PeerData *selected,
bool onlyBackground,
TimeMs ms) {
auto pos = row->pos(); auto pos = row->pos();
auto xadd = 0, yadd = 0; auto xadd = 0, yadd = 0;
if (pos < _pinnedRows.size()) { if (pos < _pinnedRows.size()) {
yadd = qRound(_pinnedRows[pos].yadd.current()); yadd = qRound(_pinnedRows[pos].yadd.current());
} }
if (xadd || yadd) p.translate(xadd, yadd); if (xadd || yadd) p.translate(xadd, yadd);
auto isActive = (row->history()->peer == active) || (row->history()->peer->migrateTo() && row->history()->peer->migrateTo() == active); // #TODO feeds dialogs
auto isActive = (row->history()->peer == active)
|| (row->history()->peer->migrateTo()
&& row->history()->peer->migrateTo() == active);
auto isSelected = (row->history()->peer == selected); auto isSelected = (row->history()->peer == selected);
Dialogs::Layout::RowPainter::paint(p, row, fullWidth, isActive, isSelected, onlyBackground, ms); Dialogs::Layout::RowPainter::paint(
p,
row,
fullWidth,
isActive,
isSelected,
onlyBackground,
ms);
if (xadd || yadd) p.translate(-xadd, -yadd); if (xadd || yadd) p.translate(-xadd, -yadd);
} }
void DialogsInner::paintPeerSearchResult(Painter &p, const PeerSearchResult *result, int fullWidth, bool active, bool selected, bool onlyBackground, TimeMs ms) const { void DialogsInner::paintPeerSearchResult(
Painter &p,
not_null<const PeerSearchResult*> result,
int fullWidth,
bool active,
bool selected,
bool onlyBackground,
TimeMs ms) const {
QRect fullRect(0, 0, fullWidth, st::dialogsRowHeight); QRect fullRect(0, 0, fullWidth, st::dialogsRowHeight);
p.fillRect(fullRect, active ? st::dialogsBgActive : (selected ? st::dialogsBgOver : st::dialogsBg)); p.fillRect(fullRect, active ? st::dialogsBgActive : (selected ? st::dialogsBgOver : st::dialogsBg));
if (!active) { if (!active) {
@ -443,7 +479,11 @@ void DialogsInner::paintPeerSearchResult(Painter &p, const PeerSearchResult *res
peer->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); peer->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
} }
void DialogsInner::paintSearchInPeer(Painter &p, int fullWidth, bool onlyBackground, TimeMs ms) const { void DialogsInner::paintSearchInPeer(
Painter &p,
int fullWidth,
bool onlyBackground,
TimeMs ms) const {
auto height = searchInPeerSkip(); auto height = searchInPeerSkip();
auto top = st::searchedBarHeight; auto top = st::searchedBarHeight;
@ -657,6 +697,7 @@ void DialogsInner::mousePressEvent(QMouseEvent *e) {
auto row = _pressed; auto row = _pressed;
row->addRipple(e->pos() - QPoint(0, dialogsOffset() + _pressed->pos() * st::dialogsRowHeight), QSize(getFullWidth(), st::dialogsRowHeight), [this, row] { row->addRipple(e->pos() - QPoint(0, dialogsOffset() + _pressed->pos() * st::dialogsRowHeight), QSize(getFullWidth(), st::dialogsRowHeight), [this, row] {
if (!_a_pinnedShifting.animating()) { if (!_a_pinnedShifting.animating()) {
// #TODO feeds dialogs
row->history()->updateChatListEntry(); row->history()->updateChatListEntry();
} }
}); });
@ -667,20 +708,19 @@ void DialogsInner::mousePressEvent(QMouseEvent *e) {
update(0, index * st::mentionHeight, getFullWidth(), st::mentionHeight); update(0, index * st::mentionHeight, getFullWidth(), st::mentionHeight);
}); });
} else if (_filteredPressed >= 0 && _filteredPressed < _filterResults.size()) { } else if (_filteredPressed >= 0 && _filteredPressed < _filterResults.size()) {
auto row = _filterResults[_filteredPressed]; const auto row = _filterResults[_filteredPressed];
row->addRipple(e->pos() - QPoint(0, filteredOffset() + _filteredPressed * st::dialogsRowHeight), QSize(getFullWidth(), st::dialogsRowHeight), [row] { const auto list = Global::DialogsMode();
if (auto main = App::main()) { row->addRipple(
main->dlgUpdated(row->history()->peer, 0); e->pos() - QPoint(0, filteredOffset() + _filteredPressed * st::dialogsRowHeight),
} QSize(getFullWidth(), st::dialogsRowHeight),
}); [=] { dlgUpdated(list, row); });
} else if (_peerSearchPressed >= 0 && _peerSearchPressed < _peerSearchResults.size()) { } else if (_peerSearchPressed >= 0 && _peerSearchPressed < _peerSearchResults.size()) {
auto &result = _peerSearchResults[_peerSearchPressed]; auto &result = _peerSearchResults[_peerSearchPressed];
auto row = &result->row; auto row = &result->row;
row->addRipple(e->pos() - QPoint(0, peerSearchOffset() + _peerSearchPressed * st::dialogsRowHeight), QSize(getFullWidth(), st::dialogsRowHeight), [peer = result->peer] { row->addRipple(
if (auto main = App::main()) { e->pos() - QPoint(0, peerSearchOffset() + _peerSearchPressed * st::dialogsRowHeight),
main->dlgUpdated(peer, 0); QSize(getFullWidth(), st::dialogsRowHeight),
} [this, peer = result->peer] { updateSearchResult(peer); });
});
} else if (_searchedPressed >= 0 && _searchedPressed < _searchResults.size()) { } else if (_searchedPressed >= 0 && _searchedPressed < _searchResults.size()) {
auto &row = _searchResults[_searchedPressed]; auto &row = _searchResults[_searchedPressed];
row->addRipple(e->pos() - QPoint(0, searchedOffset() + _searchedPressed * st::dialogsRowHeight), QSize(getFullWidth(), st::dialogsRowHeight), [this, index = _searchedPressed] { row->addRipple(e->pos() - QPoint(0, searchedOffset() + _searchedPressed * st::dialogsRowHeight), QSize(getFullWidth(), st::dialogsRowHeight), [this, index = _searchedPressed] {
@ -708,6 +748,7 @@ void DialogsInner::checkReorderPinnedStart(QPoint localPosition) {
int DialogsInner::shownPinnedCount() const { int DialogsInner::shownPinnedCount() const {
auto result = 0; auto result = 0;
for_const (auto row, *shownDialogs()) { for_const (auto row, *shownDialogs()) {
// #TODO feeds pinned
if (!row->history()->isPinnedDialog()) { if (!row->history()->isPinnedDialog()) {
break; break;
} }
@ -717,6 +758,7 @@ int DialogsInner::shownPinnedCount() const {
} }
int DialogsInner::countPinnedIndex(Dialogs::Row *ofRow) { int DialogsInner::countPinnedIndex(Dialogs::Row *ofRow) {
// #TODO feeds pinned
if (!ofRow || !ofRow->history()->isPinnedDialog()) { if (!ofRow || !ofRow->history()->isPinnedDialog()) {
return -1; return -1;
} }
@ -1032,7 +1074,7 @@ void DialogsInner::onDialogRowReplaced(Dialogs::Row *oldRow, Dialogs::Row *newRo
} }
} }
void DialogsInner::createDialog(History *history) { void DialogsInner::createDialog(not_null<History*> history) {
if (history->peer->loadedStatus != PeerData::LoadedStatus::FullLoaded) { if (history->peer->loadedStatus != PeerData::LoadedStatus::FullLoaded) {
LOG(("API Error: DialogsInner::createDialog() called for a non loaded peer!")); LOG(("API Error: DialogsInner::createDialog() called for a non loaded peer!"));
return; return;
@ -1041,7 +1083,7 @@ void DialogsInner::createDialog(History *history) {
bool creating = !history->inChatList(Dialogs::Mode::All); bool creating = !history->inChatList(Dialogs::Mode::All);
if (creating) { if (creating) {
auto mainRow = history->addToChatList(Dialogs::Mode::All, _dialogs.get()); auto mainRow = history->addToChatList(Dialogs::Mode::All, _dialogs.get());
_contactsNoDialogs->del(history->peer, mainRow); _contactsNoDialogs->del(history, mainRow);
} }
if (_dialogsImportant && !history->inChatList(Dialogs::Mode::Important) && !history->mute()) { if (_dialogsImportant && !history->inChatList(Dialogs::Mode::Important) && !history->mute()) {
if (Global::DialogsMode() == Dialogs::Mode::Important) { if (Global::DialogsMode() == Dialogs::Mode::Important) {
@ -1079,9 +1121,8 @@ void DialogsInner::createDialog(History *history) {
} }
} }
void DialogsInner::removeDialog(History *history) { void DialogsInner::removeDialog(not_null<History*> history) {
if (!history) return; // #TODO feeds dialogs
if (history->peer == _menuPeer && _menu) { if (history->peer == _menuPeer && _menu) {
InvokeQueued(this, [this] { _menu = nullptr; }); InvokeQueued(this, [this] { _menu = nullptr; });
} }
@ -1096,8 +1137,8 @@ void DialogsInner::removeDialog(History *history) {
history->removeFromChatList(Dialogs::Mode::Important, _dialogsImportant.get()); history->removeFromChatList(Dialogs::Mode::Important, _dialogsImportant.get());
} }
Auth().notifications().clearFromHistory(history); Auth().notifications().clearFromHistory(history);
if (_contacts->contains(history->peer->id)) { if (_contacts->contains(history)) {
if (!_contactsNoDialogs->contains(history->peer->id)) { if (!_contactsNoDialogs->contains(history)) {
_contactsNoDialogs->addByName(history); _contactsNoDialogs->addByName(history);
} }
} }
@ -1109,7 +1150,9 @@ void DialogsInner::removeDialog(History *history) {
refresh(); refresh();
} }
void DialogsInner::dlgUpdated(Dialogs::Mode list, Dialogs::Row *row) { void DialogsInner::dlgUpdated(
Dialogs::Mode list,
not_null<Dialogs::Row*> row) {
if (_state == DefaultState) { if (_state == DefaultState) {
if (Global::DialogsMode() == list) { if (Global::DialogsMode() == list) {
auto position = row->pos(); auto position = row->pos();
@ -1121,9 +1164,13 @@ void DialogsInner::dlgUpdated(Dialogs::Mode list, Dialogs::Row *row) {
} }
} else if (_state == FilteredState || _state == SearchedState) { } else if (_state == FilteredState || _state == SearchedState) {
if (list == Dialogs::Mode::All) { if (list == Dialogs::Mode::All) {
for (int32 i = 0, l = _filterResults.size(); i < l; ++i) { for (auto i = 0, l = _filterResults.size(); i != l; ++i) {
if (_filterResults.at(i)->history() == row->history()) { if (_filterResults[i]->key() == row->key()) {
update(0, filteredOffset() + i * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight); update(
0,
filteredOffset() + i * st::dialogsRowHeight,
getFullWidth(),
st::dialogsRowHeight);
break; break;
} }
} }
@ -1131,17 +1178,39 @@ void DialogsInner::dlgUpdated(Dialogs::Mode list, Dialogs::Row *row) {
} }
} }
void DialogsInner::dlgUpdated(PeerData *peer, MsgId msgId) { void DialogsInner::dlgUpdated(not_null<History*> history, MsgId msgId) {
updateDialogRow(peer, msgId, QRect(0, 0, getFullWidth(), st::dialogsRowHeight)); updateDialogRow(
history,
msgId,
QRect(0, 0, getFullWidth(), st::dialogsRowHeight));
} }
void DialogsInner::updateDialogRow(PeerData *peer, MsgId msgId, QRect updateRect, UpdateRowSections sections) { void DialogsInner::updateSearchResult(not_null<PeerData*> peer) {
if (_state == FilteredState || _state == SearchedState) {
if (!_peerSearchResults.empty()) {
auto index = 0, add = peerSearchOffset();
for_const (auto &result, _peerSearchResults) {
if (result->peer == peer) {
rtlupdate(0, add + index * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight);
break;
}
++index;
}
}
}
}
void DialogsInner::updateDialogRow(
not_null<History*> history,
MsgId msgId,
QRect updateRect,
UpdateRowSections sections) {
auto updateRow = [this, updateRect](int rowTop) { auto updateRow = [this, updateRect](int rowTop) {
rtlupdate(updateRect.x(), rowTop + updateRect.y(), updateRect.width(), updateRect.height()); rtlupdate(updateRect.x(), rowTop + updateRect.y(), updateRect.width(), updateRect.height());
}; };
if (_state == DefaultState) { if (_state == DefaultState) {
if (sections & UpdateRowSection::Default) { if (sections & UpdateRowSection::Default) {
if (auto row = shownDialogs()->getRow(peer->id)) { if (const auto row = shownDialogs()->getRow(history)) {
auto position = row->pos(); auto position = row->pos();
auto top = dialogsOffset(); auto top = dialogsOffset();
if (position >= 0 && position < _pinnedRows.size()) { if (position >= 0 && position < _pinnedRows.size()) {
@ -1154,7 +1223,7 @@ void DialogsInner::updateDialogRow(PeerData *peer, MsgId msgId, QRect updateRect
if ((sections & UpdateRowSection::Filtered) && !_filterResults.isEmpty()) { if ((sections & UpdateRowSection::Filtered) && !_filterResults.isEmpty()) {
auto index = 0, add = filteredOffset(); auto index = 0, add = filteredOffset();
for_const (auto row, _filterResults) { for_const (auto row, _filterResults) {
if (row->history()->peer == peer) { if (row->history() == history) {
updateRow(add + index * st::dialogsRowHeight); updateRow(add + index * st::dialogsRowHeight);
break; break;
} }
@ -1164,7 +1233,7 @@ void DialogsInner::updateDialogRow(PeerData *peer, MsgId msgId, QRect updateRect
if ((sections & UpdateRowSection::PeerSearch) && !_peerSearchResults.empty()) { if ((sections & UpdateRowSection::PeerSearch) && !_peerSearchResults.empty()) {
auto index = 0, add = peerSearchOffset(); auto index = 0, add = peerSearchOffset();
for_const (auto &result, _peerSearchResults) { for_const (auto &result, _peerSearchResults) {
if (result->peer == peer) { if (result->peer == history->peer) {
updateRow(add + index * st::dialogsRowHeight); updateRow(add + index * st::dialogsRowHeight);
break; break;
} }
@ -1175,7 +1244,7 @@ void DialogsInner::updateDialogRow(PeerData *peer, MsgId msgId, QRect updateRect
auto index = 0, add = searchedOffset(); auto index = 0, add = searchedOffset();
for_const (auto &result, _searchResults) { for_const (auto &result, _searchResults) {
auto item = result->item(); auto item = result->item();
if (item->history()->peer == peer && item->id == msgId) { if (item->history() == history && item->id == msgId) {
updateRow(add + index * st::dialogsRowHeight); updateRow(add + index * st::dialogsRowHeight);
break; break;
} }
@ -1191,6 +1260,7 @@ void DialogsInner::enterEventHook(QEvent *e) {
} }
void DialogsInner::updateSelectedRow(PeerData *peer) { void DialogsInner::updateSelectedRow(PeerData *peer) {
// #TODO feeds dialogs
if (_state == DefaultState) { if (_state == DefaultState) {
if (peer) { if (peer) {
if (auto h = App::historyLoaded(peer->id)) { if (auto h = App::historyLoaded(peer->id)) {
@ -1210,8 +1280,8 @@ void DialogsInner::updateSelectedRow(PeerData *peer) {
} }
} else if (_state == FilteredState || _state == SearchedState) { } else if (_state == FilteredState || _state == SearchedState) {
if (peer) { if (peer) {
for (int32 i = 0, l = _filterResults.size(); i != l; ++i) { for (auto i = 0, l = _filterResults.size(); i != l; ++i) {
if (_filterResults.at(i)->history()->peer == peer) { if (_filterResults[i]->history()->peer == peer) {
update(0, filteredOffset() + i * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight); update(0, filteredOffset() + i * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight);
break; break;
} }
@ -1257,6 +1327,7 @@ void DialogsInner::contextMenuEvent(QContextMenuEvent *e) {
updateSelected(); updateSelected();
} }
// #TODO feeds context menu
auto history = [&]() -> History* { auto history = [&]() -> History* {
if (_state == DefaultState) { if (_state == DefaultState) {
if (_selected) { if (_selected) {
@ -1362,6 +1433,7 @@ void DialogsInner::onFilterUpdate(QString newFilter, bool force) {
_filterResults.reserve((toFilter ? toFilter->size() : 0) + (toFilterContacts ? toFilterContacts->size() : 0)); _filterResults.reserve((toFilter ? toFilter->size() : 0) + (toFilterContacts ? toFilterContacts->size() : 0));
if (toFilter) { if (toFilter) {
for_const (auto row, *toFilter) { for_const (auto row, *toFilter) {
// #TODO feeds dialogs
const auto &nameWords = row->history()->peer->nameWords(); 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) {
@ -1382,6 +1454,7 @@ void DialogsInner::onFilterUpdate(QString newFilter, bool force) {
} }
if (toFilterContacts) { if (toFilterContacts) {
for_const (auto row, *toFilterContacts) { for_const (auto row, *toFilterContacts) {
// #TODO feeds dialogs
const auto &nameWords = row->history()->peer->nameWords(); 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) {
@ -1453,6 +1526,7 @@ void DialogsInner::clearSearchResults(bool clearPeerSearchResults) {
} }
PeerData *DialogsInner::updateFromParentDrag(QPoint globalPos) { PeerData *DialogsInner::updateFromParentDrag(QPoint globalPos) {
// #TODO feeds dialogs
_mouseSelection = true; _mouseSelection = true;
updateSelected(mapFromGlobal(globalPos)); updateSelected(mapFromGlobal(globalPos));
if (_state == DefaultState) { if (_state == DefaultState) {
@ -1549,9 +1623,11 @@ void DialogsInner::applyDialog(const MTPDdialog &dialog) {
if (!history->isPinnedDialog() && !history->lastMsgDate.isNull()) { if (!history->isPinnedDialog() && !history->lastMsgDate.isNull()) {
addSavedPeersAfter(history->lastMsgDate); addSavedPeersAfter(history->lastMsgDate);
} }
_contactsNoDialogs->del(peer); _contactsNoDialogs->del(history);
if (peer->migrateFrom()) { if (peer->migrateFrom()) {
removeDialog(App::historyLoaded(peer->migrateFrom()->id)); if (const auto historyFrom = App::historyLoaded(peer->migrateFrom())) {
removeDialog(historyFrom);
}
} else if (peer->migrateTo() && peer->migrateTo()->amIn()) { } else if (peer->migrateTo() && peer->migrateTo()->amIn()) {
removeDialog(history); removeDialog(history);
} }
@ -1591,7 +1667,7 @@ void DialogsInner::addSavedPeersAfter(const QDateTime &date) {
while (!saved.isEmpty() && (date.isNull() || date < saved.lastKey())) { while (!saved.isEmpty() && (date.isNull() || date < saved.lastKey())) {
const auto history = App::history(saved.last()->id); const auto history = App::history(saved.last()->id);
history->setChatsListDate(saved.lastKey()); history->setChatsListDate(saved.lastKey());
_contactsNoDialogs->del(history->peer); _contactsNoDialogs->del(history);
saved.remove(saved.lastKey(), saved.last()); saved.remove(saved.lastKey(), saved.last());
} }
} }
@ -1674,19 +1750,19 @@ void DialogsInner::userIsContactUpdated(not_null<UserData*> user) {
if (user->contactStatus() == UserData::ContactStatus::Contact) { if (user->contactStatus() == UserData::ContactStatus::Contact) {
const auto history = App::history(user->id); const auto history = App::history(user->id);
_contacts->addByName(history); _contacts->addByName(history);
if (!shownDialogs()->getRow(user->id) if (!shownDialogs()->getRow(history)
&& !_dialogs->contains(user->id)) { && !_dialogs->contains(history)) {
_contactsNoDialogs->addByName(history); _contactsNoDialogs->addByName(history);
} }
} else { } else if (const auto history = App::historyLoaded(user)) {
if (_selected && _selected->history()->peer == user) { if (_selected && _selected->history() == history) {
_selected = nullptr; _selected = nullptr;
} }
if (_pressed && _pressed->history()->peer == user) { if (_pressed && _pressed->history() == history) {
setPressed(nullptr); setPressed(nullptr);
} }
_contactsNoDialogs->del(user); _contactsNoDialogs->del(history);
_contacts->del(user); _contacts->del(history);
} }
refresh(); refresh();
} }
@ -1932,24 +2008,24 @@ void DialogsInner::selectSkip(int32 direction) {
update(); update();
} }
void DialogsInner::scrollToPeer(const PeerId &peer, MsgId msgId) { void DialogsInner::scrollToPeer(not_null<History*> history, MsgId msgId) {
int32 fromY = -1; int32 fromY = -1;
if (_state == DefaultState) { if (_state == DefaultState) {
if (auto row = shownDialogs()->getRow(peer)) { if (auto row = shownDialogs()->getRow(history)) {
fromY = dialogsOffset() + row->pos() * st::dialogsRowHeight; fromY = dialogsOffset() + row->pos() * st::dialogsRowHeight;
} }
} else if (_state == FilteredState || _state == SearchedState) { } else if (_state == FilteredState || _state == SearchedState) {
if (msgId) { if (msgId) {
for (int32 i = 0, c = _searchResults.size(); i < c; ++i) { for (int32 i = 0, c = _searchResults.size(); i < c; ++i) {
if (_searchResults[i]->item()->history()->peer->id == peer && _searchResults[i]->item()->id == msgId) { if (_searchResults[i]->item()->history() == history && _searchResults[i]->item()->id == msgId) {
fromY = searchedOffset() + i * st::dialogsRowHeight; fromY = searchedOffset() + i * st::dialogsRowHeight;
break; break;
} }
} }
} }
if (fromY < 0) { if (fromY < 0) {
for (int32 i = 0, c = _filterResults.size(); i < c; ++i) { for (auto i = 0, c = _filterResults.size(); i != c; ++i) {
if (_filterResults[i]->history()->peer->id == peer) { if (_filterResults[i]->history() == history) {
fromY = filteredOffset() + (i * st::dialogsRowHeight); fromY = filteredOffset() + (i * st::dialogsRowHeight);
break; break;
} }
@ -2008,6 +2084,7 @@ void DialogsInner::loadPeerPhotos() {
if (((*i)->pos() * st::dialogsRowHeight) >= yTo) { if (((*i)->pos() * st::dialogsRowHeight) >= yTo) {
break; break;
} }
// #TODO feeds dialogs
(*i)->history()->peer->loadUserpic(); (*i)->history()->peer->loadUserpic();
} }
yFrom = 0; yFrom = 0;
@ -2023,6 +2100,7 @@ void DialogsInner::loadPeerPhotos() {
if (to > _filterResults.size()) to = _filterResults.size(); if (to > _filterResults.size()) to = _filterResults.size();
for (; from < to; ++from) { for (; from < to; ++from) {
// #TODO feeds dialogs
_filterResults[from]->history()->peer->loadUserpic(); _filterResults[from]->history()->peer->loadUserpic();
} }
} }
@ -2066,6 +2144,7 @@ bool DialogsInner::choosePeer() {
_importantSwitchSelected = true; _importantSwitchSelected = true;
return true; return true;
} else if (_selected) { } else if (_selected) {
// #TODO feeds open
history = _selected->history(); history = _selected->history();
} }
} else if (_state == FilteredState || _state == SearchedState) { } else if (_state == FilteredState || _state == SearchedState) {
@ -2092,6 +2171,7 @@ bool DialogsInner::choosePeer() {
} }
return true; return true;
} }
// #TODO feeds open
if (_filteredSelected >= 0 && _filteredSelected < _filterResults.size()) { if (_filteredSelected >= 0 && _filteredSelected < _filterResults.size()) {
history = _filterResults[_filteredSelected]->history(); history = _filterResults[_filteredSelected]->history();
} else if (_peerSearchSelected >= 0 && _peerSearchSelected < _peerSearchResults.size()) { } else if (_peerSearchSelected >= 0 && _peerSearchSelected < _peerSearchResults.size()) {
@ -2163,141 +2243,154 @@ void DialogsInner::destroyData() {
} }
} }
void DialogsInner::peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const {
if (!inPeer) { Dialogs::RowDescriptor DialogsInner::chatListEntryBefore(
outPeer = nullptr; const Dialogs::RowDescriptor &which) const {
outMsg = 0; if (!which.key.value) {
return; return Dialogs::RowDescriptor();
} }
if (_state == DefaultState) { if (_state == DefaultState) {
if (auto row = shownDialogs()->getRow(inPeer->id)) { if (const auto row = shownDialogs()->getRow(which.key)) {
auto i = shownDialogs()->cfind(row); const auto i = shownDialogs()->cfind(row);
if (i != shownDialogs()->cbegin()) { if (i != shownDialogs()->cbegin()) {
outPeer = (*(--i))->history()->peer; return Dialogs::RowDescriptor((*(i - 1))->key(),
outMsg = ShowAtUnreadMsgId; ShowAtUnreadMsgId);
return;
} }
} }
outPeer = nullptr; return Dialogs::RowDescriptor();
outMsg = 0; }
return;
} else if (_state == FilteredState || _state == SearchedState) { const auto whichHistory = which.key.history();
if (inMsg && !_searchResults.empty()) { const auto whichMsgId = which.msgId;
if (!whichHistory) {
return Dialogs::RowDescriptor();
}
if (whichMsgId && !_searchResults.empty()) {
for (auto b = _searchResults.cbegin(), i = b + 1, e = _searchResults.cend(); i != e; ++i) { for (auto b = _searchResults.cbegin(), i = b + 1, e = _searchResults.cend(); i != e; ++i) {
if ((*i)->item()->history()->peer == inPeer && (*i)->item()->id == inMsg) { if ((*i)->item()->history() == whichHistory
auto j = i - 1; && (*i)->item()->id == whichMsgId) {
outPeer = (*j)->item()->history()->peer; const auto j = i - 1;
outMsg = (*j)->item()->id; return Dialogs::RowDescriptor(
return; (*j)->item()->history(),
(*j)->item()->id);
} }
} }
if (_searchResults.at(0)->item()->history()->peer == inPeer && _searchResults.at(0)->item()->id == inMsg) { if (_searchResults[0]->item()->history() == whichHistory
outMsg = ShowAtUnreadMsgId; && _searchResults[0]->item()->id == whichMsgId) {
if (_peerSearchResults.empty()) { if (_peerSearchResults.empty()) {
if (_filterResults.isEmpty()) { if (_filterResults.isEmpty()) {
outPeer = nullptr; return Dialogs::RowDescriptor();
} else {
outPeer = _filterResults.back()->history()->peer;
} }
} else { return Dialogs::RowDescriptor(
outPeer = _peerSearchResults.back()->peer; _filterResults.back()->key(),
ShowAtUnreadMsgId);
} }
return; return Dialogs::RowDescriptor(
App::history(_peerSearchResults.back()->peer),
ShowAtUnreadMsgId);
} }
} }
if (!_peerSearchResults.empty() && _peerSearchResults[0]->peer == inPeer) { if (!_peerSearchResults.empty() && _peerSearchResults[0]->peer == whichHistory->peer) {
outPeer = _filterResults.isEmpty() ? 0 : _filterResults.back()->history()->peer; if (_filterResults.isEmpty()) {
outMsg = ShowAtUnreadMsgId; return Dialogs::RowDescriptor();
return; }
return Dialogs::RowDescriptor(
_filterResults.back()->key(),
ShowAtUnreadMsgId);
} }
if (!_peerSearchResults.empty()) { if (!_peerSearchResults.empty()) {
for (auto b = _peerSearchResults.cbegin(), i = b + 1, e = _peerSearchResults.cend(); i != e; ++i) { for (auto b = _peerSearchResults.cbegin(), i = b + 1, e = _peerSearchResults.cend(); i != e; ++i) {
if ((*i)->peer == inPeer) { if ((*i)->peer == whichHistory->peer) {
outPeer = (*(i - 1))->peer; return Dialogs::RowDescriptor(
outMsg = ShowAtUnreadMsgId; App::history((*(i - 1))->peer),
return; ShowAtUnreadMsgId);
} }
} }
} }
if (_filterResults.isEmpty() || _filterResults.at(0)->history()->peer == inPeer) { if (_filterResults.isEmpty() || _filterResults[0]->key() == which.key) {
outPeer = nullptr; return Dialogs::RowDescriptor();
outMsg = 0;
return;
} }
for (auto b = _filterResults.cbegin(), i = b + 1, e = _filterResults.cend(); i != e; ++i) { for (auto b = _filterResults.cbegin(), i = b + 1, e = _filterResults.cend(); i != e; ++i) {
if ((*i)->history()->peer == inPeer) { if ((*i)->key() == which.key) {
outPeer = (*(i - 1))->history()->peer; return Dialogs::RowDescriptor(
outMsg = ShowAtUnreadMsgId; (*(i - 1))->key(),
return; ShowAtUnreadMsgId);
} }
} }
} return Dialogs::RowDescriptor();
outPeer = nullptr;
outMsg = 0;
} }
void DialogsInner::peerAfter(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const { Dialogs::RowDescriptor DialogsInner::chatListEntryAfter(
if (!inPeer) { const Dialogs::RowDescriptor &which) const {
outPeer = nullptr; if (!which.key.value) {
outMsg = 0; return Dialogs::RowDescriptor();
return;
} }
if (_state == DefaultState) { if (_state == DefaultState) {
if (auto row = shownDialogs()->getRow(inPeer->id)) { if (const auto row = shownDialogs()->getRow(which.key)) {
auto i = shownDialogs()->cfind(row) + 1; const auto i = shownDialogs()->cfind(row) + 1;
if (i != shownDialogs()->cend()) { if (i != shownDialogs()->cend()) {
outPeer = (*i)->history()->peer; return Dialogs::RowDescriptor(
outMsg = ShowAtUnreadMsgId; (*i)->key(),
return; ShowAtUnreadMsgId);
} }
} }
outPeer = nullptr; return Dialogs::RowDescriptor();
outMsg = 0; }
return;
} else if (_state == FilteredState || _state == SearchedState) { const auto whichHistory = which.key.history();
if (inMsg) { const auto whichMsgId = which.msgId;
if (!whichHistory) {
return Dialogs::RowDescriptor();
}
if (whichMsgId) {
for (auto i = _searchResults.cbegin(), e = _searchResults.cend(); i != e; ++i) { for (auto i = _searchResults.cbegin(), e = _searchResults.cend(); i != e; ++i) {
if ((*i)->item()->history()->peer == inPeer && (*i)->item()->id == inMsg) { if ((*i)->item()->history() == whichHistory
++i; && (*i)->item()->id == whichMsgId) {
outPeer = (i == e) ? nullptr : (*i)->item()->history()->peer; if (++i != e) {
outMsg = (i == e) ? 0 : (*i)->item()->id; return Dialogs::RowDescriptor(
return; (*i)->item()->history(),
(*i)->item()->id);
}
return Dialogs::RowDescriptor();
} }
} }
} }
for (auto i = _peerSearchResults.cbegin(), e = _peerSearchResults.cend(); i != e; ++i) { for (auto i = _peerSearchResults.cbegin(), e = _peerSearchResults.cend(); i != e; ++i) {
if ((*i)->peer == inPeer) { if ((*i)->peer == whichHistory->peer) {
++i; ++i;
if (i == e && !_searchResults.empty()) { if (i != e) {
outPeer = _searchResults.front()->item()->history()->peer; return Dialogs::RowDescriptor(
outMsg = _searchResults.front()->item()->id; App::history((*i)->peer),
} else { ShowAtUnreadMsgId);
outPeer = (i == e) ? nullptr : (*i)->peer; } else if (!_searchResults.empty()) {
outMsg = ShowAtUnreadMsgId; return Dialogs::RowDescriptor(
_searchResults.front()->item()->history(),
_searchResults.front()->item()->id);
} }
return; return Dialogs::RowDescriptor();
} }
} }
for (FilteredDialogs::const_iterator i = _filterResults.cbegin(), e = _filterResults.cend(); i != e; ++i) { for (auto i = _filterResults.cbegin(), e = _filterResults.cend(); i != e; ++i) {
if ((*i)->history()->peer == inPeer) { if ((*i)->key() == which.key) {
++i; ++i;
if (i == e && !_peerSearchResults.empty()) { if (i != e) {
outPeer = _peerSearchResults.front()->peer; return Dialogs::RowDescriptor(
outMsg = ShowAtUnreadMsgId; (*i)->key(),
} else if (i == e && !_searchResults.empty()) { ShowAtUnreadMsgId);
outPeer = _searchResults.front()->item()->history()->peer; } else if (!_peerSearchResults.empty()) {
outMsg = _searchResults.front()->item()->id; return Dialogs::RowDescriptor(
} else { App::history(_peerSearchResults.front()->peer),
outPeer = (i == e) ? nullptr : (*i)->history()->peer; ShowAtUnreadMsgId);
outMsg = ShowAtUnreadMsgId; } else if (!_searchResults.empty()) {
return Dialogs::RowDescriptor(
_searchResults.front()->item()->history(),
_searchResults.front()->item()->id);
} }
return; return Dialogs::RowDescriptor();
} }
} }
} return Dialogs::RowDescriptor();
outPeer = nullptr;
outMsg = 0;
} }
Dialogs::IndexedList *DialogsInner::contactsList() { Dialogs::IndexedList *DialogsInner::contactsList() {

View File

@ -44,10 +44,10 @@ public:
void selectSkip(int32 direction); void selectSkip(int32 direction);
void selectSkipPage(int32 pixels, int32 direction); void selectSkipPage(int32 pixels, int32 direction);
void createDialog(History *history); void createDialog(not_null<History*> history);
void dlgUpdated(Dialogs::Mode list, Dialogs::Row *row); void dlgUpdated(Dialogs::Mode list, not_null<Dialogs::Row*> row);
void dlgUpdated(PeerData *peer, MsgId msgId); void dlgUpdated(not_null<History*> history, MsgId msgId);
void removeDialog(History *history); void removeDialog(not_null<History*> history);
void dragLeft(); void dragLeft();
@ -59,9 +59,13 @@ public:
void destroyData(); void destroyData();
void peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const;
void peerAfter(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const; Dialogs::RowDescriptor chatListEntryBefore(
void scrollToPeer(const PeerId &peer, MsgId msgId); const Dialogs::RowDescriptor &which) const;
Dialogs::RowDescriptor chatListEntryAfter(
const Dialogs::RowDescriptor &which) const;
void scrollToPeer(not_null<History*> history, MsgId msgId);
Dialogs::IndexedList *contactsList(); Dialogs::IndexedList *contactsList();
Dialogs::IndexedList *dialogsList(); Dialogs::IndexedList *dialogsList();
@ -185,8 +189,9 @@ private:
using UpdateRowSections = base::flags<UpdateRowSection>; using UpdateRowSections = base::flags<UpdateRowSection>;
friend inline constexpr auto is_flag_type(UpdateRowSection) { return true; }; friend inline constexpr auto is_flag_type(UpdateRowSection) { return true; };
void updateSearchResult(not_null<PeerData*> peer);
void updateDialogRow( void updateDialogRow(
PeerData *peer, not_null<History*> history,
MsgId msgId, MsgId msgId,
QRect updateRect, QRect updateRect,
UpdateRowSections sections = UpdateRowSection::All); UpdateRowSections sections = UpdateRowSection::All);
@ -197,9 +202,27 @@ private:
int searchedOffset() const; int searchedOffset() const;
int searchInPeerSkip() const; int searchInPeerSkip() const;
void paintDialog(Painter &p, Dialogs::Row *row, int fullWidth, PeerData *active, PeerData *selected, bool onlyBackground, TimeMs ms); void paintDialog(
void paintPeerSearchResult(Painter &p, const PeerSearchResult *result, int fullWidth, bool active, bool selected, bool onlyBackground, TimeMs ms) const; Painter &p,
void paintSearchInPeer(Painter &p, int fullWidth, bool onlyBackground, TimeMs ms) const; not_null<Dialogs::Row*> row,
int fullWidth,
PeerData *active,
PeerData *selected,
bool onlyBackground,
TimeMs ms);
void paintPeerSearchResult(
Painter &p,
not_null<const PeerSearchResult*> result,
int fullWidth,
bool active,
bool selected,
bool onlyBackground,
TimeMs ms) const;
void paintSearchInPeer(
Painter &p,
int fullWidth,
bool onlyBackground,
TimeMs ms) const;
void paintSearchInFilter( void paintSearchInFilter(
Painter &p, Painter &p,
PeerData *peer, PeerData *peer,

View File

@ -334,6 +334,7 @@ void RowPainter::paint(
bool selected, bool selected,
bool onlyBackground, bool onlyBackground,
TimeMs ms) { TimeMs ms) {
// #TODO feeds show
auto history = row->history(); auto history = row->history();
auto item = history->lastMsg; auto item = history->lastMsg;
auto cloudDraft = history->cloudDraft(); auto cloudDraft = history->cloudDraft();

View File

@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Dialogs { namespace Dialogs {
List::List(SortMode sortMode) List::List(SortMode sortMode)
: _last(std::make_unique<Row>(nullptr, nullptr, nullptr, 0)) : _last(std::make_unique<Row>(nullptr))
, _begin(_last.get()) , _begin(_last.get())
, _end(_last.get()) , _end(_last.get())
, _sortMode(sortMode) , _sortMode(sortMode)
@ -33,15 +33,15 @@ void List::adjustCurrent(int32 y, int32 h) const {
} }
} }
Row *List::addToEnd(not_null<History*> history) { Row *List::addToEnd(Key key) {
const auto result = new Row(history, _end->_prev, _end, _end->_pos); const auto result = new Row(key, _end->_prev, _end, _end->_pos);
_end->_pos++; _end->_pos++;
if (_begin == _end) { if (_begin == _end) {
_begin = _current = result; _begin = _current = result;
} else { } else {
_end->_prev->_next = result; _end->_prev->_next = result;
} }
_rowByPeer.insert(history->peer->id, result); _rowByKey.emplace(key, result);
++_count; ++_count;
_end->_prev = result; _end->_prev = result;
if (_sortMode == SortMode::Date) { if (_sortMode == SortMode::Date) {
@ -51,13 +51,15 @@ Row *List::addToEnd(not_null<History*> history) {
} }
bool List::insertBefore(Row *row, Row *before) { bool List::insertBefore(Row *row, Row *before) {
if (row == before) return false; if (row == before) {
return false;
}
if (_current == row) { if (_current == row) {
_current = row->_prev; _current = row->_prev;
} }
Row *updateTill = row->_prev; const auto updateTill = row->_prev;
remove(row); remove(row);
// insert row // insert row
@ -70,8 +72,8 @@ bool List::insertBefore(Row *row, Row *before) {
_begin = row; _begin = row;
} }
// update y // update pos
for (Row *n = row; n != updateTill; n = n->_next) { for (auto n = row; n != updateTill; n = n->_next) {
n->_next->_pos++; n->_next->_pos++;
row->_pos--; row->_pos--;
} }
@ -79,13 +81,15 @@ bool List::insertBefore(Row *row, Row *before) {
} }
bool List::insertAfter(Row *row, Row *after) { bool List::insertAfter(Row *row, Row *after) {
if (row == after) return false; if (row == after) {
return false;
}
if (_current == row) { if (_current == row) {
_current = row->_next; _current = row->_next;
} }
Row *updateFrom = row->_next; const auto updateFrom = row->_next;
remove(row); remove(row);
// insert row // insert row
@ -94,26 +98,28 @@ bool List::insertAfter(Row *row, Row *after) {
row->_prev->_next = row; // update row->prev row->_prev->_next = row; // update row->prev
row->_next->_prev = row; // update row->next row->_next->_prev = row; // update row->next
// update y // update pos
for (Row *n = updateFrom; n != row; n = n->_next) { for (auto n = updateFrom; n != row; n = n->_next) {
n->_pos--; n->_pos--;
row->_pos++; row->_pos++;
} }
return true; return true;
} }
Row *List::adjustByName(const PeerData *peer) { Row *List::adjustByName(Key key) {
if (_sortMode != SortMode::Name) return nullptr; if (_sortMode != SortMode::Name) return nullptr;
auto i = _rowByPeer.find(peer->id); const auto i = _rowByKey.find(key);
if (i == _rowByPeer.cend()) return nullptr; if (i == _rowByKey.cend()) return nullptr;
Row *row = i.value(), *change = row; const auto row = i->second;
while (change->_prev && change->_prev->history()->peer->name > peer->name) { const auto name = key.name();
auto change = row;
while (change->_prev && change->_prev->name().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->history()->peer->name < peer->name) { while (change->_next != _end && change->_next->name().compare(name, Qt::CaseInsensitive) < 0) {
change = change->_next; change = change->_next;
} }
insertAfter(row, change); insertAfter(row, change);
@ -121,19 +127,19 @@ Row *List::adjustByName(const PeerData *peer) {
return row; return row;
} }
Row *List::addByName(not_null<History*> history) { Row *List::addByName(Key key) {
if (_sortMode != SortMode::Name) { if (_sortMode != SortMode::Name) {
return nullptr; return nullptr;
} }
const auto row = addToEnd(history); const auto row = addToEnd(key);
auto change = row; auto change = row;
const QString &peerName(history->peer->name); const auto name = key.name();
while (change->_prev && change->_prev->history()->peer->name.compare(peerName, Qt::CaseInsensitive) > 0) { while (change->_prev && change->_prev->name().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->history()->peer->name.compare(peerName, Qt::CaseInsensitive) < 0) { while (change->_next != _end && change->_next->name().compare(name, Qt::CaseInsensitive) < 0) {
change = change->_next; change = change->_next;
} }
insertAfter(row, change); insertAfter(row, change);
@ -145,18 +151,18 @@ void List::adjustByPos(Row *row) {
if (_sortMode != SortMode::Date || !_begin) return; if (_sortMode != SortMode::Date || !_begin) return;
Row *change = row; Row *change = row;
if (change != _begin && _begin->history()->sortKeyInChatList() < row->history()->sortKeyInChatList()) { if (change != _begin && _begin->sortKey() < row->sortKey()) {
change = _begin; change = _begin;
} else { } else {
while (change->_prev && change->_prev->history()->sortKeyInChatList() < row->history()->sortKeyInChatList()) { while (change->_prev && change->_prev->sortKey() < row->sortKey()) {
change = change->_prev; change = change->_prev;
} }
} }
if (!insertBefore(row, change)) { if (!insertBefore(row, change)) {
if (change->_next != _end && _end->_prev->history()->sortKeyInChatList() > row->history()->sortKeyInChatList()) { if (change->_next != _end && _end->_prev->sortKey() > row->sortKey()) {
change = _end->_prev; change = _end->_prev;
} else { } else {
while (change->_next != _end && change->_next->history()->sortKeyInChatList() > row->history()->sortKeyInChatList()) { while (change->_next != _end && change->_next->sortKey() > row->sortKey()) {
change = change->_next; change = change->_next;
} }
} }
@ -164,19 +170,23 @@ void List::adjustByPos(Row *row) {
} }
} }
bool List::moveToTop(PeerId peerId) { bool List::moveToTop(Key key) {
auto i = _rowByPeer.find(peerId); auto i = _rowByKey.find(key);
if (i == _rowByPeer.cend()) return false; if (i == _rowByKey.cend()) {
return false;
}
insertBefore(i.value(), _begin); insertBefore(i->second, _begin);
return true; return true;
} }
bool List::del(PeerId peerId, Row *replacedBy) { bool List::del(Key key, Row *replacedBy) {
auto i = _rowByPeer.find(peerId); auto i = _rowByKey.find(key);
if (i == _rowByPeer.cend()) return false; if (i == _rowByKey.cend()) {
return false;
}
auto row = i.value(); const auto row = i->second;
if (App::main()) { if (App::main()) {
emit App::main()->dialogRowReplaced(row, replacedBy); emit App::main()->dialogRowReplaced(row, replacedBy);
} }
@ -191,7 +201,7 @@ bool List::del(PeerId peerId, Row *replacedBy) {
remove(row); remove(row);
delete row; delete row;
--_count; --_count;
_rowByPeer.erase(i); _rowByKey.erase(i);
return true; return true;
} }
@ -212,7 +222,7 @@ void List::clear() {
delete _current; delete _current;
} }
_current = _begin; _current = _begin;
_rowByPeer.clear(); _rowByKey.clear();
_count = 0; _count = 0;
} }

View File

@ -24,11 +24,12 @@ public:
bool isEmpty() const { bool isEmpty() const {
return size() == 0; return size() == 0;
} }
bool contains(PeerId peerId) const { bool contains(Key key) const {
return _rowByPeer.contains(peerId); return _rowByKey.find(key) != _rowByKey.end();
} }
Row *getRow(PeerId peerId) const { Row *getRow(Key key) const {
return _rowByPeer.value(peerId); const auto i = _rowByKey.find(key);
return (i == _rowByKey.end()) ? nullptr : i->second.get();
} }
Row *rowAtY(int32 y, int32 h) const { Row *rowAtY(int32 y, int32 h) const {
auto i = cfind(y, h); auto i = cfind(y, h);
@ -38,12 +39,12 @@ public:
return *i; return *i;
} }
Row *addToEnd(not_null<History*> history); Row *addToEnd(Key key);
Row *adjustByName(const PeerData *peer); Row *adjustByName(Key key);
Row *addByName(not_null<History*> history); Row *addByName(Key key);
bool moveToTop(PeerId peerId); bool moveToTop(Key key);
void adjustByPos(Row *row); void adjustByPos(Row *row);
bool del(PeerId peerId, Row *replacedBy = nullptr); bool del(Key key, Row *replacedBy = nullptr);
void remove(Row *row); void remove(Row *row);
void clear(); void clear();
@ -114,10 +115,10 @@ private:
SortMode _sortMode; SortMode _sortMode;
int _count = 0; int _count = 0;
typedef QHash<PeerId, Row*> RowByPeer; std::map<Key, not_null<Row*>> _rowByKey;
RowByPeer _rowByPeer;
mutable Row *_current; // cache mutable Row *_current; // cache
}; };
} // namespace Dialogs } // namespace Dialogs

View File

@ -8,10 +8,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once #pragma once
#include "ui/text/text.h" #include "ui/text/text.h"
#include "base/value_ordering.h"
class History; class History;
class HistoryItem; class HistoryItem;
namespace Data {
class Feed;
} // namespace Data
namespace Ui { namespace Ui {
class RippleAnimation; class RippleAnimation;
} // namespace Ui } // namespace Ui
@ -21,6 +26,79 @@ namespace Layout {
class RowPainter; class RowPainter;
} // namespace Layout } // namespace Layout
struct Key {
Key() = default;
Key(History *history) : value(history) {
}
Key(not_null<History*> history) : value(history) {
}
Key(Data::Feed *feed) : value(feed) {
}
Key(not_null<Data::Feed*> feed) : value(feed) {
}
const QString &name() const {
if (const auto p = base::get_if<not_null<History*>>(&value)) {
return (*p)->peer->name;
}
// #TODO feeds name
static const auto empty = QString();
return empty;
}
const PeerData::NameFirstChars &nameFirstChars() const {
if (const auto p = base::get_if<not_null<History*>>(&value)) {
return (*p)->peer->nameFirstChars();
}
// #TODO feeds name
static const auto empty = PeerData::NameFirstChars();
return empty;
}
uint64 sortKey() const {
if (const auto p = base::get_if<not_null<History*>>(&value)) {
return (*p)->sortKeyInChatList();
}
// #TODO feeds sort in chats list
return 0ULL;
}
History *history() const {
if (const auto p = base::get_if<not_null<History*>>(&value)) {
return *p;
}
return nullptr;
}
Data::Feed *feed() const {
if (const auto p = base::get_if<not_null<Data::Feed*>>(&value)) {
return *p;
}
return nullptr;
}
inline bool operator<(const Key &other) const {
return value < other.value;
}
inline bool operator==(const Key &other) const {
return value == other.value;
}
// Not working :(
//friend inline auto value_ordering_helper(const Key &key) {
// return key.value;
//}
base::optional_variant<
not_null<History*>,
not_null<Data::Feed*>> value;
};
struct RowDescriptor {
RowDescriptor() = default;
RowDescriptor(Key key, MsgId msgId) : key(key), msgId(msgId) {
}
Key key;
MsgId msgId = 0;
};
class RippleRow { class RippleRow {
public: public:
RippleRow(); RippleRow();
@ -39,27 +117,44 @@ private:
class List; class List;
class Row : public RippleRow { class Row : public RippleRow {
public: public:
Row(History *history, Row *prev, Row *next, int pos) explicit Row(std::nullptr_t) {
: _history(history) }
Row(Key key, Row *prev, Row *next, int pos)
: _id(key)
, _prev(prev) , _prev(prev)
, _next(next) , _next(next)
, _pos(pos) { , _pos(pos) {
} }
void *attached = nullptr; // for any attached data, for example View in contacts list
Key key() const {
return _id;
}
History *history() const { History *history() const {
return _history; return _id.history();
}
Data::Feed *feed() const {
return _id.feed();
}
QString name() const {
return _id.name();
} }
int pos() const { int pos() const {
return _pos; return _pos;
} }
uint64 sortKey() const {
return _id.sortKey();
}
// for any attached data, for example View in contacts list
void *attached = nullptr;
private: private:
friend class List; friend class List;
History *_history; Key _id;
Row *_prev, *_next; Row *_prev = nullptr;
int _pos; Row *_next = nullptr;
int _pos = 0;
}; };

View File

@ -9,8 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/dialogs_inner_widget.h" #include "dialogs/dialogs_inner_widget.h"
#include "dialogs/dialogs_search_from_controllers.h" #include "dialogs/dialogs_search_from_controllers.h"
#include "styles/style_dialogs.h" #include "dialogs/dialogs_row.h"
#include "styles/style_window.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
#include "ui/wrap/fade_wrap.h" #include "ui/wrap/fade_wrap.h"
@ -28,6 +27,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "profile/profile_channel_controllers.h" #include "profile/profile_channel_controllers.h"
#include "storage/storage_media_prepare.h" #include "storage/storage_media_prepare.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "styles/style_dialogs.h"
#include "styles/style_window.h"
namespace { namespace {
@ -181,11 +182,11 @@ void DialogsWidget::activate() {
_inner->activate(); _inner->activate();
} }
void DialogsWidget::createDialog(History *history) { void DialogsWidget::createDialog(not_null<History*> history) {
auto creating = !history->inChatList(Dialogs::Mode::All); auto creating = !history->inChatList(Dialogs::Mode::All);
_inner->createDialog(history); _inner->createDialog(history);
if (creating && history->peer->migrateFrom()) { if (creating && history->peer->migrateFrom()) {
if (auto migrated = App::historyLoaded(history->peer->migrateFrom()->id)) { if (const auto migrated = App::historyLoaded(history->peer->migrateFrom())) {
if (migrated->inChatList(Dialogs::Mode::All)) { if (migrated->inChatList(Dialogs::Mode::All)) {
removeDialog(migrated); removeDialog(migrated);
} }
@ -193,12 +194,14 @@ void DialogsWidget::createDialog(History *history) {
} }
} }
void DialogsWidget::dlgUpdated(Dialogs::Mode list, Dialogs::Row *row) { void DialogsWidget::dlgUpdated(
Dialogs::Mode list,
not_null<Dialogs::Row*> row) {
_inner->dlgUpdated(list, row); _inner->dlgUpdated(list, row);
} }
void DialogsWidget::dlgUpdated(PeerData *peer, MsgId msgId) { void DialogsWidget::dlgUpdated(not_null<History*> history, MsgId msgId) {
_inner->dlgUpdated(peer, msgId); _inner->dlgUpdated(history, msgId);
} }
void DialogsWidget::dialogsToUp() { void DialogsWidget::dialogsToUp() {
@ -1103,19 +1106,21 @@ void DialogsWidget::destroyData() {
_inner->destroyData(); _inner->destroyData();
} }
void DialogsWidget::peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const { Dialogs::RowDescriptor DialogsWidget::chatListEntryBefore(
return _inner->peerBefore(inPeer, inMsg, outPeer, outMsg); const Dialogs::RowDescriptor &which) const {
return _inner->chatListEntryBefore(which);
} }
void DialogsWidget::peerAfter(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const { Dialogs::RowDescriptor DialogsWidget::chatListEntryAfter(
return _inner->peerAfter(inPeer, inMsg, outPeer, outMsg); const Dialogs::RowDescriptor &which) const {
return _inner->chatListEntryAfter(which);
} }
void DialogsWidget::scrollToPeer(const PeerId &peer, MsgId msgId) { void DialogsWidget::scrollToPeer(not_null<History*> history, MsgId msgId) {
_inner->scrollToPeer(peer, msgId); _inner->scrollToPeer(history, msgId);
} }
void DialogsWidget::removeDialog(History *history) { void DialogsWidget::removeDialog(not_null<History*> history) {
_inner->removeDialog(history); _inner->removeDialog(history);
onFilterUpdate(); onFilterUpdate();
} }

View File

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class DialogsInner; class DialogsInner;
namespace Dialogs { namespace Dialogs {
struct RowDescriptor;
class Row; class Row;
class FakeRow; class FakeRow;
class IndexedList; class IndexedList;
@ -54,9 +55,10 @@ public:
void loadDialogs(); void loadDialogs();
void loadPinnedDialogs(); void loadPinnedDialogs();
void createDialog(History *history); void createDialog(not_null<History*> history);
void dlgUpdated(Dialogs::Mode list, Dialogs::Row *row); void removeDialog(not_null<History*> history);
void dlgUpdated(PeerData *peer, MsgId msgId); void dlgUpdated(Dialogs::Mode list, not_null<Dialogs::Row*> row);
void dlgUpdated(not_null<History*> history, MsgId msgId);
void dialogsToUp(); void dialogsToUp();
@ -71,11 +73,12 @@ public:
void destroyData(); void destroyData();
void peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const; Dialogs::RowDescriptor chatListEntryBefore(
void peerAfter(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const; const Dialogs::RowDescriptor &which) const;
void scrollToPeer(const PeerId &peer, MsgId msgId); Dialogs::RowDescriptor chatListEntryAfter(
const Dialogs::RowDescriptor &which) const;
void removeDialog(History *history); void scrollToPeer(not_null<History*> history, MsgId msgId);
Dialogs::IndexedList *contactsList(); Dialogs::IndexedList *contactsList();
Dialogs::IndexedList *dialogsList(); Dialogs::IndexedList *dialogsList();

View File

@ -168,12 +168,6 @@ void joinGroupByHash(const QString &hash) {
if (MainWidget *m = main()) m->joinGroupByHash(hash); if (MainWidget *m = main()) m->joinGroupByHash(hash);
} }
void removeDialog(History *history) {
if (MainWidget *m = main()) {
m->removeDialog(history);
}
}
void showSettings() { void showSettings() {
if (auto w = wnd()) { if (auto w = wnd()) {
w->showSettings(); w->showSettings();

View File

@ -133,7 +133,6 @@ void openPeerByName(
MsgId msgId = ShowAtUnreadMsgId, MsgId msgId = ShowAtUnreadMsgId,
const QString &startToken = QString()); const QString &startToken = QString());
void joinGroupByHash(const QString &hash); void joinGroupByHash(const QString &hash);
void removeDialog(History *history);
void showSettings(); void showSettings();
void activateClickHandler(ClickHandlerPtr handler, Qt::MouseButton button); void activateClickHandler(ClickHandlerPtr handler, Qt::MouseButton button);

View File

@ -2564,7 +2564,7 @@ Dialogs::Row *History::addToChatList(Dialogs::Mode list, Dialogs::IndexedList *i
void History::removeFromChatList(Dialogs::Mode list, Dialogs::IndexedList *indexed) { void History::removeFromChatList(Dialogs::Mode list, Dialogs::IndexedList *indexed) {
Assert(indexed != nullptr); Assert(indexed != nullptr);
if (inChatList(list)) { if (inChatList(list)) {
indexed->del(peer); indexed->del(this);
chatListLinks(list).clear(); chatListLinks(list).clear();
if (list == Dialogs::Mode::All && unreadCount()) { if (list == Dialogs::Mode::All && unreadCount()) {
App::histories().unreadIncrement(-unreadCount(), mute()); App::histories().unreadIncrement(-unreadCount(), mute());
@ -2590,9 +2590,13 @@ void History::addChatListEntryByLetter(Dialogs::Mode list, QChar letter, Dialogs
void History::updateChatListEntry() const { void History::updateChatListEntry() const {
if (auto main = App::main()) { if (auto main = App::main()) {
if (inChatList(Dialogs::Mode::All)) { if (inChatList(Dialogs::Mode::All)) {
main->dlgUpdated(Dialogs::Mode::All, mainChatListLink(Dialogs::Mode::All)); main->dlgUpdated(
Dialogs::Mode::All,
mainChatListLink(Dialogs::Mode::All));
if (inChatList(Dialogs::Mode::Important)) { if (inChatList(Dialogs::Mode::Important)) {
main->dlgUpdated(Dialogs::Mode::Important, mainChatListLink(Dialogs::Mode::Important)); main->dlgUpdated(
Dialogs::Mode::Important,
mainChatListLink(Dialogs::Mode::Important));
} }
} }
} }

View File

@ -164,7 +164,8 @@ ReplyKeyboard *HistoryItem::inlineReplyKeyboard() {
void HistoryItem::invalidateChatsListEntry() { void HistoryItem::invalidateChatsListEntry() {
if (App::main()) { if (App::main()) {
App::main()->dlgUpdated(history()->peer, id); // #TODO feeds dialogs
App::main()->dlgUpdated(history(), id);
} }
// invalidate cache for drawInDialog // invalidate cache for drawInDialog

View File

@ -775,7 +775,8 @@ void HistoryService::updateDependentText() {
history()->textCachedFor = nullptr; history()->textCachedFor = nullptr;
} }
if (App::main()) { if (App::main()) {
App::main()->dlgUpdated(history()->peer, id); // #TODO feeds dialogs
App::main()->dlgUpdated(history(), id);
} }
App::historyUpdateDependent(this); App::historyUpdateDependent(this);
} }

View File

@ -7,13 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "history/history_widget.h" #include "history/history_widget.h"
#include "styles/style_history.h"
#include "styles/style_dialogs.h"
#include "styles/style_window.h"
#include "styles/style_boxes.h"
#include "styles/style_profile.h"
#include "styles/style_chat_helpers.h"
#include "styles/style_info.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "boxes/send_files_box.h" #include "boxes/send_files_box.h"
#include "boxes/share_box.h" #include "boxes/share_box.h"
@ -72,6 +65,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "inline_bots/inline_results_widget.h" #include "inline_bots/inline_results_widget.h"
#include "chat_helpers/emoji_suggestions_widget.h" #include "chat_helpers/emoji_suggestions_widget.h"
#include "core/crash_reports.h" #include "core/crash_reports.h"
#include "dialogs/dialogs_row.h"
#include "styles/style_history.h"
#include "styles/style_dialogs.h"
#include "styles/style_window.h"
#include "styles/style_boxes.h"
#include "styles/style_profile.h"
#include "styles/style_chat_helpers.h"
#include "styles/style_info.h"
namespace { namespace {
@ -1391,24 +1392,30 @@ bool HistoryWidget::cmd_search() {
} }
bool HistoryWidget::cmd_next_chat() { bool HistoryWidget::cmd_next_chat() {
PeerData *p = 0; if (!_history) {
MsgId m = 0; return false;
App::main()->peerAfter(_peer, qMax(_showAtMsgId, 0), p, m); }
if (p) { const auto next = App::main()->chatListEntryAfter(
Ui::showPeerHistory(p, m); Dialogs::RowDescriptor(_history, std::max(_showAtMsgId, 0)));
if (const auto history = next.key.history()) {
Ui::showPeerHistory(history, next.msgId);
return true; return true;
} }
// #TODO feeds show
return false; return false;
} }
bool HistoryWidget::cmd_previous_chat() { bool HistoryWidget::cmd_previous_chat() {
PeerData *p = 0; if (!_history) {
MsgId m = 0; return false;
App::main()->peerBefore(_peer, qMax(_showAtMsgId, 0), p, m); }
if (p) { const auto next = App::main()->chatListEntryBefore(
Ui::showPeerHistory(p, m); Dialogs::RowDescriptor(_history, std::max(_showAtMsgId, 0)));
if (const auto history = next.key.history()) {
Ui::showPeerHistory(history, next.msgId);
return true; return true;
} }
// #TODO feeds show
return false; return false;
} }
@ -1579,7 +1586,9 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re
if (!canShowNow) { if (!canShowNow) {
delayedShowAt(showAtMsgId); delayedShowAt(showAtMsgId);
App::main()->dlgUpdated(wasHistory ? wasHistory->peer : nullptr, wasMsgId); if (wasHistory) {
App::main()->dlgUpdated(wasHistory, wasMsgId);
}
emit historyShown(_history, _showAtMsgId); emit historyShown(_history, _showAtMsgId);
} else { } else {
_history->forgetScrollState(); _history->forgetScrollState();
@ -1780,7 +1789,9 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re
if (App::wnd()) QTimer::singleShot(0, App::wnd(), SLOT(setInnerFocus())); if (App::wnd()) QTimer::singleShot(0, App::wnd(), SLOT(setInnerFocus()));
App::main()->dlgUpdated(wasHistory ? wasHistory->peer : nullptr, wasMsgId); if (wasHistory) {
App::main()->dlgUpdated(wasHistory, wasMsgId);
}
emit historyShown(_history, _showAtMsgId); emit historyShown(_history, _showAtMsgId);
controller()->historyPeer = _peer; controller()->historyPeer = _peer;
@ -2988,11 +2999,14 @@ PeerData *HistoryWidget::peer() const {
return _peer; return _peer;
} }
void HistoryWidget::setMsgId(MsgId showAtMsgId) { // sometimes _showAtMsgId is set directly // Sometimes _showAtMsgId is set directly.
void HistoryWidget::setMsgId(MsgId showAtMsgId) {
if (_showAtMsgId != showAtMsgId) { if (_showAtMsgId != showAtMsgId) {
auto wasMsgId = _showAtMsgId; auto wasMsgId = _showAtMsgId;
_showAtMsgId = showAtMsgId; _showAtMsgId = showAtMsgId;
App::main()->dlgUpdated(_history ? _history->peer : nullptr, wasMsgId); if (_history) {
App::main()->dlgUpdated(_history, wasMsgId);
}
emit historyShown(_history, _showAtMsgId); emit historyShown(_history, _showAtMsgId);
} }
} }

View File

@ -15,15 +15,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_web_page.h" #include "data/data_web_page.h"
#include "data/data_game.h" #include "data/data_game.h"
#include "data/data_peer_values.h" #include "data/data_peer_values.h"
#include "styles/style_dialogs.h" #include "data/data_drafts.h"
#include "styles/style_history.h" #include "data/data_session.h"
#include "ui/special_buttons.h" #include "ui/special_buttons.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/shadow.h" #include "ui/widgets/shadow.h"
#include "window/section_memento.h" #include "window/section_memento.h"
#include "window/section_widget.h" #include "window/section_widget.h"
#include "data/data_drafts.h"
#include "data/data_session.h"
#include "ui/widgets/dropdown_menu.h" #include "ui/widgets/dropdown_menu.h"
#include "ui/focus_persister.h" #include "ui/focus_persister.h"
#include "ui/resize_area.h" #include "ui/resize_area.h"
@ -36,6 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "observer_peer.h" #include "observer_peer.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "dialogs/dialogs_widget.h" #include "dialogs/dialogs_widget.h"
#include "dialogs/dialogs_row.h"
#include "history/history_widget.h" #include "history/history_widget.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/history_media.h" #include "history/history_media.h"
@ -69,16 +68,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_slide_animation.h" #include "window/window_slide_animation.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "window/themes/window_theme.h" #include "window/themes/window_theme.h"
#include "styles/style_boxes.h"
#include "mtproto/dc_options.h" #include "mtproto/dc_options.h"
#include "core/file_utilities.h" #include "core/file_utilities.h"
#include "auth_session.h"
#include "calls/calls_instance.h" #include "calls/calls_instance.h"
#include "calls/calls_top_bar.h" #include "calls/calls_top_bar.h"
#include "auth_session.h" #include "auth_session.h"
#include "storage/storage_facade.h" #include "storage/storage_facade.h"
#include "storage/storage_shared_media.h" #include "storage/storage_shared_media.h"
#include "storage/storage_user_photos.h" #include "storage/storage_user_photos.h"
#include "styles/style_dialogs.h"
#include "styles/style_history.h"
#include "styles/style_boxes.h"
enum StackItemType { enum StackItemType {
HistoryStackItem, HistoryStackItem,
@ -120,10 +120,11 @@ private:
class StackItemHistory : public StackItem { class StackItemHistory : public StackItem {
public: public:
StackItemHistory( StackItemHistory(
PeerData *peer, not_null<History*> history,
MsgId msgId, MsgId msgId,
QList<MsgId> replyReturns) QList<MsgId> replyReturns)
: StackItem(peer) : StackItem(history->peer)
, history(history)
, msgId(msgId) , msgId(msgId)
, replyReturns(replyReturns) { , replyReturns(replyReturns) {
} }
@ -132,6 +133,7 @@ public:
return HistoryStackItem; return HistoryStackItem;
} }
not_null<History*> history;
MsgId msgId; MsgId msgId;
QList<MsgId> replyReturns; QList<MsgId> replyReturns;
@ -902,7 +904,7 @@ void MainWidget::hiderLayer(object_ptr<HistoryHider> h) {
_hider->hide(); _hider->hide();
auto animationParams = prepareDialogsAnimation(); auto animationParams = prepareDialogsAnimation();
onHistoryShown(0, 0); onHistoryShown(nullptr, 0);
if (_mainSection) { if (_mainSection) {
_mainSection->hide(); _mainSection->hide();
} else { } else {
@ -1089,7 +1091,7 @@ void MainWidget::deletedContact(UserData *user, const MTPcontacts_Link &result)
App::feedUserLink(MTP_int(peerToUser(user->id)), d.vmy_link, d.vforeign_link); App::feedUserLink(MTP_int(peerToUser(user->id)), d.vmy_link, d.vforeign_link);
} }
void MainWidget::removeDialog(History *history) { void MainWidget::removeDialog(not_null<History*> history) {
_dialogs->removeDialog(history); _dialogs->removeDialog(history);
} }
@ -2198,7 +2200,7 @@ bool MainWidget::viewsIncrementFail(const RPCError &error, mtpRequestId req) {
return false; return false;
} }
void MainWidget::createDialog(History *history) { void MainWidget::createDialog(not_null<History*> history) {
_dialogs->createDialog(history); _dialogs->createDialog(history);
} }
@ -2307,15 +2309,12 @@ void MainWidget::ui_showPeerHistory(
auto animationParams = animatedShow() ? prepareHistoryAnimation(peerId) : Window::SectionSlideParams(); auto animationParams = animatedShow() ? prepareHistoryAnimation(peerId) : Window::SectionSlideParams();
dlgUpdated();
if (back || (way == Way::ClearStack)) { if (back || (way == Way::ClearStack)) {
_peerInStack = nullptr; clearEntryInStack();
_msgIdInStack = 0;
} else { } else {
// This may modify the current section, for example remove its contents. // This may modify the current section, for example remove its contents.
saveSectionInStack(); saveSectionInStack();
} }
dlgUpdated();
if (_history->peer() && _history->peer()->id != peerId && way != Way::Forward) { if (_history->peer() && _history->peer()->id != peerId && way != Way::Forward) {
clearBotStartToken(_history->peer()); clearBotStartToken(_history->peer());
@ -2371,7 +2370,9 @@ void MainWidget::ui_showPeerHistory(
if (!_dialogs->isHidden()) { if (!_dialogs->isHidden()) {
if (!back) { if (!back) {
_dialogs->scrollToPeer(peerId, showAtMsgId); if (const auto history = _history->history()) {
_dialogs->scrollToPeer(history, showAtMsgId);
}
} }
_dialogs->update(); _dialogs->update();
} }
@ -2387,22 +2388,20 @@ PeerData *MainWidget::ui_getPeerForMouseAction() {
return _history->ui_getPeerForMouseAction(); return _history->ui_getPeerForMouseAction();
} }
void MainWidget::peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) { Dialogs::RowDescriptor MainWidget::chatListEntryBefore(
const Dialogs::RowDescriptor &which) const {
if (selectingPeer()) { if (selectingPeer()) {
outPeer = 0; return Dialogs::RowDescriptor();
outMsg = 0;
return;
} }
_dialogs->peerBefore(inPeer, inMsg, outPeer, outMsg); return _dialogs->chatListEntryBefore(which);
} }
void MainWidget::peerAfter(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) { Dialogs::RowDescriptor MainWidget::chatListEntryAfter(
const Dialogs::RowDescriptor &which) const {
if (selectingPeer()) { if (selectingPeer()) {
outPeer = 0; return Dialogs::RowDescriptor();
outMsg = 0;
return;
} }
_dialogs->peerAfter(inPeer, inMsg, outPeer, outMsg); return _dialogs->chatListEntryAfter(which);
} }
PeerData *MainWidget::peer() { PeerData *MainWidget::peer() {
@ -2410,13 +2409,33 @@ PeerData *MainWidget::peer() {
} }
PeerData *MainWidget::activePeer() { PeerData *MainWidget::activePeer() {
return _history->peer() ? _history->peer() : _peerInStack; if (const auto history = _history->history()) {
return history->peer;
} else if (_historyInStack) {
return _historyInStack->peer;
}
return nullptr;
} }
MsgId MainWidget::activeMsgId() { MsgId MainWidget::activeMsgId() {
return _history->peer() ? _history->msgId() : _msgIdInStack; return _history->peer() ? _history->msgId() : _msgIdInStack;
} }
void MainWidget::setEntryInStack(not_null<History*> history, MsgId msgId) {
setEntryInStackValues(history, msgId);
}
void MainWidget::clearEntryInStack() {
setEntryInStackValues(nullptr, 0);
}
void MainWidget::setEntryInStackValues(History *history, MsgId msgId) {
updateCurrentChatListEntry();
_historyInStack = history;
_msgIdInStack = msgId;
updateCurrentChatListEntry();
}
void MainWidget::saveSectionInStack() { void MainWidget::saveSectionInStack() {
if (_mainSection) { if (_mainSection) {
if (auto memento = _mainSection->createMemento()) { if (auto memento = _mainSection->createMemento()) {
@ -2424,11 +2443,10 @@ void MainWidget::saveSectionInStack() {
std::move(memento))); std::move(memento)));
_stack.back()->setThirdSectionWeak(_thirdSection.data()); _stack.back()->setThirdSectionWeak(_thirdSection.data());
} }
} else if (_history->peer()) { } else if (const auto history = _history->history()) {
_peerInStack = _history->peer(); setEntryInStack(history, _history->msgId());
_msgIdInStack = _history->msgId();
_stack.push_back(std::make_unique<StackItemHistory>( _stack.push_back(std::make_unique<StackItemHistory>(
_peerInStack, _historyInStack,
_msgIdInStack, _msgIdInStack,
_history->replyReturns())); _history->replyReturns()));
_stack.back()->setThirdSectionWeak(_thirdSection.data()); _stack.back()->setThirdSectionWeak(_thirdSection.data());
@ -2765,15 +2783,11 @@ void MainWidget::showBackFromStack(
} }
_thirdSectionFromStack = item->takeThirdSectionMemento(); _thirdSectionFromStack = item->takeThirdSectionMemento();
if (item->type() == HistoryStackItem) { if (item->type() == HistoryStackItem) {
dlgUpdated(); clearEntryInStack();
_peerInStack = nullptr;
_msgIdInStack = 0;
for (auto i = _stack.size(); i > 0;) { for (auto i = _stack.size(); i > 0;) {
if (_stack[--i]->type() == HistoryStackItem) { if (_stack[--i]->type() == HistoryStackItem) {
auto historyItem = static_cast<StackItemHistory*>(_stack[i].get()); auto historyItem = static_cast<StackItemHistory*>(_stack[i].get());
_peerInStack = historyItem->peer(); setEntryInStack(historyItem->history, historyItem->msgId);
_msgIdInStack = historyItem->msgId;
dlgUpdated();
break; break;
} }
} }
@ -2899,24 +2913,29 @@ QPixmap MainWidget::grabForShowAnimation(const Window::SectionSlideParams &param
return result; return result;
} }
void MainWidget::dlgUpdated() { void MainWidget::updateCurrentChatListEntry() {
if (_peerInStack) { if (_historyInStack) {
_dialogs->dlgUpdated(_peerInStack, _msgIdInStack); _dialogs->dlgUpdated(_historyInStack, _msgIdInStack);
} }
} }
void MainWidget::dlgUpdated(Dialogs::Mode list, Dialogs::Row *row) { void MainWidget::dlgUpdated(
Dialogs::Mode list,
not_null<Dialogs::Row*> row) {
if (row) { if (row) {
_dialogs->dlgUpdated(list, row); _dialogs->dlgUpdated(list, row);
} }
} }
void MainWidget::dlgUpdated(PeerData *peer, MsgId msgId) { void MainWidget::dlgUpdated(not_null<History*> history, MsgId msgId) {
if (!peer) return; if (msgId < 0 && -msgId < ServerMaxMsgId) {
if (msgId < 0 && -msgId < ServerMaxMsgId && peer->migrateFrom()) { if (const auto from = history->peer->migrateFrom()) {
_dialogs->dlgUpdated(peer->migrateFrom(), -msgId); if (const auto migrated = App::historyLoaded(from)) {
_dialogs->dlgUpdated(migrated, -msgId);
}
}
} else { } else {
_dialogs->dlgUpdated(peer, msgId); _dialogs->dlgUpdated(history, msgId);
} }
} }
@ -3539,7 +3558,9 @@ int MainWidget::backgroundFromY() const {
void MainWidget::onHistoryShown(History *history, MsgId atMsgId) { void MainWidget::onHistoryShown(History *history, MsgId atMsgId) {
// updateControlsGeometry(); // updateControlsGeometry();
dlgUpdated(history ? history->peer : nullptr, atMsgId); if (history) {
dlgUpdated(history, atMsgId);
}
} }
void MainWidget::searchInPeer(PeerData *peer) { void MainWidget::searchInPeer(PeerData *peer) {

View File

@ -25,6 +25,7 @@ struct PeerUpdate;
} // namespace Notify } // namespace Notify
namespace Dialogs { namespace Dialogs {
struct RowDescriptor;
class Row; class Row;
} // namespace Dialogs } // namespace Dialogs
@ -105,11 +106,10 @@ public:
void activate(); void activate();
void createDialog(History *history); void createDialog(not_null<History*> history);
void removeDialog(History *history); void removeDialog(not_null<History*> history);
void dlgUpdated(); void dlgUpdated(Dialogs::Mode list, not_null<Dialogs::Row*> row);
void dlgUpdated(Dialogs::Mode list, Dialogs::Row *row); void dlgUpdated(not_null<History*> history, MsgId msgId);
void dlgUpdated(PeerData *peer, MsgId msgId);
void windowShown(); void windowShown();
@ -126,10 +126,12 @@ public:
void newUnreadMsg(History *history, HistoryItem *item); void newUnreadMsg(History *history, HistoryItem *item);
void markActiveHistoryAsRead(); void markActiveHistoryAsRead();
void peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg); Dialogs::RowDescriptor chatListEntryBefore(
void peerAfter(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg); const Dialogs::RowDescriptor &which) const;
PeerData *peer(); Dialogs::RowDescriptor chatListEntryAfter(
const Dialogs::RowDescriptor &which) const;
PeerData *peer();
PeerData *activePeer(); PeerData *activePeer();
MsgId activeMsgId(); MsgId activeMsgId();
@ -438,6 +440,11 @@ private:
void closeBothPlayers(); void closeBothPlayers();
void playerHeightUpdated(); void playerHeightUpdated();
void updateCurrentChatListEntry();
void setEntryInStack(not_null<History*> history, MsgId msgId);
void clearEntryInStack();
void setEntryInStackValues(History *history, MsgId msgId);
void setCurrentCall(Calls::Call *call); void setCurrentCall(Calls::Call *call);
void createCallTopBar(); void createCallTopBar();
void destroyCallTopBar(); void destroyCallTopBar();
@ -581,7 +588,7 @@ private:
QPointer<ConfirmBox> _forwardConfirm; // for single column layout QPointer<ConfirmBox> _forwardConfirm; // for single column layout
object_ptr<HistoryHider> _hider = { nullptr }; object_ptr<HistoryHider> _hider = { nullptr };
std::vector<std::unique_ptr<StackItem>> _stack; std::vector<std::unique_ptr<StackItem>> _stack;
PeerData *_peerInStack = nullptr; History *_historyInStack = nullptr;
MsgId _msgIdInStack = 0; MsgId _msgIdInStack = 0;
int _playerHeight = 0; int _playerHeight = 0;

View File

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