mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Correctly show premium promo for custom reactions.
This commit is contained in:
parent
a3c110dafa
commit
ebf6cea2f5
8 changed files with 75 additions and 47 deletions
|
@ -996,7 +996,7 @@ void ReactionPreview::paintEffect(QPainter &p) {
|
||||||
Data::Reactions::Type::Active);
|
Data::Reactions::Type::Active);
|
||||||
const auto count = ranges::count(list, true, &Data::Reaction::premium);
|
const auto count = ranges::count(list, true, &Data::Reaction::premium);
|
||||||
const auto rows = (count + kReactionsPerRow - 1) / kReactionsPerRow;
|
const auto rows = (count + kReactionsPerRow - 1) / kReactionsPerRow;
|
||||||
const auto inrowmax = (count + rows - 1) / rows;
|
const auto inrowmax = rows ? ((count + rows - 1) / rows) : 1;
|
||||||
const auto inrowless = (inrowmax * rows - count);
|
const auto inrowless = (inrowmax * rows - count);
|
||||||
const auto inrowmore = rows - inrowless;
|
const auto inrowmore = rows - inrowless;
|
||||||
const auto inmaxrows = inrowmore * inrowmax;
|
const auto inmaxrows = inrowmore * inrowmax;
|
||||||
|
|
|
@ -455,9 +455,7 @@ void ReactionsSettingsBox(
|
||||||
|
|
||||||
button->setClickedCallback([=, id = r.id] {
|
button->setClickedCallback([=, id = r.id] {
|
||||||
if (premium && !controller->session().premium()) {
|
if (premium && !controller->session().premium()) {
|
||||||
ShowPremiumPreviewBox(
|
ShowPremiumPreviewBox(controller, PremiumPreview::Reactions);
|
||||||
controller,
|
|
||||||
PremiumPreview::Reactions);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checkButton(button);
|
checkButton(button);
|
||||||
|
|
|
@ -826,8 +826,11 @@ void EmojiListWidget::paint(
|
||||||
const auto buttonSelected = selectedButton
|
const auto buttonSelected = selectedButton
|
||||||
? (selectedButton->section == info.section)
|
? (selectedButton->section == info.section)
|
||||||
: false;
|
: false;
|
||||||
|
const auto titleLeft = (info.premiumRequired
|
||||||
|
? st().headerLockedLeft
|
||||||
|
: st().headerLeft) - st().margin.left();
|
||||||
const auto widthForTitle = emojiRight()
|
const auto widthForTitle = emojiRight()
|
||||||
- (st().headerLeft - st().margin.left())
|
- titleLeft
|
||||||
- paintButtonGetWidth(p, info, buttonSelected, clip);
|
- paintButtonGetWidth(p, info, buttonSelected, clip);
|
||||||
if (info.section > 0 && clip.top() < info.rowsTop) {
|
if (info.section > 0 && clip.top() < info.rowsTop) {
|
||||||
p.setFont(st::emojiPanHeaderFont);
|
p.setFont(st::emojiPanHeaderFont);
|
||||||
|
@ -840,9 +843,6 @@ void EmojiListWidget::paint(
|
||||||
titleText = st::emojiPanHeaderFont->elided(titleText, widthForTitle);
|
titleText = st::emojiPanHeaderFont->elided(titleText, widthForTitle);
|
||||||
titleWidth = st::emojiPanHeaderFont->width(titleText);
|
titleWidth = st::emojiPanHeaderFont->width(titleText);
|
||||||
}
|
}
|
||||||
const auto left = (info.premiumRequired
|
|
||||||
? st().headerLockedLeft
|
|
||||||
: st().headerLeft) - st().margin.left();
|
|
||||||
const auto top = info.top + st().headerTop;
|
const auto top = info.top + st().headerTop;
|
||||||
if (info.premiumRequired) {
|
if (info.premiumRequired) {
|
||||||
st::emojiPremiumRequired.paint(
|
st::emojiPremiumRequired.paint(
|
||||||
|
@ -851,10 +851,10 @@ void EmojiListWidget::paint(
|
||||||
top,
|
top,
|
||||||
width());
|
width());
|
||||||
}
|
}
|
||||||
const auto textTop = top + st::emojiPanHeaderFont->ascent;
|
const auto textBaseline = top + st::emojiPanHeaderFont->ascent;
|
||||||
p.setFont(st::emojiPanHeaderFont);
|
p.setFont(st::emojiPanHeaderFont);
|
||||||
p.setPen(st::emojiPanHeaderFg);
|
p.setPen(st::emojiPanHeaderFg);
|
||||||
p.drawText(left, textTop, titleText);
|
p.drawText(titleLeft, textBaseline, titleText);
|
||||||
}
|
}
|
||||||
if (clip.top() + clip.height() > info.rowsTop) {
|
if (clip.top() + clip.height() > info.rowsTop) {
|
||||||
ensureLoaded(info.section);
|
ensureLoaded(info.section);
|
||||||
|
@ -1139,7 +1139,18 @@ void EmojiListWidget::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
_localSetsManager->install(id);
|
_localSetsManager->install(id);
|
||||||
} else if (_controller) {
|
} else if (_controller) {
|
||||||
_jumpedToPremium.fire({});
|
_jumpedToPremium.fire({});
|
||||||
Settings::ShowPremium(_controller, u"animated_emoji"_q);
|
switch (_mode) {
|
||||||
|
case Mode::Full:
|
||||||
|
Settings::ShowPremium(_controller, u"animated_emoji"_q);
|
||||||
|
break;
|
||||||
|
case Mode::FullReactions:
|
||||||
|
case Mode::RecentReactions:
|
||||||
|
Settings::ShowPremium(_controller, u"unique_reactions"_q);
|
||||||
|
break;
|
||||||
|
case Mode::EmojiStatus:
|
||||||
|
Settings::ShowPremium(_controller, u"emoji_status"_q);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1679,7 +1690,7 @@ int EmojiListWidget::paintButtonGetWidth(
|
||||||
remove.topLeft() + st::stickerPanRemoveSet.iconPosition,
|
remove.topLeft() + st::stickerPanRemoveSet.iconPosition,
|
||||||
width());
|
width());
|
||||||
}
|
}
|
||||||
return remove.width();
|
return emojiRight() - remove.x();
|
||||||
}
|
}
|
||||||
const auto canAdd = hasAddButton(info.section);
|
const auto canAdd = hasAddButton(info.section);
|
||||||
const auto &button = rightButton(info.section);
|
const auto &button = rightButton(info.section);
|
||||||
|
@ -1704,7 +1715,7 @@ int EmojiListWidget::paintButtonGetWidth(
|
||||||
+ st::emojiPanButton.textTop
|
+ st::emojiPanButton.textTop
|
||||||
+ st::emojiPanButton.font->ascent),
|
+ st::emojiPanButton.font->ascent),
|
||||||
button.text);
|
button.text);
|
||||||
return rect.width();
|
return emojiRight() - rect.x();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmojiListWidget::eventHook(QEvent *e) {
|
bool EmojiListWidget::eventHook(QEvent *e) {
|
||||||
|
|
|
@ -184,18 +184,21 @@ Reactions::Reactions(not_null<Session*> owner)
|
||||||
_repaintItems.remove(item);
|
_repaintItems.remove(item);
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
|
|
||||||
rpl::single(rpl::empty) | rpl::then(
|
crl::on_main(&owner->session(), [=] {
|
||||||
_owner->session().mtp().config().updates()
|
// applyFavorite accesses not yet constructed parts of session.
|
||||||
) | rpl::map([=] {
|
rpl::single(rpl::empty) | rpl::then(
|
||||||
const auto &config = _owner->session().mtp().configValues();
|
_owner->session().mtp().config().updates()
|
||||||
return config.reactionDefaultCustom
|
) | rpl::map([=] {
|
||||||
? ReactionId{ DocumentId(config.reactionDefaultCustom) }
|
const auto &config = _owner->session().mtp().configValues();
|
||||||
: ReactionId{ config.reactionDefaultEmoji };
|
return config.reactionDefaultCustom
|
||||||
}) | rpl::filter([=](const ReactionId &id) {
|
? ReactionId{ DocumentId(config.reactionDefaultCustom) }
|
||||||
return !_saveFaveRequestId;
|
: ReactionId{ config.reactionDefaultEmoji };
|
||||||
}) | rpl::start_with_next([=](ReactionId &&id) {
|
}) | rpl::filter([=](const ReactionId &id) {
|
||||||
applyFavorite(id);
|
return !_saveFaveRequestId;
|
||||||
}, _lifetime);
|
}) | rpl::start_with_next([=](ReactionId &&id) {
|
||||||
|
applyFavorite(id);
|
||||||
|
}, _lifetime);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Reactions::~Reactions() = default;
|
Reactions::~Reactions() = default;
|
||||||
|
|
|
@ -464,11 +464,15 @@ HistoryInner::HistoryInner(
|
||||||
|
|
||||||
void HistoryInner::reactionChosen(const ChosenReaction &reaction) {
|
void HistoryInner::reactionChosen(const ChosenReaction &reaction) {
|
||||||
const auto item = session().data().message(reaction.context);
|
const auto item = session().data().message(reaction.context);
|
||||||
if (!item
|
if (!item) {
|
||||||
|| Window::ShowReactPremiumError(
|
return;
|
||||||
|
} else if (Window::ShowReactPremiumError(
|
||||||
_controller,
|
_controller,
|
||||||
item,
|
item,
|
||||||
reaction.id)) {
|
reaction.id)) {
|
||||||
|
if (_menu) {
|
||||||
|
_menu->hideMenu();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
item->toggleReaction(reaction.id, HistoryItem::ReactionSource::Selector);
|
item->toggleReaction(reaction.id, HistoryItem::ReactionSource::Selector);
|
||||||
|
@ -1943,9 +1947,9 @@ void HistoryInner::toggleFavoriteReaction(not_null<Element*> view) const {
|
||||||
const auto item = view->data();
|
const auto item = view->data();
|
||||||
const auto favorite = session().data().reactions().favoriteId();
|
const auto favorite = session().data().reactions().favoriteId();
|
||||||
if (!ranges::contains(
|
if (!ranges::contains(
|
||||||
Data::LookupPossibleReactions(item).recent,
|
Data::LookupPossibleReactions(item).recent,
|
||||||
favorite,
|
favorite,
|
||||||
&Data::Reaction::id)
|
&Data::Reaction::id)
|
||||||
|| Window::ShowReactPremiumError(_controller, item, favorite)) {
|
|| Window::ShowReactPremiumError(_controller, item, favorite)) {
|
||||||
return;
|
return;
|
||||||
} else if (!ranges::contains(item->chosenReactions(), favorite)) {
|
} else if (!ranges::contains(item->chosenReactions(), favorite)) {
|
||||||
|
|
|
@ -357,11 +357,15 @@ ListWidget::ListWidget(
|
||||||
_reactionsManager->updateButton({});
|
_reactionsManager->updateButton({});
|
||||||
|
|
||||||
const auto item = session().data().message(reaction.context);
|
const auto item = session().data().message(reaction.context);
|
||||||
if (!item
|
if (!item) {
|
||||||
|| Window::ShowReactPremiumError(
|
return;
|
||||||
_controller,
|
} else if (Window::ShowReactPremiumError(
|
||||||
item,
|
_controller,
|
||||||
reaction.id)) {
|
item,
|
||||||
|
reaction.id)) {
|
||||||
|
if (_menu) {
|
||||||
|
_menu->hideMenu();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
item->toggleReaction(
|
item->toggleReaction(
|
||||||
|
|
|
@ -19,7 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "chat_helpers/emoji_list_widget.h"
|
#include "chat_helpers/emoji_list_widget.h"
|
||||||
#include "chat_helpers/stickers_list_footer.h"
|
#include "chat_helpers/stickers_list_footer.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "settings/settings_premium.h"
|
#include "boxes/premium_preview_box.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "base/call_delayed.h"
|
#include "base/call_delayed.h"
|
||||||
|
@ -515,7 +515,14 @@ void Selector::expand() {
|
||||||
}
|
}
|
||||||
_expandScheduled = true;
|
_expandScheduled = true;
|
||||||
const auto parent = parentWidget()->geometry();
|
const auto parent = parentWidget()->geometry();
|
||||||
const auto additionalBottom = parent.height() - y() - height();
|
const auto extents = extentsForShadow();
|
||||||
|
const auto heightLimit = _reactions.customAllowed
|
||||||
|
? st::emojiPanMaxHeight
|
||||||
|
: minimalHeight();
|
||||||
|
const auto willBeHeight = std::min(
|
||||||
|
parent.height() - y(),
|
||||||
|
extents.top() + heightLimit + extents.bottom());
|
||||||
|
const auto additionalBottom = willBeHeight - height();
|
||||||
const auto additional = _specialExpandTopSkip + additionalBottom;
|
const auto additional = _specialExpandTopSkip + additionalBottom;
|
||||||
const auto strong = _parentController.get();
|
const auto strong = _parentController.get();
|
||||||
if (additionalBottom < 0 || additional <= 0 || !strong) {
|
if (additionalBottom < 0 || additional <= 0 || !strong) {
|
||||||
|
@ -627,9 +634,14 @@ void Selector::createList(not_null<Window::SessionController*> controller) {
|
||||||
})
|
})
|
||||||
).data();
|
).data();
|
||||||
|
|
||||||
_list->customChosen(
|
rpl::merge(
|
||||||
) | rpl::start_with_next([=](const TabbedSelector::FileChosen &chosen) {
|
_list->customChosen(
|
||||||
const auto id = DocumentId{ chosen.document->id };
|
) | rpl::map([=](const TabbedSelector::FileChosen &chosen) {
|
||||||
|
return chosen.document;
|
||||||
|
}),
|
||||||
|
_list->premiumChosen()
|
||||||
|
) | rpl::start_with_next([=](not_null<DocumentData*> document) {
|
||||||
|
const auto id = DocumentId{ document->id };
|
||||||
const auto i = defaultReactionIds.find(id);
|
const auto i = defaultReactionIds.find(id);
|
||||||
if (i != end(defaultReactionIds)) {
|
if (i != end(defaultReactionIds)) {
|
||||||
_chosen.fire({ .id = { i->second } });
|
_chosen.fire({ .id = { i->second } });
|
||||||
|
@ -638,12 +650,6 @@ void Selector::createList(not_null<Window::SessionController*> controller) {
|
||||||
}
|
}
|
||||||
}, _list->lifetime());
|
}, _list->lifetime());
|
||||||
|
|
||||||
_list->premiumChosen(
|
|
||||||
) | rpl::start_with_next([=] {
|
|
||||||
_jumpedToPremium();
|
|
||||||
Settings::ShowPremium(controller, u"animated_emoji"_q);
|
|
||||||
}, _list->lifetime());
|
|
||||||
|
|
||||||
_list->jumpedToPremium(
|
_list->jumpedToPremium(
|
||||||
) | rpl::start_with_next(_jumpedToPremium, _list->lifetime());
|
) | rpl::start_with_next(_jumpedToPremium, _list->lifetime());
|
||||||
|
|
||||||
|
|
|
@ -375,7 +375,9 @@ bool ShowReactPremiumError(
|
||||||
Data::Reactions::Type::Active);
|
Data::Reactions::Type::Active);
|
||||||
const auto i = ranges::find(list, id, &Data::Reaction::id);
|
const auto i = ranges::find(list, id, &Data::Reaction::id);
|
||||||
if (i == end(list) || !i->premium) {
|
if (i == end(list) || !i->premium) {
|
||||||
return false;
|
if (!id.custom()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ShowPremiumPreviewBox(
|
ShowPremiumPreviewBox(
|
||||||
controller,
|
controller,
|
||||||
|
|
Loading…
Add table
Reference in a new issue