Respect can_see_list flag in reactions.

This commit is contained in:
John Preston 2021-12-21 15:29:40 +00:00
parent 118072db77
commit fe468ce7e9
9 changed files with 22 additions and 12 deletions

View File

@ -309,6 +309,10 @@ bool WhoReadExists(not_null<HistoryItem*> item) {
return true;
}
bool WhoReactedExists(not_null<HistoryItem*> item) {
return item->canViewReactions() || WhoReadExists(item);
}
rpl::producer<Ui::WhoReadContent> WhoRead(
not_null<HistoryItem*> item,
not_null<QWidget*> context,

View File

@ -20,6 +20,7 @@ struct WhoReadContent;
namespace Api {
[[nodiscard]] bool WhoReadExists(not_null<HistoryItem*> item);
[[nodiscard]] bool WhoReactedExists(not_null<HistoryItem*> item);
// The context must be destroyed before the session holding this item.
[[nodiscard]] rpl::producer<Ui::WhoReadContent> WhoRead(

View File

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

View File

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

View File

@ -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<Ui::PopupMenu>(
this,
hasWhoReadItem ? st::whoReadMenu : st::popupMenuWithIcons);

View File

@ -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<QString, int> &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())

View File

@ -396,6 +396,7 @@ public:
void toggleReaction(const QString &reaction);
void updateReactions(const MTPMessageReactions &reactions);
[[nodiscard]] const base::flat_map<QString, int> &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*> _history;
not_null<PeerData*> _from;
const not_null<PeerData*> _from;
MessageFlags _flags = 0;
void invalidateChatListEntry();

View File

@ -64,9 +64,6 @@ namespace {
if (from) {
result |= MessageFlag::HasFromId;
}
if (fwd->Has<HistoryMessageVia>()) {
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);

View File

@ -410,7 +410,7 @@ rpl::producer<int> 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();
}