diff --git a/Telegram/SourceFiles/data/data_replies_list.cpp b/Telegram/SourceFiles/data/data_replies_list.cpp index 511ffb2e3..98c7ec5a7 100644 --- a/Telegram/SourceFiles/data/data_replies_list.cpp +++ b/Telegram/SourceFiles/data/data_replies_list.cpp @@ -239,7 +239,7 @@ bool RepliesList::buildFromData(not_null viewer) { return viewer->around; } else if (const auto item = lookupRoot()) { if (const auto original = item->lookupDiscussionPostOriginal()) { - return original->commentsReadTill(); + return original->computeCommentsReadTillFull(); } } return viewer->around; diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 9a19378e4..36dd54c33 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -1767,6 +1767,14 @@ MsgId History::loadAroundId() const { return MsgId(0); } +MsgId History::inboxReadTillId() const { + return _inboxReadBefore.value_or(1) - 1; +} + +MsgId History::outboxReadTillId() const { + return _outboxReadBefore.value_or(1) - 1; +} + HistoryItem *History::lastAvailableMessage() const { return isEmpty() ? nullptr : blocks.back()->messages.back()->data().get(); } diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index 392178442..5b42c22e0 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -201,6 +201,8 @@ public: [[nodiscard]] bool isServerSideUnread( not_null item) const; [[nodiscard]] MsgId loadAroundId() const; + [[nodiscard]] MsgId inboxReadTillId() const; + [[nodiscard]] MsgId outboxReadTillId() const; [[nodiscard]] bool trackUnreadMessages() const; [[nodiscard]] int unreadCount() const; diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index b4569f07a..009cace3e 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -212,6 +212,9 @@ public: } virtual void setCommentsPossibleMaxId(MsgId possibleMaxId) { } + [[nodiscard]] virtual MsgId computeCommentsReadTillFull() const { + return MsgId(0); + } [[nodiscard]] virtual bool areCommentsUnread() const { return false; } diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index d838a5732..0f614c62b 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -856,10 +856,31 @@ void HistoryMessage::setCommentsPossibleMaxId(MsgId possibleMaxId) { } } +MsgId HistoryMessage::computeCommentsReadTillFull() const { + const auto local = commentsReadTill(); + const auto views = Get(); + if (!views || !views->commentsChannelId) { + return local; + } + const auto group = history()->owner().historyLoaded( + peerFromChannel(views->commentsChannelId)); + if (!group) { + return local; + } + return std::max(local, group->inboxReadTillId()); +} + bool HistoryMessage::areCommentsUnread() const { if (const auto views = Get()) { - return (views->commentsReadTillId > 1) - && (views->commentsMaxId > views->commentsReadTillId); + if (views->commentsReadTillId < 2 + || views->commentsMaxId <= views->commentsReadTillId) { + return false; + } else if (!views->commentsChannelId) { + return true; + } + const auto group = history()->owner().historyLoaded( + peerFromChannel(views->commentsChannelId)); + return !group || (views->commentsMaxId > group->inboxReadTillId()); } return false; } diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index 137d84cab..45eecc137 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -37,7 +37,7 @@ QString GetErrorTextForSending( bool ignoreSlowmodeCountdown = false); void FastShareMessage(not_null item); -class HistoryMessage : public HistoryItem { +class HistoryMessage final : public HistoryItem { public: HistoryMessage( not_null history, @@ -166,6 +166,7 @@ public: void setCommentsReadTill(MsgId readTillId) override; void setCommentsMaxId(MsgId maxId) override; void setCommentsPossibleMaxId(MsgId possibleMaxId) override; + [[nodiscard]] MsgId computeCommentsReadTillFull() const override; [[nodiscard]] bool areCommentsUnread() const override; bool updateDependencyItem() override; [[nodiscard]] MsgId dependencyMsgId() const override { diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 0035eb50e..12a9bb4de 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -93,7 +93,7 @@ RepliesMemento::RepliesMemento( FullMsgId(commentsItem->history()->channelId(), commentId) }); } else if (const auto original = commentsItem->lookupDiscussionPostOriginal()) { - if (original->commentsReadTill() == MsgId(1)) { + if (original->computeCommentsReadTillFull() == MsgId(1)) { _list.setAroundPosition(Data::MinMessagePosition); _list.setScrollTopState(ListMemento::ScrollTopState{ Data::MinMessagePosition @@ -241,7 +241,7 @@ void RepliesWidget::sendReadTillRequest() { _readRequestId = api->request(MTPmessages_ReadDiscussion( _commentsRoot->history()->peer->input, MTP_int(_commentsRoot->id), - MTP_int(_commentsRoot->commentsReadTill()) + MTP_int(_commentsRoot->computeCommentsReadTillFull()) )).done([=](const MTPBool &) { }).send(); } @@ -1519,7 +1519,7 @@ void RepliesWidget::readTill(not_null item) { if (!_commentsRoot) { return; } - const auto was = _commentsRoot->commentsReadTill(); + const auto was = _commentsRoot->computeCommentsReadTillFull(); const auto now = item->id; const auto fast = item->out(); if (was < now) { @@ -1547,7 +1547,7 @@ MessagesBarData RepliesWidget::listMessagesBar( if (!_commentsRoot || elements.empty()) { return {}; } - const auto till = _commentsRoot->commentsReadTill(); + const auto till = _commentsRoot->computeCommentsReadTillFull(); if (till < 2) { return {}; }