Show comments button using 'has_link' flag.

This commit is contained in:
John Preston 2020-09-10 14:56:46 +03:00
parent 01ab6e6d4d
commit 47170da813
4 changed files with 29 additions and 22 deletions

View file

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

View file

@ -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<Data::UnavailableReason> _unavailableReasons;
std::unique_ptr<InvitePeek> _invitePeek;
QString _inviteLink;
ChannelData *_linkedChat = nullptr;
std::optional<ChannelData*> _linkedChat;
int _slowmodeSeconds = 0;
TimeId _slowmodeLastMessage = 0;

View file

@ -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<HistoryMessageViews>()) {
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<HistoryMessageViews>()) {
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();
}

View file

@ -198,6 +198,8 @@ private:
return _flags & MTPDmessage::Flag::f_legacy;
}
[[nodiscard]] bool checkCommentsLinkedChat(ChannelId id) const;
void clearIsolatedEmoji();
void checkIsolatedEmoji();