From 84f561b251c8f96aa48276953692a0b7e9ee6c15 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 4 Oct 2021 08:46:12 +0400 Subject: [PATCH] Don't use MTP* in the image editor. --- Telegram/SourceFiles/editor/scene/scene.cpp | 4 ++-- Telegram/SourceFiles/editor/scene/scene.h | 3 ++- Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp | 4 ++-- Telegram/SourceFiles/editor/scene/scene_item_sticker.h | 4 +++- Telegram/SourceFiles/storage/localimageloader.cpp | 7 +++++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/editor/scene/scene.cpp b/Telegram/SourceFiles/editor/scene/scene.cpp index 4a878b85c..923d44250 100644 --- a/Telegram/SourceFiles/editor/scene/scene.cpp +++ b/Telegram/SourceFiles/editor/scene/scene.cpp @@ -46,7 +46,7 @@ void Scene::cancelDrawing() { _canvas->cancelDrawing(); } -void Scene::addItem(std::shared_ptr item) { +void Scene::addItem(ItemPtr item) { if (!item) { return; } @@ -120,7 +120,7 @@ std::vector Scene::items( return copyItems; } -std::vector Scene::attachedStickers() const { +std::vector> Scene::attachedStickers() const { const auto allItems = items(); return ranges::views::all( diff --git a/Telegram/SourceFiles/editor/scene/scene.h b/Telegram/SourceFiles/editor/scene/scene.h index bbee707d3..2c9354f6f 100644 --- a/Telegram/SourceFiles/editor/scene/scene.h +++ b/Telegram/SourceFiles/editor/scene/scene.h @@ -39,7 +39,8 @@ public: [[nodiscard]] rpl::producer<> addsItem() const; [[nodiscard]] rpl::producer<> removesItem() const; - [[nodiscard]] std::vector attachedStickers() const; + [[nodiscard]] auto attachedStickers() const + -> std::vector>; [[nodiscard]] std::shared_ptr lastZ() const; diff --git a/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp b/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp index 58136b6c4..1075db0a7 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp +++ b/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp @@ -95,8 +95,8 @@ void ItemSticker::paint( ItemBase::paint(p, option, w); } -MTPInputDocument ItemSticker::sticker() const { - return _document->mtpInput(); +not_null ItemSticker::sticker() const { + return _document; } int ItemSticker::type() const { diff --git a/Telegram/SourceFiles/editor/scene/scene_item_sticker.h b/Telegram/SourceFiles/editor/scene/scene_item_sticker.h index e8bb3078a..201aeb2a5 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_sticker.h +++ b/Telegram/SourceFiles/editor/scene/scene_item_sticker.h @@ -30,11 +30,13 @@ public: QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget) override; - MTPInputDocument sticker() const; + [[nodiscard]] not_null sticker() const; int type() const override; + protected: void performFlip() override; std::shared_ptr duplicate(ItemBase::Data data) const override; + private: const not_null _document; const std::shared_ptr<::Data::DocumentMedia> _mediaView; diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index 1538875a8..3c1440b96 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -1007,8 +1007,11 @@ void FileLoadTask::process(Args &&args) { if (auto image = std::get_if( &_information->media)) { if (image->modifications.paint) { - _result->attachedStickers = - image->modifications.paint->attachedStickers(); + const auto documents + = image->modifications.paint->attachedStickers(); + _result->attachedStickers = documents + | ranges::view::transform(&DocumentData::mtpInput) + | ranges::to_vector; } } }