diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index 90f69371f..1d7bd373f 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -153,7 +153,11 @@ void ChannelData::setLinkedChat(ChannelData *linked) { } ChannelData *ChannelData::linkedChat() const { - return _linkedChat; + return _linkedChat.value_or(nullptr); +} + +bool ChannelData::linkedChatKnown() const { + return _linkedChat.has_value(); } void ChannelData::setMembersCount(int newMembersCount) { diff --git a/Telegram/SourceFiles/data/data_channel.h b/Telegram/SourceFiles/data/data_channel.h index 288f13dd3..ffeeec06e 100644 --- a/Telegram/SourceFiles/data/data_channel.h +++ b/Telegram/SourceFiles/data/data_channel.h @@ -312,6 +312,7 @@ public: void setLinkedChat(ChannelData *linked); [[nodiscard]] ChannelData *linkedChat() const; + [[nodiscard]] bool linkedChatKnown() const; void ptsInit(int32 pts) { _ptsWaiter.init(pts); @@ -436,7 +437,7 @@ private: std::vector _unavailableReasons; std::unique_ptr _invitePeek; QString _inviteLink; - ChannelData *_linkedChat = nullptr; + std::optional _linkedChat; int _slowmodeSeconds = 0; TimeId _slowmodeLastMessage = 0; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index eab50fab5..efb7b31d2 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -745,17 +745,26 @@ int HistoryMessage::viewsCount() const { return HistoryItem::viewsCount(); } +bool HistoryMessage::checkCommentsLinkedChat(ChannelId id) const { + if (!id) { + return true; + } else if (const auto channel = history()->peer->asChannel()) { + if (channel->linkedChatKnown() + || !(channel->flags() & MTPDchannel::Flag::f_has_link)) { + const auto linked = channel->linkedChat(); + if (!linked || linked->bareId() != id) { + return false; + } + } + return true; + } + return false; +} + int HistoryMessage::repliesCount() const { if (const auto views = Get()) { - if (views->commentsChannelId) { - if (const auto channel = history()->peer->asChannel()) { - const auto linked = channel->linkedChat(); - if (!linked || linked->bareId() != views->commentsChannelId) { - return 0; - } - } else { - return 0; - } + if (!checkCommentsLinkedChat(views->commentsChannelId)) { + return 0; } return std::max(views->replies.count, 0); } @@ -764,17 +773,8 @@ int HistoryMessage::repliesCount() const { bool HistoryMessage::repliesAreComments() const { if (const auto views = Get()) { - if (!views->commentsChannelId) { - return false; - } else if (const auto channel = history()->peer->asChannel()) { - const auto linked = channel->linkedChat(); - if (!linked || linked->bareId() != views->commentsChannelId) { - return false; - } - } else { - return false; - } - return true; + return (views->commentsChannelId != 0) + && checkCommentsLinkedChat(views->commentsChannelId); } return HistoryItem::repliesAreComments(); } diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index 477bd9bba..32290ad54 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -198,6 +198,8 @@ private: return _flags & MTPDmessage::Flag::f_legacy; } + [[nodiscard]] bool checkCommentsLinkedChat(ChannelId id) const; + void clearIsolatedEmoji(); void checkIsolatedEmoji();