diff --git a/Telegram/SourceFiles/api/api_editing.cpp b/Telegram/SourceFiles/api/api_editing.cpp index c0a67e28e2..60db338804 100644 --- a/Telegram/SourceFiles/api/api_editing.cpp +++ b/Telegram/SourceFiles/api/api_editing.cpp @@ -165,22 +165,30 @@ void EditMessageWithUploadedDocument( HistoryItem *item, const MTPInputFile &file, const std::optional &thumb, - SendOptions options) { + SendOptions options, + std::vector attachedStickers) { if (!item || !item->media() || !item->media()->document()) { return; } - const auto media = PrepareUploadedDocument(item, file, thumb); + const auto media = PrepareUploadedDocument( + item, + file, + thumb, + std::move(attachedStickers)); EditMessageWithUploadedMedia(item, options, media); } void EditMessageWithUploadedPhoto( HistoryItem *item, const MTPInputFile &file, - SendOptions options) { + SendOptions options, + std::vector attachedStickers) { if (!item || !item->media() || !item->media()->photo()) { return; } - const auto media = PrepareUploadedPhoto(file); + const auto media = PrepareUploadedPhoto( + file, + std::move(attachedStickers)); EditMessageWithUploadedMedia(item, options, media); } diff --git a/Telegram/SourceFiles/api/api_editing.h b/Telegram/SourceFiles/api/api_editing.h index 8e1e56fb23..87200cde20 100644 --- a/Telegram/SourceFiles/api/api_editing.h +++ b/Telegram/SourceFiles/api/api_editing.h @@ -31,12 +31,14 @@ void EditMessageWithUploadedDocument( HistoryItem *item, const MTPInputFile &file, const std::optional &thumb, - SendOptions options); + SendOptions options, + std::vector attachedStickers); void EditMessageWithUploadedPhoto( HistoryItem *item, const MTPInputFile &file, - SendOptions options); + SendOptions options, + std::vector attachedStickers); mtpRequestId EditCaption( not_null item, diff --git a/Telegram/SourceFiles/api/api_media.cpp b/Telegram/SourceFiles/api/api_media.cpp index 8b4275c2f3..fe79c89be4 100644 --- a/Telegram/SourceFiles/api/api_media.cpp +++ b/Telegram/SourceFiles/api/api_media.cpp @@ -73,18 +73,24 @@ MTPVector ComposeSendingDocumentAttributes( } // namespace -MTPInputMedia PrepareUploadedPhoto(const MTPInputFile &file) { +MTPInputMedia PrepareUploadedPhoto( + const MTPInputFile &file, + std::vector attachedStickers) { + const auto flags = attachedStickers.empty() + ? MTPDinputMediaUploadedPhoto::Flags(0) + : MTPDinputMediaUploadedPhoto::Flag::f_stickers; return MTP_inputMediaUploadedPhoto( - MTP_flags(0), + MTP_flags(flags), file, - MTPVector(), + MTP_vector(ranges::to(attachedStickers)), MTP_int(0)); } MTPInputMedia PrepareUploadedDocument( not_null item, const MTPInputFile &file, - const std::optional &thumb) { + const std::optional &thumb, + std::vector attachedStickers) { if (!item || !item->media() || !item->media()->document()) { return MTP_inputMediaEmpty(); } @@ -92,7 +98,8 @@ MTPInputMedia PrepareUploadedDocument( using DocFlags = MTPDinputMediaUploadedDocument::Flag; const auto flags = emptyFlag | (thumb ? DocFlags::f_thumb : emptyFlag) - | (item->groupId() ? DocFlags::f_nosound_video : emptyFlag); + | (item->groupId() ? DocFlags::f_nosound_video : emptyFlag) + | (attachedStickers.empty() ? DocFlags::f_stickers : emptyFlag); const auto document = item->media()->document(); return MTP_inputMediaUploadedDocument( MTP_flags(flags), @@ -100,7 +107,7 @@ MTPInputMedia PrepareUploadedDocument( thumb.value_or(MTPInputFile()), MTP_string(document->mimeString()), ComposeSendingDocumentAttributes(document), - MTPVector(), + MTP_vector(ranges::to(attachedStickers)), MTP_int(0)); } diff --git a/Telegram/SourceFiles/api/api_media.h b/Telegram/SourceFiles/api/api_media.h index b33dfa11e7..75a6d193b3 100644 --- a/Telegram/SourceFiles/api/api_media.h +++ b/Telegram/SourceFiles/api/api_media.h @@ -11,11 +11,14 @@ class HistoryItem; namespace Api { -MTPInputMedia PrepareUploadedPhoto(const MTPInputFile &file); +MTPInputMedia PrepareUploadedPhoto( + const MTPInputFile &file, + std::vector attachedStickers); MTPInputMedia PrepareUploadedDocument( not_null item, const MTPInputFile &file, - const std::optional &thumb); + const std::optional &thumb, + std::vector attachedStickers); } // namespace Api diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index e8d13c14e5..8bfa6f725b 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3947,9 +3947,12 @@ void ApiWrap::sendFile( void ApiWrap::sendUploadedPhoto( FullMsgId localId, const MTPInputFile &file, - Api::SendOptions options) { + Api::SendOptions options, + std::vector attachedStickers) { if (const auto item = _session->data().message(localId)) { - const auto media = Api::PrepareUploadedPhoto(file); + const auto media = Api::PrepareUploadedPhoto( + file, + std::move(attachedStickers)); if (const auto groupId = item->groupId()) { uploadAlbumMedia(item, groupId, media); } else { @@ -3962,12 +3965,17 @@ void ApiWrap::sendUploadedDocument( FullMsgId localId, const MTPInputFile &file, const std::optional &thumb, - Api::SendOptions options) { + Api::SendOptions options, + std::vector attachedStickers) { if (const auto item = _session->data().message(localId)) { if (!item->media() || !item->media()->document()) { return; } - const auto media = Api::PrepareUploadedDocument(item, file, thumb); + const auto media = Api::PrepareUploadedDocument( + item, + file, + thumb, + std::move(attachedStickers)); const auto groupId = item->groupId(); if (groupId) { uploadAlbumMedia(item, groupId, media); diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index bbf2771d66..b65ade7dad 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -410,12 +410,14 @@ public: void sendUploadedPhoto( FullMsgId localId, const MTPInputFile &file, - Api::SendOptions options); + Api::SendOptions options, + std::vector attachedStickers); void sendUploadedDocument( FullMsgId localId, const MTPInputFile &file, const std::optional &thumb, - Api::SendOptions options); + Api::SendOptions options, + std::vector attachedStickers); void cancelLocalItem(not_null item); diff --git a/Telegram/SourceFiles/editor/scene.cpp b/Telegram/SourceFiles/editor/scene.cpp index a3f4b57bb5..f4bc1e36f9 100644 --- a/Telegram/SourceFiles/editor/scene.cpp +++ b/Telegram/SourceFiles/editor/scene.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "editor/scene_item_canvas.h" #include "editor/scene_item_line.h" +#include "editor/scene_item_sticker.h" #include "ui/rp_widget.h" #include @@ -99,6 +100,18 @@ std::vector Scene::items(Qt::SortOrder order) const { return filteredItems; } +std::vector Scene::attachedStickers() const { + const auto allItems = items(); + + return ranges::views::all( + allItems + ) | ranges::views::filter([](QGraphicsItem *i) { + return i->isVisible() && (i->type() == ItemSticker::Type); + }) | ranges::views::transform([](QGraphicsItem *i) { + return qgraphicsitem_cast(i)->sticker(); + }) | ranges::to_vector; +} + Scene::~Scene() { } diff --git a/Telegram/SourceFiles/editor/scene.h b/Telegram/SourceFiles/editor/scene.h index 46b5cf111d..63710d382d 100644 --- a/Telegram/SourceFiles/editor/scene.h +++ b/Telegram/SourceFiles/editor/scene.h @@ -34,6 +34,7 @@ public: [[nodiscard]] rpl::producer<> addsItem() const; [[nodiscard]] rpl::producer<> mousePresses() const; + [[nodiscard]] std::vector attachedStickers() const; protected: void mousePressEvent(QGraphicsSceneMouseEvent *event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; diff --git a/Telegram/SourceFiles/editor/scene_item_base.h b/Telegram/SourceFiles/editor/scene_item_base.h index df61ebf134..51676e70b4 100644 --- a/Telegram/SourceFiles/editor/scene_item_base.h +++ b/Telegram/SourceFiles/editor/scene_item_base.h @@ -35,6 +35,7 @@ public: QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget) override; + int type() const override; protected: enum HandleType { None, @@ -46,7 +47,6 @@ protected: void mousePressEvent(QGraphicsSceneMouseEvent *event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; - int type() const override; QRectF innerRect() const; int size() const; diff --git a/Telegram/SourceFiles/editor/scene_item_sticker.cpp b/Telegram/SourceFiles/editor/scene_item_sticker.cpp index 0c8c2ea7dd..c92b19a295 100644 --- a/Telegram/SourceFiles/editor/scene_item_sticker.cpp +++ b/Telegram/SourceFiles/editor/scene_item_sticker.cpp @@ -85,4 +85,12 @@ void ItemSticker::paint( ItemBase::paint(p, option, w); } +MTPInputDocument ItemSticker::sticker() const { + return _document->mtpInput(); +} + +int ItemSticker::type() const { + return Type; +} + } // namespace Editor diff --git a/Telegram/SourceFiles/editor/scene_item_sticker.h b/Telegram/SourceFiles/editor/scene_item_sticker.h index 213a957068..1cd1a805e4 100644 --- a/Telegram/SourceFiles/editor/scene_item_sticker.h +++ b/Telegram/SourceFiles/editor/scene_item_sticker.h @@ -21,7 +21,7 @@ namespace Editor { class ItemSticker : public ItemBase { public: - enum { Type = ItemBase::Type + 1 }; + enum { Type = ItemBase::Type + 2 }; ItemSticker( not_null document, @@ -33,6 +33,8 @@ public: QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget) override; + MTPInputDocument sticker() const; + int type() const override; private: const not_null _document; const std::shared_ptr _mediaView; diff --git a/Telegram/SourceFiles/storage/file_upload.cpp b/Telegram/SourceFiles/storage/file_upload.cpp index 912541ed8a..3bbcbd985e 100644 --- a/Telegram/SourceFiles/storage/file_upload.cpp +++ b/Telegram/SourceFiles/storage/file_upload.cpp @@ -161,12 +161,17 @@ Uploader::Uploader(not_null api) ) | rpl::start_with_next([=](const UploadedPhoto &data) { if (data.edit) { const auto item = session->data().message(data.fullId); - Api::EditMessageWithUploadedPhoto(item, data.file, data.options); + Api::EditMessageWithUploadedPhoto( + item, + data.file, + data.options, + data.attachedStickers); } else { _api->sendUploadedPhoto( data.fullId, data.file, - data.options); + data.options, + data.attachedStickers); } }, _lifetime); @@ -178,13 +183,15 @@ Uploader::Uploader(not_null api) item, data.file, data.thumb, - data.options); + data.options, + data.attachedStickers); } else { _api->sendUploadedDocument( data.fullId, data.file, data.thumb, - data.options); + data.options, + data.attachedStickers); } }, _lifetime); @@ -448,6 +455,9 @@ void Uploader::sendNext() { : Api::SendOptions(); const auto edit = uploadingData.file && uploadingData.file->to.replaceMediaOf; + const auto attachedStickers = uploadingData.file + ? uploadingData.file->attachedStickers + : std::vector(); if (uploadingData.type() == SendMediaType::Photo) { auto photoFilename = uploadingData.filename(); if (!photoFilename.endsWith(qstr(".jpg"), Qt::CaseInsensitive)) { @@ -464,7 +474,12 @@ void Uploader::sendNext() { MTP_int(uploadingData.partsCount), MTP_string(photoFilename), MTP_bytes(md5)); - _photoReady.fire({ uploadingId, options, file, edit }); + _photoReady.fire({ + uploadingId, + options, + file, + edit, + attachedStickers }); } else if (uploadingData.type() == SendMediaType::File || uploadingData.type() == SendMediaType::ThemeFile || uploadingData.type() == SendMediaType::Audio) { @@ -502,7 +517,8 @@ void Uploader::sendNext() { options, file, thumb, - edit }); + edit, + attachedStickers }); } else if (uploadingData.type() == SendMediaType::Secure) { _secureReady.fire({ uploadingId, diff --git a/Telegram/SourceFiles/storage/file_upload.h b/Telegram/SourceFiles/storage/file_upload.h index 89e4b4e777..521adc05b9 100644 --- a/Telegram/SourceFiles/storage/file_upload.h +++ b/Telegram/SourceFiles/storage/file_upload.h @@ -33,6 +33,7 @@ struct UploadedPhoto { Api::SendOptions options; MTPInputFile file; bool edit = false; + std::vector attachedStickers; }; struct UploadedDocument { @@ -41,6 +42,7 @@ struct UploadedDocument { MTPInputFile file; std::optional thumb; bool edit = false; + std::vector attachedStickers; }; struct UploadSecureProgress { diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index d2a171bfb8..acabea47bc 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/mime_type.h" #include "base/unixtime.h" #include "base/qt_adapters.h" +#include "editor/scene.h" // Editor::Scene::attachedStickers #include "media/audio/media_audio.h" #include "media/clip/media_clip_reader.h" #include "mtproto/facade.h" @@ -952,6 +953,16 @@ void FileLoadTask::process(Args &&args) { _type = SendMediaType::File; } + if (_information) { + if (auto image = std::get_if( + &_information->media)) { + if (image->modifications.paint) { + _result->attachedStickers = + image->modifications.paint->attachedStickers(); + } + } + } + _result->type = _type; _result->filepath = _filepath; _result->content = _content; diff --git a/Telegram/SourceFiles/storage/localimageloader.h b/Telegram/SourceFiles/storage/localimageloader.h index 97974efa32..1d4d0164fa 100644 --- a/Telegram/SourceFiles/storage/localimageloader.h +++ b/Telegram/SourceFiles/storage/localimageloader.h @@ -267,6 +267,8 @@ struct FileLoadResult { PreparedPhotoThumbs photoThumbs; TextWithTags caption; + std::vector attachedStickers; + void setFileData(const QByteArray &filedata); void setThumbData(const QByteArray &thumbdata);