Improve premium preview from emoji panel.

This commit is contained in:
John Preston 2022-07-22 20:37:12 +03:00
parent 19f89b1d87
commit bb8f8131e4
3 changed files with 22 additions and 6 deletions

View File

@ -65,6 +65,7 @@ struct Descriptor {
base::flat_map<QString, ReactionDisableType> disabled;
bool fromSettings = false;
Fn<void()> hiddenCallback;
Fn<void(not_null<Ui::BoxContent*>)> shownCallback;
};
bool operator==(const Descriptor &a, const Descriptor &b) {
@ -1516,7 +1517,11 @@ void Show(
const Descriptor &descriptor,
const std::shared_ptr<Data::DocumentMedia> &media,
QImage back) {
controller->show(Box(PreviewBox, controller, descriptor, media, back));
const auto box = controller->show(
Box(PreviewBox, controller, descriptor, media, back));
if (descriptor.shownCallback) {
descriptor.shownCallback(box);
}
}
void Show(not_null<Window::SessionController*> controller, QImage back) {
@ -1539,7 +1544,10 @@ void Show(
not_null<Window::SessionController*> controller,
Descriptor &&descriptor) {
if (!controller->session().premiumPossible()) {
controller->show(Box(PremiumUnavailableBox));
const auto box = controller->show(Box(PremiumUnavailableBox));
if (descriptor.shownCallback) {
descriptor.shownCallback(box);
}
return;
}
auto &list = Preloads();
@ -1616,10 +1624,12 @@ void ShowStickerPreviewBox(
void ShowPremiumPreviewBox(
not_null<Window::SessionController*> controller,
PremiumPreview section,
const base::flat_map<QString, ReactionDisableType> &disabled) {
const base::flat_map<QString, ReactionDisableType> &disabled,
Fn<void(not_null<Ui::BoxContent*>)> shown) {
Show(controller, Descriptor{
.section = section,
.disabled = disabled,
.shownCallback = std::move(shown),
});
}

View File

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class DocumentData;
namespace Ui {
class BoxContent;
class GenericBox;
class GradientButton;
} // namespace Ui
@ -55,7 +56,8 @@ enum class ReactionDisableType {
void ShowPremiumPreviewBox(
not_null<Window::SessionController*> controller,
PremiumPreview section,
const base::flat_map<QString, ReactionDisableType> &disabled = {});
const base::flat_map<QString, ReactionDisableType> &disabled = {},
Fn<void(not_null<Ui::BoxContent*>)> shown = nullptr);
void ShowPremiumPreviewToBuy(
not_null<Window::SessionController*> controller,

View File

@ -1093,7 +1093,11 @@ void EmojiListWidget::selectCustom(not_null<DocumentData*> document) {
if (document->isPremiumEmoji() && !document->session().premium()) {
ShowPremiumPreviewBox(
controller(),
PremiumPreview::AnimatedEmoji);
PremiumPreview::AnimatedEmoji,
{},
crl::guard(this, [=](not_null<Ui::BoxContent*> box) {
checkHideWithBox(box.get());
}));
return;
}
Core::App().settings().incrementRecentEmoji({ RecentEmojiDocument{
@ -1755,7 +1759,7 @@ void EmojiListWidget::initButton(
button.back = prepare(Qt::transparent, [&]() -> QBrush {
if (gradient) {
auto result = QLinearGradient(QPointF(0, 0), QPointF(width, 0));
result.setStops(Ui::Premium::ButtonGradientStops());
result.setStops(Ui::Premium::GiftGradientStops());
return result;
}
return st::emojiPanButton.textBg;