Don't replace local with server last message.

This commit is contained in:
John Preston 2020-02-19 17:49:49 +04:00
parent 32d93e2651
commit c04f3a7048
3 changed files with 19 additions and 34 deletions

View File

@ -1937,8 +1937,8 @@ void History::setFolder(
not_null<Data::Folder*> 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();

View File

@ -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);

View File

@ -145,22 +145,6 @@ void ActivateWindow(not_null<Window::SessionController*> controller) {
Ui::ActivateWindowDelayed(window);
}
bool ShowHistoryEndInsteadOfUnread(
not_null<Data::Session*> 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<Ui::FlatButton> SetupDiscussButton(
not_null<QWidget*> parent,
not_null<Window::SessionController*> 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();