2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Track real latest message in the folder.

This commit is contained in:
John Preston
2019-04-22 19:09:03 +04:00
parent 8fd811517b
commit ceec71d3e6
4 changed files with 75 additions and 16 deletions

View File

@@ -154,7 +154,7 @@ void History::checkChatListMessageRemoved(not_null<HistoryItem*> item) {
if (chatListMessage() != item) {
return;
}
_chatListMessage = std::nullopt;
setChatListMessageUnknown();
refreshChatListMessage();
//if (const auto channel = peer->asChannel()) { // #feed
// if (const auto feed = channel->feed()) {
@@ -2201,12 +2201,16 @@ void History::setLastMessage(HistoryItem *item) {
}
}
_lastMessage = item;
_chatListMessage = std::nullopt;
if (!peer->migrateTo()) {
if (peer->migrateTo()) {
// We don't want to request last message for all deactivated chats.
// This is a heavy request for them, because we need to get last
// two items by messages.getHistory to skip the migration message.
requestChatListMessage();
setChatListMessageUnknown();
} else {
setChatListMessageFromLast();
if (!chatListMessageKnown()) {
setFakeChatListMessage();
}
}
}
@@ -2222,6 +2226,7 @@ void History::setChatListMessage(HistoryItem *item) {
if (_chatListMessage && *_chatListMessage == item) {
return;
}
const auto was = _chatListMessage.value_or(nullptr);
if (item) {
if (!_chatListMessage || !*_chatListMessage) {
Local::removeSavedPeer(peer);
@@ -2235,6 +2240,9 @@ void History::setChatListMessage(HistoryItem *item) {
_chatListMessage = nullptr;
updateChatListEntry();
}
if (const auto folder = this->folder()) {
folder->oneListMessageChanged(was, item);
}
if (const auto to = peer->migrateTo()) {
if (const auto history = owner().historyLoaded(to)) {
if (!history->chatListMessageKnown()) {
@@ -2297,7 +2305,18 @@ void History::setChatListMessageFromLast() {
if (const auto good = computeChatListMessageFromLast()) {
setChatListMessage(*good);
} else {
_chatListMessage = std::nullopt;
setChatListMessageUnknown();
}
}
void History::setChatListMessageUnknown() {
if (!_chatListMessage.has_value()) {
return;
}
const auto was = *_chatListMessage;
_chatListMessage = std::nullopt;
if (const auto folder = this->folder()) {
folder->oneListMessageChanged(was, nullptr);
}
}