diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 343a381a2..b272f4b95 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -230,7 +230,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_limits_increase" = "Increase Limit"; -"lng_sticker_premium_title" = "With Effects"; "lng_sticker_premium_text" = "This pack contains premium stickers like this one."; "lng_sticker_premium_view" = "View"; "lng_reaction_premium_info" = "Click on the reaction to preview the animation."; diff --git a/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp b/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp index 6b4b0cf21..c93b01d9c 100644 --- a/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp +++ b/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp @@ -12,12 +12,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "data/data_document.h" #include "data/data_document_media.h" +#include "data/data_session.h" #include "main/main_session.h" #include "lang/lang_keys.h" #include "ui/text/text_utilities.h" #include "boxes/sticker_set_box.h" #include "lottie/lottie_single_player.h" #include "window/window_session_controller.h" +#include "apiwrap.h" #include "styles/style_chat.h" namespace HistoryView { @@ -36,7 +38,9 @@ StickerToast::StickerToast( , _destroy(std::move(destroy)) { } -StickerToast::~StickerToast() = default; +StickerToast::~StickerToast() { + cancelRequest(); +} void StickerToast::showFor(not_null document) { const auto sticker = document->sticker(); @@ -49,11 +53,76 @@ void StickerToast::showFor(not_null document) { return; } strong->hideAnimated(); + } else if (_setRequestId) { + if (_for == document) { + return; + } + cancelRequest(); } _for = document; + const auto title = lookupTitle(); + if (!title.isEmpty()) { + showWithTitle(title); + } else { + requestSet(); + } +} + +QString StickerToast::lookupTitle() const { + Expects(_for != nullptr); + + const auto sticker = _for->sticker(); + if (!sticker) { + return {}; + } + + const auto id = sticker->set.id; + if (!id) { + return {}; + } + + const auto &sets = _for->owner().stickers().sets(); + const auto i = sets.find(id); + if (i == end(sets)) { + return {}; + } + return i->second->title; +} + +void StickerToast::requestSet() { + Expects(_for != nullptr); + + if (const auto sticker = _for->sticker()) { + const auto api = &_controller->session().api(); + _setRequestId = api->request(MTPmessages_GetStickerSet( + Data::InputStickerSet(sticker->set), + MTP_int(0) // hash + )).done([=](const MTPmessages_StickerSet &result) { + _setRequestId = 0; + result.match([&](const MTPDmessages_stickerSet &data) { + data.vset().match([&](const MTPDstickerSet &data) { + const auto owner = &_controller->session().data(); + showWithTitle(owner->stickers().getSetTitle(data)); + }); + }, [&](const MTPDmessages_stickerSetNotModified &) { + LOG(("API Error: Got messages.stickerSetNotModified.")); + }); + }).fail([=] { + _setRequestId = 0; + }).send(); + } +} + +void StickerToast::cancelRequest() { + _controller->session().api().request(base::take(_setRequestId)).cancel(); +} + +void StickerToast::showWithTitle(const QString &title) { + Expects(_for != nullptr); + const auto text = Ui::Text::Bold( - tr::lng_sticker_premium_title(tr::now) + title ).append('\n').append( tr::lng_sticker_premium_text(tr::now) ); @@ -98,8 +167,8 @@ void StickerToast::showFor(not_null document) { preview->resize(size, size); preview->show(); - const auto bytes = document->createMediaView()->bytes(); - const auto filepath = document->filepath(); + const auto bytes = _for->createMediaView()->bytes(); + const auto filepath = _for->filepath(); const auto player = preview->lifetime().make_state( Lottie::ReadContent(bytes, filepath), Lottie::FrameRequest{ QSize(size, size) }, @@ -122,7 +191,7 @@ void StickerToast::showFor(not_null document) { button->setClickedCallback([=, weak = _weak] { _controller->show( - Box(_controller, document->sticker()->set), + Box(_controller, _for->sticker()->set), Ui::LayerOption::KeepOther); if (const auto strong = weak.get()) { strong->hideAnimated(); diff --git a/Telegram/SourceFiles/history/view/history_view_sticker_toast.h b/Telegram/SourceFiles/history/view/history_view_sticker_toast.h index ef2a58352..d66e728af 100644 --- a/Telegram/SourceFiles/history/view/history_view_sticker_toast.h +++ b/Telegram/SourceFiles/history/view/history_view_sticker_toast.h @@ -34,6 +34,11 @@ public: void showFor(not_null document); private: + void requestSet(); + void cancelRequest(); + void showWithTitle(const QString &title); + [[nodiscard]] QString lookupTitle() const; + const not_null _controller; const not_null _parent; style::Toast _st; @@ -41,6 +46,8 @@ private: DocumentData *_for = nullptr; Fn _destroy; + mtpRequestId _setRequestId = 0; + }; } // namespace HistoryView diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 941dc4836..7aedf7703 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 941dc48366268688f05f6260bf38ed717112ef1a +Subproject commit 7aedf7703fdf24c11375b7e67c2a6d9e16b0008b