From 7cd6b821b3ec7fa06e4f5e4171697a7b7be36a57 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 31 Mar 2021 00:00:48 +0300 Subject: [PATCH] Fixed update of recently attached stickers after sending. --- Telegram/SourceFiles/api/api_editing.cpp | 8 ++++++++ Telegram/SourceFiles/api/api_media.cpp | 12 ++++++++++++ Telegram/SourceFiles/api/api_media.h | 2 ++ Telegram/SourceFiles/apiwrap.cpp | 6 ++++++ Telegram/SourceFiles/data/stickers/data_stickers.cpp | 1 - 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/api/api_editing.cpp b/Telegram/SourceFiles/api/api_editing.cpp index 60db33880..3e4f98ae8 100644 --- a/Telegram/SourceFiles/api/api_editing.cpp +++ b/Telegram/SourceFiles/api/api_editing.cpp @@ -52,6 +52,10 @@ mtpRequestId EditMessage( ConvertOption::SkipLocal); const auto media = item->media(); + const auto updateRecentStickers = inputMedia.has_value() + ? Api::HasAttachedStickers(*inputMedia) + : false; + const auto emptyFlag = MTPmessages_EditMessage::Flag(0); const auto flags = emptyFlag | (!text.isEmpty() || media @@ -97,6 +101,10 @@ mtpRequestId EditMessage( } else { apply(); } + + if (updateRecentStickers) { + api->requestRecentStickersForce(true); + } }).fail( fail ).send(); diff --git a/Telegram/SourceFiles/api/api_media.cpp b/Telegram/SourceFiles/api/api_media.cpp index fe79c89be..f99848b0a 100644 --- a/Telegram/SourceFiles/api/api_media.cpp +++ b/Telegram/SourceFiles/api/api_media.cpp @@ -111,4 +111,16 @@ MTPInputMedia PrepareUploadedDocument( MTP_int(0)); } +bool HasAttachedStickers(MTPInputMedia media) { + return media.match([&](const MTPDinputMediaUploadedPhoto &photo) -> bool { + return (photo.vflags().v + & MTPDinputMediaUploadedPhoto::Flag::f_stickers); + }, [&](const MTPDinputMediaUploadedDocument &document) -> bool { + return (document.vflags().v + & MTPDinputMediaUploadedDocument::Flag::f_stickers); + }, [](const auto &d) { + return false; + }); +} + } // namespace Api diff --git a/Telegram/SourceFiles/api/api_media.h b/Telegram/SourceFiles/api/api_media.h index 75a6d193b..d9dbaefb2 100644 --- a/Telegram/SourceFiles/api/api_media.h +++ b/Telegram/SourceFiles/api/api_media.h @@ -21,4 +21,6 @@ MTPInputMedia PrepareUploadedDocument( const std::optional &thumb, std::vector attachedStickers); +bool HasAttachedStickers(MTPInputMedia media); + } // namespace Api diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index dd59fca25..4102b5ac6 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -4521,6 +4521,8 @@ void ApiWrap::sendMediaWithRandomId( caption.entities, Api::ConvertOption::SkipLocal); + const auto updateRecentStickers = Api::HasAttachedStickers(media); + const auto flags = MTPmessages_SendMedia::Flags(0) | (replyTo ? MTPmessages_SendMedia::Flag::f_reply_to_msg_id @@ -4553,6 +4555,10 @@ void ApiWrap::sendMediaWithRandomId( )).done([=](const MTPUpdates &result) { applyUpdates(result); finish(); + + if (updateRecentStickers) { + requestRecentStickersForce(true); + } }).fail([=](const MTP::Error &error) { sendMessageFail(error, peer, randomId, itemId); finish(); diff --git a/Telegram/SourceFiles/data/stickers/data_stickers.cpp b/Telegram/SourceFiles/data/stickers/data_stickers.cpp index a8b80af5d..7aedbf08a 100644 --- a/Telegram/SourceFiles/data/stickers/data_stickers.cpp +++ b/Telegram/SourceFiles/data/stickers/data_stickers.cpp @@ -110,7 +110,6 @@ rpl::producer Stickers::stickerSetInstalled() const { return _stickerSetInstalled.events(); } -// Increment attached sticker. void Stickers::incrementSticker(not_null document) { if (!document->sticker() || document->sticker()->set.type() == mtpc_inputStickerSetEmpty) {