From aafc24008b9d152c92bd9070415b2571b37c44ac Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 28 Dec 2021 19:34:40 +0300 Subject: [PATCH] Apply reactions from message edit updates. --- Telegram/SourceFiles/api/api_sending.cpp | 1 + Telegram/SourceFiles/api/api_updates.cpp | 2 +- Telegram/SourceFiles/history/history_item.cpp | 9 +++++++-- Telegram/SourceFiles/history/history_item.h | 2 +- Telegram/SourceFiles/history/history_item_edition.cpp | 1 + Telegram/SourceFiles/history/history_item_edition.h | 2 ++ Telegram/SourceFiles/history/history_message.cpp | 5 ++++- Telegram/SourceFiles/history/history_service.cpp | 2 +- 8 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/api/api_sending.cpp b/Telegram/SourceFiles/api/api_sending.cpp index fea8defacc..0a97d3e4f8 100644 --- a/Telegram/SourceFiles/api/api_sending.cpp +++ b/Telegram/SourceFiles/api/api_sending.cpp @@ -452,6 +452,7 @@ void SendConfirmedFile( edition.textWithEntities = caption; edition.useSameMarkup = true; edition.useSameReplies = true; + edition.useSameReactions = true; itemToEdit->applyEdition(std::move(edition)); } else { const auto viaBotId = UserId(); diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index 11a4651583..17e0b1e0bd 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -1625,7 +1625,7 @@ void Updates::feedUpdate(const MTPUpdate &update) { peer, d.vmsg_id().v); if (item) { - item->updateReactions(d.vreactions()); + item->updateReactions(&d.vreactions()); } } } break; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 629fec6842..ea491fd666 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -772,8 +772,13 @@ void HistoryItem::toggleReaction(const QString &reaction) { history()->owner().notifyItemDataChange(this); } -void HistoryItem::updateReactions(const MTPMessageReactions &reactions) { - reactions.match([&](const MTPDmessageReactions &data) { +void HistoryItem::updateReactions(const MTPMessageReactions *reactions) { + if (!reactions) { + _flags &= ~MessageFlag::CanViewReactions; + _reactions = nullptr; + return; + } + reactions->match([&](const MTPDmessageReactions &data) { if (data.is_can_see_list()) { _flags |= MessageFlag::CanViewReactions; } else { diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index e497403817..25d6aa20cc 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -363,7 +363,7 @@ public: [[nodiscard]] bool canReact() const; void addReaction(const QString &reaction); void toggleReaction(const QString &reaction); - void updateReactions(const MTPMessageReactions &reactions); + void updateReactions(const MTPMessageReactions *reactions); [[nodiscard]] const base::flat_map &reactions() const; [[nodiscard]] bool canViewReactions() const; [[nodiscard]] QString chosenReaction() const; diff --git a/Telegram/SourceFiles/history/history_item_edition.cpp b/Telegram/SourceFiles/history/history_item_edition.cpp index 78935394ad..a9bfd1125c 100644 --- a/Telegram/SourceFiles/history/history_item_edition.cpp +++ b/Telegram/SourceFiles/history/history_item_edition.cpp @@ -23,6 +23,7 @@ HistoryMessageEdition::HistoryMessageEdition( }; replyMarkup = HistoryMessageMarkupData(message.vreply_markup()); mtpMedia = message.vmedia(); + mtpReactions = message.vreactions(); views = message.vviews().value_or(-1); forwards = message.vforwards().value_or(-1); if (const auto mtpReplies = message.vreplies()) { diff --git a/Telegram/SourceFiles/history/history_item_edition.h b/Telegram/SourceFiles/history/history_item_edition.h index 8bc25a1d59..10afd3fa39 100644 --- a/Telegram/SourceFiles/history/history_item_edition.h +++ b/Telegram/SourceFiles/history/history_item_edition.h @@ -26,8 +26,10 @@ struct HistoryMessageEdition { int ttl = 0; bool useSameReplies = false; bool useSameMarkup = false; + bool useSameReactions = false; TextWithEntities textWithEntities; HistoryMessageMarkupData replyMarkup; HistoryMessageRepliesData replies; const MTPMessageMedia *mtpMedia = nullptr; + const MTPMessageReactions *mtpReactions = nullptr; }; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 6b38ac24b7..41ea47a613 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -511,7 +511,7 @@ HistoryMessage::HistoryMessage( MessageGroupId::FromRaw(history->peer->id, groupedId->v)); } if (const auto reactions = data.vreactions()) { - updateReactions(*reactions); + updateReactions(reactions); } applyTTL(data); @@ -1414,6 +1414,9 @@ void HistoryMessage::applyEdition(HistoryMessageEdition &&edition) { if (!isLocalUpdateMedia()) { refreshMedia(edition.mtpMedia); } + if (!edition.useSameReactions) { + updateReactions(edition.mtpReactions); + } changeViewsCount(edition.views); setForwardsCount(edition.forwards); setText(_media diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 9c0361e6c3..cd7f94113d 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -1076,7 +1076,7 @@ void HistoryService::createFromMtp(const MTPDmessage &message) { } if (const auto reactions = message.vreactions()) { - updateReactions(*reactions); + updateReactions(reactions); } }