From c04f3a704800144948fbe114a33f56fd95384517 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 19 Feb 2020 17:49:49 +0400 Subject: [PATCH] Don't replace local with server last message. --- Telegram/SourceFiles/history/history.cpp | 33 ++++++++++--------- Telegram/SourceFiles/history/history.h | 1 + .../SourceFiles/history/history_widget.cpp | 19 ----------- 3 files changed, 19 insertions(+), 34 deletions(-) diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 247b9893d..15834f0d4 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -1937,8 +1937,8 @@ void History::setFolder( not_null folder, HistoryItem *folderDialogItem) { setFolderPointer(folder); - if (folderDialogItem && _lastMessage != folderDialogItem) { - setLastMessage(folderDialogItem); + if (folderDialogItem) { + setLastServerMessage(folderDialogItem); } } @@ -2369,16 +2369,19 @@ void History::clearSharedMedia() { //} } +void History::setLastServerMessage(HistoryItem *item) { + if (_lastMessage + && *_lastMessage + && !IsServerMsgId((*_lastMessage)->id) + && (!item || (*_lastMessage)->date() > item->date())) { + return; + } + setLastMessage(item); +} + void History::setLastMessage(HistoryItem *item) { - if (_lastMessage) { - if (*_lastMessage == item) { - return; - } else if (*_lastMessage - && item - && !IsServerMsgId((*_lastMessage)->id) - && (*_lastMessage)->date() > item->date()) { - return; - } + if (_lastMessage && *_lastMessage == item) { + return; } _lastMessage = item; if (peer->migrateTo()) { @@ -2766,12 +2769,12 @@ void History::applyDialogTopMessage(MsgId topMessageId) { channelId(), topMessageId); if (const auto item = owner().message(itemId)) { - setLastMessage(item); + setLastServerMessage(item); } else { - setLastMessage(nullptr); + setLastServerMessage(nullptr); } } else { - setLastMessage(nullptr); + setLastServerMessage(nullptr); } if (clearUnreadOnClientSide()) { setUnreadCount(0); @@ -3167,7 +3170,7 @@ void History::clear(ClearType type) { setUnreadCount(0); } if (type == ClearType::DeleteChat) { - setLastMessage(nullptr); + setLastServerMessage(nullptr); } else if (_lastMessage && *_lastMessage) { if (IsServerMsgId((*_lastMessage)->id)) { (*_lastMessage)->applyEditionToHistoryCleared(); diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index 47d833970..9385c6da7 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -455,6 +455,7 @@ private: // After adding a new history slice check lastMessage / loadedAtBottom. void checkLastMessage(); void setLastMessage(HistoryItem *item); + void setLastServerMessage(HistoryItem *item); void refreshChatListMessage(); void setChatListMessage(HistoryItem *item); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index ea4701bd3..d34e0cc13 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -145,22 +145,6 @@ void ActivateWindow(not_null controller) { Ui::ActivateWindowDelayed(window); } -bool ShowHistoryEndInsteadOfUnread( - not_null session, - PeerId peerId) { - // Ignore unread messages in case of unread changelogs. - // We must show this history at end for the changelog to be visible. - if (peerId != PeerData::kServiceNotificationsId) { - return false; - } - const auto history = session->history(peerId); - if (!history->unreadCount()) { - return false; - } - const auto last = history->lastMessage(); - return (last != nullptr) && !IsServerMsgId(last->id); -} - object_ptr SetupDiscussButton( not_null parent, not_null controller) { @@ -1646,9 +1630,6 @@ void HistoryWidget::showHistory( const auto startBot = (showAtMsgId == ShowAndStartBotMsgId); if (startBot) { showAtMsgId = ShowAtTheEndMsgId; - } else if ((showAtMsgId == ShowAtUnreadMsgId) - && ShowHistoryEndInsteadOfUnread(&session().data(), peerId)) { - showAtMsgId = ShowAtTheEndMsgId; } clearHighlightMessages();