From ec0380b250ac6fe45f56f281d55e2c48595320b9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 25 Oct 2022 12:48:48 +0400 Subject: [PATCH] Show premium tooltip on custom topic icon selection. --- .../boxes/peers/edit_forum_topic_box.cpp | 19 ++++++++++++++++--- .../chat_helpers/emoji_list_widget.cpp | 3 +++ .../chat_helpers/emoji_list_widget.h | 1 + .../view/history_view_sticker_toast.cpp | 16 +++++++++++++--- .../history/view/history_view_sticker_toast.h | 9 ++++++++- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp index 05741f9ab5..179d4756b3 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp @@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "history/history.h" #include "history/view/history_view_replies_section.h" +#include "history/view/history_view_sticker_toast.h" #include "lang/lang_keys.h" #include "info/profile/info_profile_emoji_status_panel.h" #include "window/window_session_controller.h" @@ -210,6 +211,7 @@ struct IconSelector { struct State { std::unique_ptr animation; + std::unique_ptr toast; rpl::variable iconId; QPointer button; }; @@ -242,7 +244,7 @@ struct IconSelector { const auto selector = body->add( object_ptr(body, EmojiListDescriptor{ .session = &controller->session(), - .mode = EmojiListWidget::Mode::EmojiStatus, + .mode = EmojiListWidget::Mode::TopicIcon, .controller = controller, .paused = Window::PausedIn( controller, @@ -289,6 +291,18 @@ struct IconSelector { selector->setMinimalHeight(selector->width(), height); }, body->lifetime()); + const auto showToast = [=](not_null document) { + if (!state->toast) { + state->toast = std::make_unique( + controller, + controller->widget()->bodyWidget(), + [=] { state->toast = nullptr; }); + } + state->toast->showFor( + document, + HistoryView::StickerToast::Section::TopicIcon); + }; + selector->customChosen( ) | rpl::start_with_next([=](ChatHelpers::FileChosen data) { const auto owner = &controller->session().data(); @@ -298,8 +312,7 @@ struct IconSelector { const auto premium = custom && !ranges::contains(document->owner().forumIcons().list(), id); if (premium && !controller->session().premium()) { - // #TODO forum premium promo - ShowPremiumPreviewBox(controller, PremiumPreview::EmojiStatus); + showToast(document); return; } const auto body = controller->window().widget()->bodyWidget(); diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index 9ebf2854da..d96cf61eb2 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -1254,6 +1254,9 @@ void EmojiListWidget::mouseReleaseEvent(QMouseEvent *e) { case Mode::EmojiStatus: Settings::ShowPremium(_controller, u"emoji_status"_q); break; + case Mode::TopicIcon: + Settings::ShowPremium(_controller, u"forum_topic_icon"_q); + break; } } } diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h index b76a3cb96b..5cfbf8a2df 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h @@ -63,6 +63,7 @@ class LocalStickersManager; enum class EmojiListMode { Full, + TopicIcon, EmojiStatus, FullReactions, RecentReactions, diff --git a/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp b/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp index 804d25b09e..768435bda4 100644 --- a/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp +++ b/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/premium_preview_box.h" #include "lottie/lottie_single_player.h" #include "window/window_session_controller.h" +#include "settings/settings_premium.h" #include "apiwrap.h" #include "styles/style_chat.h" @@ -50,7 +51,9 @@ StickerToast::~StickerToast() { } } -void StickerToast::showFor(not_null document) { +void StickerToast::showFor( + not_null document, + Section section) { const auto sticker = document->sticker(); if (!sticker || !document->session().premiumPossible()) { return; @@ -66,6 +69,7 @@ void StickerToast::showFor(not_null document) { cancelRequest(); } _for = document; + _section = section; const auto title = lookupTitle(); if (!title.isEmpty()) { @@ -129,8 +133,11 @@ void StickerToast::showWithTitle(const QString &title) { static auto counter = 0; const auto setType = _for->sticker()->setType; - const auto isEmoji = (setType == Data::StickersType::Emoji); - const auto toSaved = isEmoji && !(++counter % 2); + const auto isEmoji = (_section == Section::TopicIcon) + || (setType == Data::StickersType::Emoji); + const auto toSaved = isEmoji + && (_section == Section::Message) + && !(++counter % 2); const auto text = Ui::Text::Bold( title ).append('\n').append( @@ -219,6 +226,9 @@ void StickerToast::showWithTitle(const QString &title) { Window::SectionShow::Way::Forward); hideToast(); return; + } else if (_section == Section::TopicIcon) { + Settings::ShowPremium(_controller, u"forum_topic_icon"_q); + return; } const auto id = _for->sticker()->set.id; const auto &sets = _for->owner().stickers().sets(); diff --git a/Telegram/SourceFiles/history/view/history_view_sticker_toast.h b/Telegram/SourceFiles/history/view/history_view_sticker_toast.h index d91c8c7c84..75cd372e86 100644 --- a/Telegram/SourceFiles/history/view/history_view_sticker_toast.h +++ b/Telegram/SourceFiles/history/view/history_view_sticker_toast.h @@ -32,7 +32,13 @@ public: Fn destroy); ~StickerToast(); - void showFor(not_null document); + enum class Section { + Message, + TopicIcon, + }; + void showFor( + not_null document, + Section section = Section::Message); private: void requestSet(); @@ -46,6 +52,7 @@ private: const not_null _controller; const not_null _parent; + Section _section = {}; style::Toast _st; base::weak_ptr _weak; std::vector> _hiding;