Show premium tooltip on custom topic icon selection.

This commit is contained in:
John Preston 2022-10-25 12:48:48 +04:00
parent c6bc7c3de1
commit ec0380b250
5 changed files with 41 additions and 7 deletions

View File

@ -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<Ui::EmojiFlyAnimation> animation;
std::unique_ptr<HistoryView::StickerToast> toast;
rpl::variable<DocumentId> iconId;
QPointer<QWidget> button;
};
@ -242,7 +244,7 @@ struct IconSelector {
const auto selector = body->add(
object_ptr<EmojiListWidget>(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<DocumentData*> document) {
if (!state->toast) {
state->toast = std::make_unique<HistoryView::StickerToast>(
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();

View File

@ -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;
}
}
}

View File

@ -63,6 +63,7 @@ class LocalStickersManager;
enum class EmojiListMode {
Full,
TopicIcon,
EmojiStatus,
FullReactions,
RecentReactions,

View File

@ -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<DocumentData*> document) {
void StickerToast::showFor(
not_null<DocumentData*> document,
Section section) {
const auto sticker = document->sticker();
if (!sticker || !document->session().premiumPossible()) {
return;
@ -66,6 +69,7 @@ void StickerToast::showFor(not_null<DocumentData*> 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();

View File

@ -32,7 +32,13 @@ public:
Fn<void()> destroy);
~StickerToast();
void showFor(not_null<DocumentData*> document);
enum class Section {
Message,
TopicIcon,
};
void showFor(
not_null<DocumentData*> document,
Section section = Section::Message);
private:
void requestSet();
@ -46,6 +52,7 @@ private:
const not_null<Window::SessionController*> _controller;
const not_null<QWidget*> _parent;
Section _section = {};
style::Toast _st;
base::weak_ptr<Ui::Toast::Instance> _weak;
std::vector<base::weak_ptr<Ui::Toast::Instance>> _hiding;