Remove legacy premium reactions code.

This commit is contained in:
John Preston 2024-01-26 17:10:51 +04:00
parent 6f57302562
commit 87df90227e
15 changed files with 18 additions and 139 deletions

View file

@ -520,11 +520,6 @@ void ReactionsSettingsBox(
rpl::single<QString>(base::duplicate(r.title)),
st::settingsButton));
const auto premium = r.premium;
if (premium && !premiumPossible) {
continue;
}
const auto iconSize = st::settingsReactionSize;
const auto left = button->st().iconLeft;
auto iconPositionValue = button->sizeValue(
@ -556,12 +551,6 @@ void ReactionsSettingsBox(
&button->lifetime());
}
button->setClickedCallback([=, id = r.id] {
if (premium && !controller->session().premium()) {
ShowPremiumPreviewBox(
controller,
PremiumPreview::InfiniteReactions);
return;
}
checkButton(button);
state->selectedId = id;
});

View file

@ -71,7 +71,6 @@ ComposeIcons {
menuSpoilerOff: icon;
stripBubble: icon;
stripPremiumLocked: icon;
stripExpandPanel: icon;
stripExpandDropdown: icon;
}
@ -609,10 +608,6 @@ defaultComposeIcons: ComposeIcons {
{ "chat/reactions_bubble_shadow", windowShadowFg },
{ "chat/reactions_bubble", windowBg },
};
stripPremiumLocked: icon{
{ "chat/reactions_premium_bg", historyPeerArchiveUserpicBg },
{ "chat/reactions_premium_star", historyPeerUserpicFg },
};
stripExpandPanel: icon{
{ "chat/reactions_round_big", windowBgRipple },
{ "chat/reactions_expand_panel", windowSubTextFg },

View file

@ -209,13 +209,6 @@ PossibleItemReactionsRef LookupPossibleReactions(
} else if (id.custom()
&& allowed.type == AllowedReactionsType::Default) {
return false;
} else if (reaction.premium
&& !session->premium()
&& !ranges::contains(all, id, &MessageReaction::id)) {
if (premiumPossible) {
result.morePremiumAvailable = true;
}
return false;
}
return true;
});
@ -248,7 +241,6 @@ PossibleItemReactions::PossibleItemReactions(
: recent(other.recent | ranges::views::transform([](const auto &value) {
return *value;
}) | ranges::to_vector)
, morePremiumAvailable(other.morePremiumAvailable)
, customAllowed(other.customAllowed)
, tags(other.tags){
}
@ -1139,7 +1131,6 @@ std::optional<Reaction> Reactions::parse(const MTPAvailableReaction &entry) {
*data.varound_animation()).get()
: nullptr),
.active = !data.is_inactive(),
.premium = data.is_premium(),
})
: std::nullopt;
});

View file

@ -37,12 +37,10 @@ struct Reaction {
DocumentData *aroundAnimation = nullptr;
int count = 0;
bool active = false;
bool premium = false;
};
struct PossibleItemReactionsRef {
std::vector<not_null<const Reaction*>> recent;
bool morePremiumAvailable = false;
bool customAllowed = false;
bool tags = false;
};
@ -52,7 +50,6 @@ struct PossibleItemReactions {
explicit PossibleItemReactions(const PossibleItemReactionsRef &other);
std::vector<Reaction> recent;
bool morePremiumAvailable = false;
bool customAllowed = false;
bool tags = false;
};

View file

@ -386,14 +386,6 @@ HistoryInner::HistoryInner(
reactionChosen(reaction);
}, lifetime());
_reactionsManager->premiumPromoChosen(
) | rpl::start_with_next([=](FullMsgId context) {
_reactionsManager->updateButton({});
ShowPremiumPreviewBox(
_controller,
PremiumPreview::InfiniteReactions);
}, lifetime());
session().data().peerDecorationsUpdated(
) | rpl::start_with_next([=] {
update();
@ -2644,9 +2636,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
desiredPosition,
reactItem,
[=](ChosenReaction reaction) { reactionChosen(reaction); },
[=](FullMsgId context) { ShowPremiumPreviewBox(
controller,
PremiumPreview::InfiniteReactions); },
TextWithEntities(),
_controller->cachedReactionIconFactory().createMethod())
: AttachSelectorResult::Skipped;
if (attached == AttachSelectorResult::Failed) {

View file

@ -398,14 +398,6 @@ ListWidget::ListWidget(
reactionChosen(reaction);
}, lifetime());
_reactionsManager->premiumPromoChosen(
) | rpl::start_with_next([=] {
_reactionsManager->updateButton({});
ShowPremiumPreviewBox(
_controller,
PremiumPreview::InfiniteReactions);
}, lifetime());
Reactions::SetupManagerList(
_reactionsManager.get(),
_reactionsItem.value());
@ -2641,9 +2633,7 @@ void ListWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
desiredPosition,
reactItem,
[=](ChosenReaction reaction) { reactionChosen(reaction); },
[=](FullMsgId context) { ShowPremiumPreviewBox(
_controller,
PremiumPreview::InfiniteReactions); },
TextWithEntities(),
_controller->cachedReactionIconFactory().createMethod())
: AttachSelectorResult::Skipped;
if (attached == AttachSelectorResult::Failed) {

View file

@ -448,8 +448,6 @@ void Manager::applyList(const Data::PossibleItemReactionsRef &reactions) {
reactions.recent,
(/*reactions.customAllowed
? Button::Expand
: reactions.morePremiumAvailable
? Button::Premium
: */Button::None));
_tagsStrip = reactions.tags;
}
@ -519,14 +517,7 @@ ClickHandlerPtr Manager::computeButtonLink(QPoint position) const {
int(_strip.count() - 1));
_strip.setSelected(index);
const auto selected = _strip.selected();
if (selected == Strip::AddedButton::Premium) {
if (!_premiumPromoLink) {
_premiumPromoLink = std::make_shared<LambdaClickHandler>([=] {
_premiumPromoChosen.fire_copy(_buttonContext);
});
}
return _premiumPromoLink;
} else if (selected == Strip::AddedButton::Expand) {
if (selected == Strip::AddedButton::Expand) {
if (!_expandLink) {
_expandLink = std::make_shared<LambdaClickHandler>([=] {
_expandChosen.fire_copy(_buttonContext);

View file

@ -155,9 +155,6 @@ public:
[[nodiscard]] rpl::producer<ChosenReaction> chosen() const {
return _chosen.events();
}
[[nodiscard]] rpl::producer<FullMsgId> premiumPromoChosen() const {
return _premiumPromoChosen.events();
}
[[nodiscard]] rpl::producer<FullMsgId> expandChosen() const {
return _expandChosen.events();
}
@ -227,10 +224,8 @@ private:
QColor _gradient;
rpl::event_stream<ChosenReaction> _chosen;
rpl::event_stream<FullMsgId> _premiumPromoChosen;
rpl::event_stream<FullMsgId> _expandChosen;
mutable base::flat_map<ReactionId, ClickHandlerPtr> _links;
mutable ClickHandlerPtr _premiumPromoLink;
mutable ClickHandlerPtr _expandLink;
rpl::variable<int> _uniqueLimit = 0;

View file

@ -278,8 +278,7 @@ int Selector::recentCount() const {
}
int Selector::countSkipLeft() const {
const auto addedToMax = _reactions.customAllowed
|| _reactions.morePremiumAvailable;
const auto addedToMax = _reactions.customAllowed;
const auto max = recentCount() + (addedToMax ? 1 : 0);
return std::max(
(st::reactStripMinWidth - (max * _size)) / 2,
@ -287,8 +286,7 @@ int Selector::countSkipLeft() const {
}
int Selector::countWidth(int desiredWidth, int maxWidth) {
const auto addedToMax = _reactions.customAllowed
|| _reactions.morePremiumAvailable;
const auto addedToMax = _reactions.customAllowed;
const auto max = recentCount() + (addedToMax ? 1 : 0);
const auto desiredColumns = std::max(
(desiredWidth - 2 * _skipx + _size - 1) / _size,
@ -298,13 +296,9 @@ int Selector::countWidth(int desiredWidth, int maxWidth) {
(maxWidth - 2 * _skipx) / _size);
_columns = _strip ? std::min(possibleColumns, max) : kDefaultColumns;
_small = (possibleColumns - _columns > 1);
_recentRows = (recentCount()
+ (_reactions.morePremiumAvailable ? 1 : 0)
+ _columns - 1) / _columns;
_recentRows = (recentCount() + _columns - 1) / _columns;
const auto added = (_columns < max || _reactions.customAllowed)
? Strip::AddedButton::Expand
: _reactions.morePremiumAvailable
? Strip::AddedButton::Premium
: Strip::AddedButton::None;
if (_strip) {
const auto &real = _reactions.recent;
@ -731,9 +725,7 @@ void Selector::mouseReleaseEvent(QMouseEvent *e) {
}
_pressed = -1;
const auto selected = _strip->selected();
if (selected == Strip::AddedButton::Premium) {
_premiumPromoChosen.fire({});
} else if (selected == Strip::AddedButton::Expand) {
if (selected == Strip::AddedButton::Expand) {
expand();
} else if (const auto id = std::get_if<Data::ReactionId>(&selected)) {
if (!id->empty()) {
@ -993,6 +985,7 @@ bool AdjustMenuGeometryForSelector(
return menu->prepareGeometryFor(desiredPosition);
}
#if 0 // not ready
AttachSelectorResult MakeJustSelectorMenu(
not_null<Ui::PopupMenu*> menu,
not_null<Window::SessionController*> controller,
@ -1062,6 +1055,7 @@ AttachSelectorResult MakeJustSelectorMenu(
return AttachSelectorResult::Attached;
}
#endif
AttachSelectorResult AttachSelectorToMenu(
not_null<Ui::PopupMenu*> menu,
@ -1069,7 +1063,7 @@ AttachSelectorResult AttachSelectorToMenu(
QPoint desiredPosition,
not_null<HistoryItem*> item,
Fn<void(ChosenReaction)> chosen,
Fn<void(FullMsgId)> showPremiumPromo,
TextWithEntities description,
IconFactory iconFactory) {
const auto result = AttachSelectorToMenu(
menu,
@ -1090,11 +1084,6 @@ AttachSelectorResult AttachSelectorToMenu(
chosen(std::move(reaction));
}, selector->lifetime());
selector->premiumPromoChosen() | rpl::start_with_next([=] {
menu->hideMenu();
showPremiumPromo(itemId);
}, selector->lifetime());
const auto weak = base::make_weak(controller);
controller->enableGifPauseReason(
Window::GifPauseReason::MediaPreview);
@ -1116,7 +1105,7 @@ auto AttachSelectorToMenu(
const Data::PossibleItemReactionsRef &reactions,
IconFactory iconFactory)
-> base::expected<not_null<Selector*>, AttachSelectorResult> {
if (reactions.recent.empty() && !reactions.morePremiumAvailable) {
if (reactions.recent.empty()) {
return base::make_unexpected(AttachSelectorResult::Skipped);
}
const auto withSearch = reactions.customAllowed;

View file

@ -106,9 +106,6 @@ public:
[[nodiscard]] rpl::producer<ChosenReaction> chosen() const {
return _chosen.events();
}
[[nodiscard]] rpl::producer<> premiumPromoChosen() const {
return _premiumPromoChosen.events();
}
[[nodiscard]] rpl::producer<> willExpand() const {
return _willExpand.events();
}
@ -184,7 +181,6 @@ private:
std::unique_ptr<Strip> _strip;
rpl::event_stream<ChosenReaction> _chosen;
rpl::event_stream<> _premiumPromoChosen;
rpl::event_stream<> _willExpand;
rpl::event_stream<> _escapes;
@ -231,6 +227,7 @@ enum class AttachSelectorResult {
Attached,
};
#if 0 // not ready
AttachSelectorResult MakeJustSelectorMenu(
not_null<Ui::PopupMenu*> menu,
not_null<Window::SessionController*> controller,
@ -238,6 +235,7 @@ AttachSelectorResult MakeJustSelectorMenu(
ChatHelpers::EmojiListMode mode,
std::vector<DocumentId> recent,
Fn<void(ChosenReaction)> chosen);
#endif
AttachSelectorResult AttachSelectorToMenu(
not_null<Ui::PopupMenu*> menu,
@ -245,7 +243,7 @@ AttachSelectorResult AttachSelectorToMenu(
QPoint desiredPosition,
not_null<HistoryItem*> item,
Fn<void(ChosenReaction)> chosen,
Fn<void(FullMsgId)> showPremiumPromo,
TextWithEntities description,
IconFactory iconFactory);
[[nodiscard]] auto AttachSelectorToMenu(

View file

@ -169,9 +169,7 @@ void Strip::paintOne(
QPoint position,
QRectF target,
bool allowAppearStart) {
if (icon.added == AddedButton::Premium) {
paintPremiumIcon(p, position, target);
} else if (icon.added == AddedButton::Expand) {
if (icon.added == AddedButton::Expand) {
paintExpandIcon(p, position, target);
} else {
const auto paintFrame = [&](not_null<Ui::AnimatedIcon*> animation) {
@ -248,30 +246,6 @@ int Strip::fillChosenIconGetIndex(ChosenReaction &chosen) const {
return (i - begin(_icons));
}
void Strip::paintPremiumIcon(
QPainter &p,
QPoint position,
QRectF target) const {
const auto to = QRect(
_inner.x() + (_inner.width() - _finalSize) / 2,
_inner.y() + (_inner.height() - _finalSize) / 2,
_finalSize,
_finalSize
).translated(position);
const auto scale = target.width() / to.width();
if (scale != 1.) {
p.save();
p.translate(target.center());
p.scale(scale, scale);
p.translate(-target.center());
}
auto hq = PainterHighQualityEnabler(p);
_st.icons.stripPremiumLocked.paintInCenter(p, to);
if (scale != 1.) {
p.restore();
}
}
void Strip::paintExpandIcon(
QPainter &p,
QPoint position,

View file

@ -58,7 +58,6 @@ public:
enum class AddedButton : uchar {
None,
Expand,
Premium,
};
void applyList(
const std::vector<not_null<const Data::Reaction*>> &list,
@ -110,7 +109,6 @@ private:
};
void clearStateForHidden(ReactionIcons &icon);
void paintPremiumIcon(QPainter &p, QPoint position, QRectF target) const;
void paintExpandIcon(QPainter &p, QPoint position, QRectF target) const;
void clearStateForSelectFinished(ReactionIcons &icon);

View file

@ -646,7 +646,7 @@ void Reactions::Panel::attachToReactionButton(
void Reactions::Panel::create() {
auto reactions = LookupPossibleReactions(
&_controller->uiShow()->session());
if (reactions.recent.empty() && !reactions.morePremiumAvailable) {
if (reactions.recent.empty()) {
return;
}
_parent = std::make_unique<Ui::RpWidget>(_controller->wrap().get());
@ -685,13 +685,6 @@ void Reactions::Panel::create() {
hide(mode);
}, _selector->lifetime());
_selector->premiumPromoChosen() | rpl::start_with_next([=] {
hide(mode);
ShowPremiumPreviewBox(
_controller->uiShow(),
PremiumPreview::InfiniteReactions);
}, _selector->lifetime());
const auto desiredWidth = st::storiesReactionsWidth;
const auto maxWidth = desiredWidth * 2;
const auto width = _selector->countWidth(desiredWidth, maxWidth);

View file

@ -638,10 +638,6 @@ storiesEmojiPan: EmojiPan(defaultEmojiPan) {
{ "chat/reactions_bubble_shadow", windowShadowFg },
{ "chat/reactions_bubble", storiesComposeBg },
};
stripPremiumLocked: icon{
{ "chat/reactions_premium_bg", storiesComposeBgRipple },
{ "chat/reactions_premium_star", storiesComposeGrayIcon },
};
stripExpandPanel: icon{
{ "chat/reactions_round_big", storiesComposeBgRipple },
{ "chat/reactions_expand_panel", storiesComposeGrayIcon },

View file

@ -536,15 +536,8 @@ bool ShowReactPremiumError(
if (i != end(list)) {
return false;
}
} else {
const auto &list = controller->session().data().reactions().list(
Data::Reactions::Type::Active);
const auto i = ranges::find(list, id, &Data::Reaction::id);
if (i == end(list) || !i->premium) {
if (!id.custom()) {
return false;
}
}
} else if (!id.custom()) {
return false;
}
ShowPremiumPreviewBox(controller, PremiumPreview::InfiniteReactions);
return true;