diff --git a/Telegram/SourceFiles/api/api_attached_stickers.cpp b/Telegram/SourceFiles/api/api_attached_stickers.cpp index fcdfe7721..dc38822da 100644 --- a/Telegram/SourceFiles/api/api_attached_stickers.cpp +++ b/Telegram/SourceFiles/api/api_attached_stickers.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "boxes/sticker_set_box.h" #include "boxes/stickers_box.h" +#include "data/data_document.h" #include "data/data_photo.h" #include "lang/lang_keys.h" #include "window/window_session_controller.h" @@ -21,15 +22,14 @@ AttachedStickers::AttachedStickers(not_null api) : _api(&api->instance()) { } -void AttachedStickers::requestAttachedStickerSets( +void AttachedStickers::request( not_null controller, - not_null photo) { + MTPmessages_GetAttachedStickers &&mtpRequest) { const auto weak = base::make_weak(controller.get()); _api.request(_requestId).cancel(); _requestId = _api.request( - MTPmessages_GetAttachedStickers( - MTP_inputStickeredMediaPhoto(photo->mtpInput()) - )).done([=](const MTPVector &result) { + std::move(mtpRequest) + ).done([=](const MTPVector &result) { _requestId = 0; const auto strongController = weak.get(); if (!strongController) { @@ -61,4 +61,22 @@ void AttachedStickers::requestAttachedStickerSets( }).send(); } +void AttachedStickers::requestAttachedStickerSets( + not_null controller, + not_null photo) { + request( + controller, + MTPmessages_GetAttachedStickers( + MTP_inputStickeredMediaPhoto(photo->mtpInput()))); +} + +void AttachedStickers::requestAttachedStickerSets( + not_null controller, + not_null document) { + request( + controller, + MTPmessages_GetAttachedStickers( + MTP_inputStickeredMediaDocument(document->mtpInput()))); +} + } // namespace Api diff --git a/Telegram/SourceFiles/api/api_attached_stickers.h b/Telegram/SourceFiles/api/api_attached_stickers.h index bf186fef0..d0dd18bb4 100644 --- a/Telegram/SourceFiles/api/api_attached_stickers.h +++ b/Telegram/SourceFiles/api/api_attached_stickers.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/sender.h" class ApiWrap; +class DocumentData; class PhotoData; namespace Window { @@ -26,7 +27,15 @@ public: not_null controller, not_null photo); + void requestAttachedStickerSets( + not_null controller, + not_null document); + private: + void request( + not_null controller, + MTPmessages_GetAttachedStickers &&mtpRequest); + MTP::Sender _api; mtpRequestId _requestId = 0; diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index b80953ba5..56aee3cd0 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -499,7 +499,9 @@ Main::Session &DocumentData::session() const { void DocumentData::setattributes( const QVector &attributes) { - _flags &= ~(Flag::ImageType | kStreamingSupportedMask); + _flags &= ~(Flag::ImageType + | Flag::HasAttachedStickers + | kStreamingSupportedMask); _flags |= kStreamingSupportedUnknown; validateLottieSticker(); @@ -577,6 +579,7 @@ void DocumentData::setattributes( _filename = std::move(_filename).replace(ch, "_"); } }, [&](const MTPDdocumentAttributeHasStickers &data) { + _flags |= Flag::HasAttachedStickers; }); } if (type == StickerDocument @@ -1539,6 +1542,10 @@ bool DocumentData::isImage() const { return (_flags & Flag::ImageType); } +bool DocumentData::hasAttachedStickers() const { + return (_flags & Flag::HasAttachedStickers); +} + bool DocumentData::supportsStreaming() const { return (_flags & kStreamingSupportedMask) == kStreamingSupportedMaybeYes; } diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h index efd777f5e..4c065e476 100644 --- a/Telegram/SourceFiles/data/data_document.h +++ b/Telegram/SourceFiles/data/data_document.h @@ -221,6 +221,8 @@ public: [[nodiscard]] bool hasMimeType(QLatin1String mime) const; void setMimeString(const QString &mime); + [[nodiscard]] bool hasAttachedStickers() const; + [[nodiscard]] MediaKey mediaKey() const; [[nodiscard]] Storage::Cache::Key cacheKey() const; [[nodiscard]] uint8 cacheTag() const; @@ -259,6 +261,7 @@ private: ImageType = 0x08, DownloadCancelled = 0x10, LoadedInMediaCache = 0x20, + HasAttachedStickers = 0x40, }; using Flags = base::flags; friend constexpr bool is_flag_type(Flag) { return true; }; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 750a2273b..9489ea8f7 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1635,6 +1635,13 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu->addAction(lnkIsVideo ? tr::lng_context_save_video(tr::now) : (lnkIsVoice ? tr::lng_context_save_audio(tr::now) : (lnkIsAudio ? tr::lng_context_save_audio_file(tr::now) : tr::lng_context_save_file(tr::now))), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] { saveDocumentToFile(itemId, document); })); + if (document->hasAttachedStickers()) { + _menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] { + session->api().attachedStickers().requestAttachedStickerSets( + controller, + document); + }); + } }; const auto link = ClickHandler::getActive(); auto lnkPhoto = dynamic_cast(link.get()); diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 43649dbe2..38bf76a48 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -773,8 +773,15 @@ void OverlayWidget::updateActions() { if ((_document && documentContentShown()) || (_photo && _photoMedia->loaded())) { _actions.push_back({ tr::lng_mediaview_copy(tr::now), SLOT(onCopy()) }); } - if (_photo && _photo->hasAttachedStickers()) { - _actions.push_back({ tr::lng_context_attached_stickers(tr::now), SLOT(onAttachedStickers()) }); + if ((_photo && _photo->hasAttachedStickers()) + || (_document && _document->hasAttachedStickers())) { + auto member = _photo + ? SLOT(onPhotoAttachedStickers()) + : SLOT(onDocumentAttachedStickers()); + _actions.push_back({ + tr::lng_context_attached_stickers(tr::now), + std::move(member) + }); } if (_canForwardItem) { _actions.push_back({ tr::lng_mediaview_forward(tr::now), SLOT(onForward()) }); @@ -1545,7 +1552,7 @@ void OverlayWidget::onCopy() { } } -void OverlayWidget::onAttachedStickers() { +void OverlayWidget::onPhotoAttachedStickers() { if (!_session || !_photo) { return; } @@ -1559,6 +1566,20 @@ void OverlayWidget::onAttachedStickers() { close(); } +void OverlayWidget::onDocumentAttachedStickers() { + if (!_session || !_document) { + return; + } + const auto &active = _session->windows(); + if (active.empty()) { + return; + } + _session->api().attachedStickers().requestAttachedStickerSets( + active.front(), + _document); + close(); +} + auto OverlayWidget::sharedMediaType() const -> std::optional { using Type = SharedMediaType; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h index b1bbdc697..69902cfec 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h @@ -125,7 +125,8 @@ private slots: void onCopy(); void onMenuDestroy(QObject *obj); void receiveMouse(); - void onAttachedStickers(); + void onPhotoAttachedStickers(); + void onDocumentAttachedStickers(); void onDropdown();