From 4e9a52343f52cc8d22b22fb9f66cfc011ee002e2 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 28 Jan 2022 17:11:38 +0300 Subject: [PATCH] Process unread reactions to unknown messages. --- Telegram/SourceFiles/api/api_updates.cpp | 3 ++ .../data/data_message_reactions.cpp | 30 +++++++++++++++++++ .../SourceFiles/data/data_message_reactions.h | 5 ++++ Telegram/SourceFiles/data/data_session.cpp | 1 + 4 files changed, 39 insertions(+) diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index 9359a0d73..f2f3ea1f5 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_folder.h" #include "data/data_scheduled_messages.h" #include "data/data_send_action.h" +#include "data/data_message_reactions.h" #include "chat_helpers/emoji_interactions.h" #include "lang/lang_cloud_manager.h" #include "history/history.h" @@ -1632,6 +1633,8 @@ void Updates::feedUpdate(const MTPUpdate &update) { d.vmsg_id().v); if (item) { item->updateReactions(&d.vreactions()); + } else if (Data::Reactions::HasUnread(d.vreactions())) { + history->owner().histories().requestDialogEntry(history); } } } break; diff --git a/Telegram/SourceFiles/data/data_message_reactions.cpp b/Telegram/SourceFiles/data/data_message_reactions.cpp index 80c8a7d1a..9eeccff72 100644 --- a/Telegram/SourceFiles/data/data_message_reactions.cpp +++ b/Telegram/SourceFiles/data/data_message_reactions.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_app_config.h" #include "data/data_user.h" #include "data/data_session.h" +#include "data/data_histories.h" #include "data/data_changes.h" #include "data/data_document.h" #include "data/data_document_media.h" @@ -472,6 +473,35 @@ bool Reactions::sending(not_null item) const { return _sentRequests.contains(item->fullId()); } +bool Reactions::HasUnread(const MTPMessageReactions &data) { + return data.match([&](const MTPDmessageReactions &data) { + if (const auto &recent = data.vrecent_reactions()) { + for (const auto &one : recent->v) { + if (one.match([&](const MTPDmessagePeerReaction &data) { + return data.is_unread(); + })) { + return true; + } + } + } + return false; + }); +} + +void Reactions::CheckUnknownForUnread( + not_null owner, + const MTPMessage &message) { + message.match([&](const MTPDmessage &data) { + if (data.vreactions() && HasUnread(*data.vreactions())) { + const auto peerId = peerFromMTP(data.vpeer_id()); + if (const auto history = owner->historyLoaded(peerId)) { + owner->histories().requestDialogEntry(history); + } + } + }, [](const auto &) { + }); +} + MessageReactions::MessageReactions(not_null item) : _item(item) { } diff --git a/Telegram/SourceFiles/data/data_message_reactions.h b/Telegram/SourceFiles/data/data_message_reactions.h index 2ab784c91..555828dad 100644 --- a/Telegram/SourceFiles/data/data_message_reactions.h +++ b/Telegram/SourceFiles/data/data_message_reactions.h @@ -68,6 +68,11 @@ public: void updateAllInHistory(not_null peer, bool enabled); + [[nodiscard]] static bool HasUnread(const MTPMessageReactions &data); + static void CheckUnknownForUnread( + not_null owner, + const MTPMessage &message); + private: struct ImageSet { QImage bottomInfo; diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index a138442e8..34b435a6a 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -1872,6 +1872,7 @@ void Session::updateEditedMessage(const MTPMessage &data) { return message(peerFromMTP(data.vpeer_id()), data.vid().v); }); if (!existing) { + Reactions::CheckUnknownForUnread(this, data); return; } if (existing->isLocalUpdateMedia() && data.type() == mtpc_message) {