From fe468ce7e9447f9f0ef9f69601a856f465496ee8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 21 Dec 2021 15:29:40 +0000 Subject: [PATCH] Respect can_see_list flag in reactions. --- Telegram/SourceFiles/api/api_who_read.cpp | 4 ++++ Telegram/SourceFiles/api/api_who_read.h | 1 + Telegram/SourceFiles/apiwrap.cpp | 3 --- Telegram/SourceFiles/data/data_types.h | 2 +- .../SourceFiles/history/history_inner_widget.cpp | 2 +- Telegram/SourceFiles/history/history_item.cpp | 12 +++++++++++- Telegram/SourceFiles/history/history_item.h | 3 ++- Telegram/SourceFiles/history/history_message.cpp | 5 +---- .../SourceFiles/info/profile/info_profile_values.cpp | 2 +- 9 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/api/api_who_read.cpp b/Telegram/SourceFiles/api/api_who_read.cpp index 40f659c955..6735facfeb 100644 --- a/Telegram/SourceFiles/api/api_who_read.cpp +++ b/Telegram/SourceFiles/api/api_who_read.cpp @@ -309,6 +309,10 @@ bool WhoReadExists(not_null item) { return true; } +bool WhoReactedExists(not_null item) { + return item->canViewReactions() || WhoReadExists(item); +} + rpl::producer WhoRead( not_null item, not_null context, diff --git a/Telegram/SourceFiles/api/api_who_read.h b/Telegram/SourceFiles/api/api_who_read.h index 9ea7f30516..d77e247898 100644 --- a/Telegram/SourceFiles/api/api_who_read.h +++ b/Telegram/SourceFiles/api/api_who_read.h @@ -20,6 +20,7 @@ struct WhoReadContent; namespace Api { [[nodiscard]] bool WhoReadExists(not_null item); +[[nodiscard]] bool WhoReactedExists(not_null item); // The context must be destroyed before the session holding this item. [[nodiscard]] rpl::producer WhoRead( diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 778d1e8a1d..0bb6038a5f 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3687,9 +3687,6 @@ void ApiWrap::sendInlineResult( if (silentPost) { sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_silent; } - if (bot) { - flags |= MessageFlag::HasViaBot; - } if (action.options.scheduled) { flags |= MessageFlag::IsOrWasScheduled; sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_schedule_date; diff --git a/Telegram/SourceFiles/data/data_types.h b/Telegram/SourceFiles/data/data_types.h index 1bb5f0db63..4c3c5629d3 100644 --- a/Telegram/SourceFiles/data/data_types.h +++ b/Telegram/SourceFiles/data/data_types.h @@ -227,7 +227,7 @@ enum class MessageFlag : uint32 { HasPostAuthor = (1U << 4), HasViews = (1U << 5), HasReplyInfo = (1U << 6), - HasViaBot = (1U << 7), + CanViewReactions = (1U << 7), AdminLogEntry = (1U << 8), Post = (1U << 9), Silent = (1U << 10), diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 526298c006..616bc26704 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1702,7 +1702,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } const auto hasWhoReadItem = _dragStateItem - && Api::WhoReadExists(_dragStateItem); + && Api::WhoReactedExists(_dragStateItem); _menu = base::make_unique_q( this, hasWhoReadItem ? st::whoReadMenu : st::popupMenuWithIcons); diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 07287c302d..c4a31b4395 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -773,6 +773,11 @@ void HistoryItem::toggleReaction(const QString &reaction) { void HistoryItem::updateReactions(const MTPMessageReactions &reactions) { reactions.match([&](const MTPDmessageReactions &data) { + if (data.is_can_see_list()) { + _flags |= MessageFlag::CanViewReactions; + } else { + _flags &= ~MessageFlag::CanViewReactions; + } if (data.vresults().v.isEmpty()) { _reactions = nullptr; return; @@ -789,6 +794,12 @@ const base::flat_map &HistoryItem::reactions() const { return _reactions ? _reactions->list() : kEmpty; } +bool HistoryItem::canViewReactions() const { + return (_flags & MessageFlag::CanViewReactions) + && _reactions + && !_reactions->list().empty(); +} + QString HistoryItem::chosenReaction() const { return _reactions ? _reactions->chosen() : QString(); } @@ -1138,7 +1149,6 @@ MessageFlags FlagsFromMTP( | ((flags & MTP::f_edit_hide) ? Flag::HideEdited : Flag()) | ((flags & MTP::f_pinned) ? Flag::Pinned : Flag()) | ((flags & MTP::f_from_id) ? Flag::HasFromId : Flag()) - | ((flags & MTP::f_via_bot_id) ? Flag::HasViaBot : Flag()) | ((flags & MTP::f_reply_to) ? Flag::HasReplyInfo : Flag()) | ((flags & MTP::f_reply_markup) ? Flag::HasReplyMarkup : Flag()) | ((flags & MTP::f_from_scheduled) ? Flag::IsOrWasScheduled : Flag()) diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 25fb45df44..345f9eada7 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -396,6 +396,7 @@ public: void toggleReaction(const QString &reaction); void updateReactions(const MTPMessageReactions &reactions); [[nodiscard]] const base::flat_map &reactions() const; + [[nodiscard]] bool canViewReactions() const; [[nodiscard]] QString chosenReaction() const; [[nodiscard]] bool hasDirectLink() const; @@ -476,7 +477,7 @@ protected: void finishEditionToEmpty(); const not_null _history; - not_null _from; + const not_null _from; MessageFlags _flags = 0; void invalidateChatListEntry(); diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 757bdeb878..3b380d248c 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -64,9 +64,6 @@ namespace { if (from) { result |= MessageFlag::HasFromId; } - if (fwd->Has()) { - result |= MessageFlag::HasViaBot; - } if (const auto media = fwd->media()) { if ((!peer->isChannel() || peer->isMegagroup()) && media->forwardedBecomesUnread()) { @@ -777,7 +774,7 @@ void HistoryMessage::createComponentsHelper( const QString &postAuthor, HistoryMessageMarkupData &&markup) { auto config = CreateConfig(); - if (flags & MessageFlag::HasViaBot) config.viaBotId = viaBotId; + config.viaBotId = viaBotId; if (flags & MessageFlag::HasReplyInfo) { config.replyTo = replyTo; const auto replyToTop = LookupReplyToTop(history(), replyTo); diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index 61e31dd409..7074def566 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -410,7 +410,7 @@ rpl::producer FullReactionsCountValue( ) | rpl::then( reactions->updates() ) | rpl::map([=] { - return int(reactions->list().size()); + return int(reactions->list(Data::Reactions::Type::Active).size()); }) | rpl::distinct_until_changed(); }