Start showing gifts from stories.

This commit is contained in:
John Preston 2025-01-07 14:52:25 +04:00
parent dcb98ce0fb
commit 51213b499f
32 changed files with 347 additions and 314 deletions

View file

@ -129,7 +129,7 @@ constexpr auto kRarityTooltipDuration = 3 * crl::time(1000);
[[nodiscard]] object_ptr<Ui::RpWidget> MakePeerTableValue( [[nodiscard]] object_ptr<Ui::RpWidget> MakePeerTableValue(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
PeerId id, PeerId id,
rpl::producer<QString> button = nullptr, rpl::producer<QString> button = nullptr,
Fn<void()> handler = nullptr) { Fn<void()> handler = nullptr) {
@ -139,7 +139,7 @@ constexpr auto kRarityTooltipDuration = 3 * crl::time(1000);
const auto &st = st::giveawayGiftCodeUserpic; const auto &st = st::giveawayGiftCodeUserpic;
raw->resize(raw->width(), st.photoSize); raw->resize(raw->width(), st.photoSize);
const auto peer = controller->session().data().peer(id); const auto peer = show->session().data().peer(id);
const auto userpic = Ui::CreateChild<Ui::UserpicButton>(raw, peer, st); const auto userpic = Ui::CreateChild<Ui::UserpicButton>(raw, peer, st);
const auto label = Ui::CreateChild<Ui::FlatLabel>( const auto label = Ui::CreateChild<Ui::FlatLabel>(
raw, raw,
@ -182,15 +182,14 @@ constexpr auto kRarityTooltipDuration = 3 * crl::time(1000);
label->setTextColorOverride(st::windowActiveTextFg->c); label->setTextColorOverride(st::windowActiveTextFg->c);
raw->setClickedCallback([=] { raw->setClickedCallback([=] {
controller->uiShow()->showBox(PrepareShortInfoBox(peer, controller)); show->showBox(PrepareShortInfoBox(peer, show));
}); });
return result; return result;
} }
[[nodiscard]] object_ptr<Ui::RpWidget> MakeHiddenPeerTableValue( [[nodiscard]] object_ptr<Ui::RpWidget> MakeHiddenPeerTableValue(
not_null<QWidget*> parent, not_null<QWidget*> parent) {
not_null<Window::SessionNavigation*> controller) {
auto result = object_ptr<Ui::RpWidget>(parent); auto result = object_ptr<Ui::RpWidget>(parent);
const auto raw = result.data(); const auto raw = result.data();
@ -295,13 +294,13 @@ void AddTableRow(
[[nodiscard]] object_ptr<Ui::RpWidget> MakeStarGiftStarsValue( [[nodiscard]] object_ptr<Ui::RpWidget> MakeStarGiftStarsValue(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
const Data::CreditsHistoryEntry &entry, const Data::CreditsHistoryEntry &entry,
Fn<void()> convertToStars) { Fn<void()> convertToStars) {
auto result = object_ptr<Ui::RpWidget>(parent); auto result = object_ptr<Ui::RpWidget>(parent);
const auto raw = result.data(); const auto raw = result.data();
const auto session = &controller->session(); const auto session = &show->session();
const auto makeContext = [session](Fn<void()> update) { const auto makeContext = [session](Fn<void()> update) {
return Core::MarkedTextContext{ return Core::MarkedTextContext{
.session = session, .session = session,
@ -360,7 +359,6 @@ void AddTableRow(
[[nodiscard]] object_ptr<Ui::RpWidget> MakeVisibilityTableValue( [[nodiscard]] object_ptr<Ui::RpWidget> MakeVisibilityTableValue(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Window::SessionNavigation*> controller,
bool savedToProfile, bool savedToProfile,
Fn<void(bool)> toggleVisibility) { Fn<void(bool)> toggleVisibility) {
auto result = object_ptr<Ui::RpWidget>(parent); auto result = object_ptr<Ui::RpWidget>(parent);
@ -414,7 +412,6 @@ void AddTableRow(
[[nodiscard]] object_ptr<Ui::RpWidget> MakeNonUniqueStatusTableValue( [[nodiscard]] object_ptr<Ui::RpWidget> MakeNonUniqueStatusTableValue(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Window::SessionNavigation*> controller,
Fn<void()> startUpgrade) { Fn<void()> startUpgrade) {
auto result = object_ptr<Ui::RpWidget>(parent); auto result = object_ptr<Ui::RpWidget>(parent);
const auto raw = result.data(); const auto raw = result.data();
@ -482,7 +479,7 @@ not_null<Ui::FlatLabel*> AddTableRow(
void AddTableRow( void AddTableRow(
not_null<Ui::TableLayout*> table, not_null<Ui::TableLayout*> table,
rpl::producer<QString> label, rpl::producer<QString> label,
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
PeerId id) { PeerId id) {
if (!id) { if (!id) {
return; return;
@ -490,13 +487,13 @@ void AddTableRow(
AddTableRow( AddTableRow(
table, table,
std::move(label), std::move(label),
MakePeerTableValue(table, controller, id), MakePeerTableValue(table, show, id),
st::giveawayGiftCodePeerMargin); st::giveawayGiftCodePeerMargin);
} }
void AddTable( void AddTable(
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
const Api::GiftCode &current, const Api::GiftCode &current,
bool skipReason) { bool skipReason) {
auto table = container->add( auto table = container->add(
@ -508,14 +505,14 @@ void AddTable(
AddTableRow( AddTableRow(
table, table,
tr::lng_gift_link_label_from(), tr::lng_gift_link_label_from(),
controller, show,
current.from); current.from);
} }
if (current.from && current.to) { if (current.from && current.to) {
AddTableRow( AddTableRow(
table, table,
tr::lng_gift_link_label_to(), tr::lng_gift_link_label_to(),
controller, show,
current.to); current.to);
} else if (current.from) { } else if (current.from) {
AddTableRow( AddTableRow(
@ -547,10 +544,12 @@ void AddTable(
) | rpl::type_erased()) ) | rpl::type_erased())
: tr::lng_gift_link_reason_chosen(Ui::Text::WithEntities))); : tr::lng_gift_link_reason_chosen(Ui::Text::WithEntities)));
reason->setClickHandlerFilter([=](const auto &...) { reason->setClickHandlerFilter([=](const auto &...) {
controller->showPeerHistory( if (const auto window = show->resolveWindow()) {
window->showPeerHistory(
current.from, current.from,
Window::SectionShow::Way::Forward, Window::SectionShow::Way::Forward,
current.giveawayId); current.giveawayId);
}
return false; return false;
}); });
} }
@ -678,7 +677,8 @@ void GiftCodeBox(
MakeLinkCopyIcon(box)), MakeLinkCopyIcon(box)),
st::giveawayGiftCodeLinkMargin); st::giveawayGiftCodeLinkMargin);
AddTable(box->verticalLayout(), controller, state->data.current(), false); const auto show = controller->uiShow();
AddTable(box->verticalLayout(), show, state->data.current(), false);
auto shareLink = tr::lng_gift_link_also_send_link( auto shareLink = tr::lng_gift_link_also_send_link(
) | rpl::map([](const QString &text) { ) | rpl::map([](const QString &text) {
@ -838,7 +838,8 @@ void GiftCodePendingBox(
spoiler->show(); spoiler->show();
} }
AddTable(box->verticalLayout(), controller, data, true); const auto show = controller->uiShow();
AddTable(box->verticalLayout(), show, data, true);
box->addRow( box->addRow(
object_ptr<Ui::FlatLabel>( object_ptr<Ui::FlatLabel>(
@ -1189,7 +1190,7 @@ void ResolveGiveawayInfo(
} }
void AddStarGiftTable( void AddStarGiftTable(
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
const Data::CreditsHistoryEntry &entry, const Data::CreditsHistoryEntry &entry,
Fn<void(bool)> toggleVisibility, Fn<void(bool)> toggleVisibility,
@ -1201,7 +1202,7 @@ void AddStarGiftTable(
st::giveawayGiftCodeTable), st::giveawayGiftCodeTable),
st::giveawayGiftCodeTableMargin); st::giveawayGiftCodeTableMargin);
const auto peerId = PeerId(entry.barePeerId); const auto peerId = PeerId(entry.barePeerId);
const auto session = &controller->session(); const auto session = &show->session();
const auto unique = entry.uniqueGift.get(); const auto unique = entry.uniqueGift.get();
const auto selfBareId = session->userPeerId().value; const auto selfBareId = session->userPeerId().value;
const auto giftToSelf = (peerId == session->userPeerId()) const auto giftToSelf = (peerId == session->userPeerId())
@ -1213,15 +1214,17 @@ void AddStarGiftTable(
&& (unique->starsForTransfer >= 0); && (unique->starsForTransfer >= 0);
auto send = transfer ? tr::lng_gift_unique_owner_change() : nullptr; auto send = transfer ? tr::lng_gift_unique_owner_change() : nullptr;
auto handler = transfer ? Fn<void()>([=] { auto handler = transfer ? Fn<void()>([=] {
if (const auto window = show->resolveWindow()) {
ShowTransferGiftBox( ShowTransferGiftBox(
controller->parentController(), window,
entry.uniqueGift, entry.uniqueGift,
MsgId(entry.bareMsgId)); MsgId(entry.bareMsgId));
}
}) : nullptr; }) : nullptr;
AddTableRow( AddTableRow(
table, table,
tr::lng_gift_unique_owner(), tr::lng_gift_unique_owner(),
MakePeerTableValue(table, controller, ownerId, send, handler), MakePeerTableValue(table, show, ownerId, send, handler),
st::giveawayGiftCodePeerMargin); st::giveawayGiftCodePeerMargin);
} else if (unique) { } else if (unique) {
AddTableRow( AddTableRow(
@ -1234,19 +1237,21 @@ void AddStarGiftTable(
const auto withSendButton = entry.in && user && !user->isBot(); const auto withSendButton = entry.in && user && !user->isBot();
auto send = withSendButton ? tr::lng_gift_send_small() : nullptr; auto send = withSendButton ? tr::lng_gift_send_small() : nullptr;
auto handler = send ? Fn<void()>([=] { auto handler = send ? Fn<void()>([=] {
Ui::ShowStarGiftBox(controller->parentController(), user); if (const auto window = show->resolveWindow()) {
Ui::ShowStarGiftBox(window, user);
}
}) : nullptr; }) : nullptr;
AddTableRow( AddTableRow(
table, table,
tr::lng_credits_box_history_entry_peer_in(), tr::lng_credits_box_history_entry_peer_in(),
MakePeerTableValue(table, controller, peerId, send, handler), MakePeerTableValue(table, show, peerId, send, handler),
st::giveawayGiftCodePeerMargin); st::giveawayGiftCodePeerMargin);
} }
} else if (!entry.soldOutInfo) { } else if (!entry.soldOutInfo) {
AddTableRow( AddTableRow(
table, table,
tr::lng_credits_box_history_entry_peer_in(), tr::lng_credits_box_history_entry_peer_in(),
MakeHiddenPeerTableValue(table, controller), MakeHiddenPeerTableValue(table),
st::giveawayGiftCodePeerMargin); st::giveawayGiftCodePeerMargin);
} }
if (!unique && !entry.firstSaleDate.isNull()) { if (!unique && !entry.firstSaleDate.isNull()) {
@ -1357,7 +1362,7 @@ void AddStarGiftTable(
tr::lng_gift_link_label_value(), tr::lng_gift_link_label_value(),
MakeStarGiftStarsValue( MakeStarGiftStarsValue(
table, table,
controller, show,
entry, entry,
std::move(convertToStars)), std::move(convertToStars)),
marginWithButton); marginWithButton);
@ -1368,7 +1373,6 @@ void AddStarGiftTable(
tr::lng_gift_visibility(), tr::lng_gift_visibility(),
MakeVisibilityTableValue( MakeVisibilityTableValue(
table, table,
controller,
entry.savedToProfile, entry.savedToProfile,
std::move(toggleVisibility)), std::move(toggleVisibility)),
marginWithButton); marginWithButton);
@ -1398,16 +1402,13 @@ void AddStarGiftTable(
AddTableRow( AddTableRow(
table, table,
tr::lng_gift_unique_status(), tr::lng_gift_unique_status(),
MakeNonUniqueStatusTableValue( MakeNonUniqueStatusTableValue(table, std::move(startUpgrade)),
table,
controller,
std::move(startUpgrade)),
marginWithButton); marginWithButton);
} }
if (unique) { if (unique) {
const auto &original = unique->originalDetails; const auto &original = unique->originalDetails;
if (original.recipientId) { if (original.recipientId) {
const auto owner = &controller->session().data(); const auto owner = &show->session().data();
const auto to = owner->peer(original.recipientId); const auto to = owner->peer(original.recipientId);
const auto from = original.senderId const auto from = original.senderId
? owner->peer(original.senderId).get() ? owner->peer(original.senderId).get()
@ -1462,8 +1463,7 @@ void AddStarGiftTable(
makeContext); makeContext);
const auto showBoxLink = [=](not_null<PeerData*> peer) { const auto showBoxLink = [=](not_null<PeerData*> peer) {
return std::make_shared<LambdaClickHandler>([=] { return std::make_shared<LambdaClickHandler>([=] {
controller->uiShow()->showBox( show->showBox(PrepareShortInfoBox(peer, show));
PrepareShortInfoBox(peer, controller));
}); });
}; };
label->setLink(1, showBoxLink(to)); label->setLink(1, showBoxLink(to));
@ -1500,7 +1500,7 @@ void AddStarGiftTable(
} }
void AddCreditsHistoryEntryTable( void AddCreditsHistoryEntryTable(
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
const Data::CreditsHistoryEntry &entry) { const Data::CreditsHistoryEntry &entry) {
if (!entry) { if (!entry) {
@ -1514,7 +1514,7 @@ void AddCreditsHistoryEntryTable(
const auto peerId = PeerId(entry.barePeerId); const auto peerId = PeerId(entry.barePeerId);
const auto actorId = PeerId(entry.bareActorId); const auto actorId = PeerId(entry.bareActorId);
const auto starrefRecipientId = PeerId(entry.starrefRecipientId); const auto starrefRecipientId = PeerId(entry.starrefRecipientId);
const auto session = &controller->session(); const auto session = &show->session();
if (entry.starrefCommission) { if (entry.starrefCommission) {
if (entry.starrefAmount) { if (entry.starrefAmount) {
AddTableRow( AddTableRow(
@ -1534,7 +1534,7 @@ void AddCreditsHistoryEntryTable(
AddTableRow( AddTableRow(
table, table,
tr::lng_credits_box_history_entry_affiliate(), tr::lng_credits_box_history_entry_affiliate(),
controller, show,
starrefRecipientId); starrefRecipientId);
} }
if (peerId && entry.starrefCommission) { if (peerId && entry.starrefCommission) {
@ -1543,7 +1543,7 @@ void AddCreditsHistoryEntryTable(
(entry.starrefAmount (entry.starrefAmount
? tr::lng_credits_box_history_entry_referred ? tr::lng_credits_box_history_entry_referred
: tr::lng_credits_box_history_entry_miniapp)(), : tr::lng_credits_box_history_entry_miniapp)(),
controller, show,
peerId); peerId);
} }
if (actorId || (!entry.starrefCommission && peerId)) { if (actorId || (!entry.starrefCommission && peerId)) {
@ -1557,7 +1557,7 @@ void AddCreditsHistoryEntryTable(
AddTableRow( AddTableRow(
table, table,
std::move(text), std::move(text),
controller, show,
actorId ? actorId : peerId); actorId ? actorId : peerId);
} }
if (const auto msgId = MsgId(peerId ? entry.bareMsgId : 0)) { if (const auto msgId = MsgId(peerId ? entry.bareMsgId : 0)) {
@ -1572,7 +1572,9 @@ void AddCreditsHistoryEntryTable(
rpl::single(Ui::Text::Link(link)), rpl::single(Ui::Text::Link(link)),
st::giveawayGiftCodeValue); st::giveawayGiftCodeValue);
label->setClickHandlerFilter([=](const auto &...) { label->setClickHandlerFilter([=](const auto &...) {
controller->showPeerHistory(channel, {}, msgId); if (const auto window = show->resolveWindow()) {
window->showPeerHistory(channel, {}, msgId);
}
return false; return false;
}); });
AddTableRow( AddTableRow(
@ -1623,8 +1625,8 @@ void AddCreditsHistoryEntryTable(
AddTableRow( AddTableRow(
table, table,
tr::lng_gift_link_label_to(), tr::lng_gift_link_label_to(),
controller, show,
controller->session().userId()); show->session().userId());
} }
if (entry.bareGiveawayMsgId && entry.credits) { if (entry.bareGiveawayMsgId && entry.credits) {
AddTableRow( AddTableRow(
@ -1670,7 +1672,7 @@ void AddCreditsHistoryEntryTable(
label->setClickHandlerFilter([=](const auto &...) { label->setClickHandlerFilter([=](const auto &...) {
TextUtilities::SetClipboardText( TextUtilities::SetClipboardText(
TextForMimeData::Simple(entry.id)); TextForMimeData::Simple(entry.id));
controller->showToast( show->showToast(
tr::lng_credits_box_history_entry_id_copied(tr::now)); tr::lng_credits_box_history_entry_id_copied(tr::now));
return false; return false;
}); });
@ -1710,7 +1712,7 @@ void AddCreditsHistoryEntryTable(
} }
void AddSubscriptionEntryTable( void AddSubscriptionEntryTable(
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
const Data::SubscriptionEntry &s) { const Data::SubscriptionEntry &s) {
if (!s) { if (!s) {
@ -1723,7 +1725,7 @@ void AddSubscriptionEntryTable(
st::giveawayGiftCodeTableMargin); st::giveawayGiftCodeTableMargin);
const auto peerId = PeerId(s.barePeerId); const auto peerId = PeerId(s.barePeerId);
const auto user = peerIsUser(peerId) const auto user = peerIsUser(peerId)
? controller->session().data().peer(peerId)->asUser() ? show->session().data().peer(peerId)->asUser()
: nullptr; : nullptr;
AddTableRow( AddTableRow(
table, table,
@ -1732,7 +1734,7 @@ void AddSubscriptionEntryTable(
: (!s.title.isEmpty() && user && !user->botInfo) : (!s.title.isEmpty() && user && !user->botInfo)
? tr::lng_credits_subscription_row_to_business() ? tr::lng_credits_subscription_row_to_business()
: tr::lng_credits_subscription_row_to(), : tr::lng_credits_subscription_row_to(),
controller, show,
peerId); peerId);
if (!s.title.isEmpty()) { if (!s.title.isEmpty()) {
AddTableRow( AddTableRow(
@ -1763,7 +1765,7 @@ void AddSubscriptionEntryTable(
} }
void AddSubscriberEntryTable( void AddSubscriberEntryTable(
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
not_null<PeerData*> peer, not_null<PeerData*> peer,
TimeId date) { TimeId date) {
@ -1775,7 +1777,7 @@ void AddSubscriberEntryTable(
AddTableRow( AddTableRow(
table, table,
tr::lng_group_invite_joined_row_subscriber(), tr::lng_group_invite_joined_row_subscriber(),
controller, show,
peer->id); peer->id);
if (const auto d = base::unixtime::parse(date); !d.isNull()) { if (const auto d = base::unixtime::parse(date); !d.isNull()) {
AddTableRow( AddTableRow(
@ -1786,7 +1788,7 @@ void AddSubscriberEntryTable(
} }
void AddCreditsBoostTable( void AddCreditsBoostTable(
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
const Data::Boost &b) { const Data::Boost &b) {
auto table = container->add( auto table = container->add(
@ -1798,11 +1800,11 @@ void AddCreditsBoostTable(
if (!peerId) { if (!peerId) {
return; return;
} }
const auto from = controller->session().data().peer(peerId); const auto from = show->session().data().peer(peerId);
AddTableRow( AddTableRow(
table, table,
tr::lng_credits_box_history_entry_peer_in(), tr::lng_credits_box_history_entry_peer_in(),
controller, show,
from->id); from->id);
if (b.credits) { if (b.credits) {
AddTableRow( AddTableRow(
@ -1815,7 +1817,7 @@ void AddCreditsBoostTable(
} }
{ {
const auto link = CreateMessageLink( const auto link = CreateMessageLink(
&controller->session(), &show->session(),
peerId, peerId,
b.giveawayMessage.msg.bare); b.giveawayMessage.msg.bare);
if (!link.isEmpty()) { if (!link.isEmpty()) {

View file

@ -13,6 +13,10 @@ namespace Api {
struct GiftCode; struct GiftCode;
} // namespace Api } // namespace Api
namespace ChatHelpers {
class Show;
} // namespace ChatHelpers
namespace Data { namespace Data {
struct Boost; struct Boost;
struct CreditsHistoryEntry; struct CreditsHistoryEntry;
@ -55,28 +59,28 @@ void ResolveGiveawayInfo(
std::optional<Data::GiveawayResults> results); std::optional<Data::GiveawayResults> results);
void AddStarGiftTable( void AddStarGiftTable(
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
const Data::CreditsHistoryEntry &entry, const Data::CreditsHistoryEntry &entry,
Fn<void(bool)> toggleVisibility, Fn<void(bool)> toggleVisibility,
Fn<void()> convertToStars, Fn<void()> convertToStars,
Fn<void()> startUpgrade); Fn<void()> startUpgrade);
void AddCreditsHistoryEntryTable( void AddCreditsHistoryEntryTable(
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
const Data::CreditsHistoryEntry &entry); const Data::CreditsHistoryEntry &entry);
void AddSubscriptionEntryTable( void AddSubscriptionEntryTable(
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
const Data::SubscriptionEntry &s); const Data::SubscriptionEntry &s);
void AddSubscriberEntryTable( void AddSubscriberEntryTable(
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
not_null<PeerData*> peer, not_null<PeerData*> peer,
TimeId date); TimeId date);
void AddCreditsBoostTable( void AddCreditsBoostTable(
not_null<Window::SessionNavigation*> controller, std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
const Data::Boost &boost); const Data::Boost &boost);

View file

@ -872,8 +872,7 @@ int ColorSelector::resizeGetHeight(int newWidth) {
const auto customTextColor = [=] { const auto customTextColor = [=] {
return style->coloredValues(false, state->index).name; return style->coloredValues(false, state->index).name;
}; };
const auto controller = show->resolveWindow( const auto controller = show->resolveWindow();
ChatHelpers::WindowUsage::PremiumPromo);
if (controller) { if (controller) {
state->panel.show({ state->panel.show({
.controller = controller, .controller = controller,
@ -986,8 +985,7 @@ int ColorSelector::resizeGetHeight(int newWidth) {
}, right->lifetime()); }, right->lifetime());
raw->setClickedCallback([=] { raw->setClickedCallback([=] {
const auto controller = show->resolveWindow( const auto controller = show->resolveWindow();
ChatHelpers::WindowUsage::PremiumPromo);
if (controller) { if (controller) {
state->panel.show({ state->panel.show({
.controller = controller, .controller = controller,
@ -1264,8 +1262,7 @@ void EditPeerColorBox(
{ &st::menuBlueIconWallpaper } { &st::menuBlueIconWallpaper }
); );
button->setClickedCallback([=] { button->setClickedCallback([=] {
const auto usage = ChatHelpers::WindowUsage::PremiumPromo; if (const auto strong = show->resolveWindow()) {
if (const auto strong = show->resolveWindow(usage)) {
show->show(Box<BackgroundBox>(strong, channel)); show->show(Box<BackgroundBox>(strong, channel));
} }
}); });
@ -1472,8 +1469,7 @@ void CheckBoostLevel(
return; return;
} }
const auto openStatistics = [=] { const auto openStatistics = [=] {
if (const auto controller = show->resolveWindow( if (const auto controller = show->resolveWindow()) {
ChatHelpers::WindowUsage::PremiumPromo)) {
controller->showSection(Info::Boosts::Make(peer)); controller->showSection(Info::Boosts::Make(peer));
} }
}; };

View file

@ -1019,7 +1019,8 @@ void Controller::rowClicked(not_null<PeerListRow*> row) {
Ui::AddSkip(content); Ui::AddSkip(content);
Ui::AddSkip(content); Ui::AddSkip(content);
AddSubscriberEntryTable(controller, content, row->peer(), data.date); const auto show = controller->uiShow();
AddSubscriberEntryTable(show, content, row->peer(), data.date);
Ui::AddSkip(content); Ui::AddSkip(content);
Ui::AddSkip(content); Ui::AddSkip(content);

View file

@ -486,20 +486,23 @@ object_ptr<Ui::BoxContent> PrepareShortInfoBox(
object_ptr<Ui::BoxContent> PrepareShortInfoBox( object_ptr<Ui::BoxContent> PrepareShortInfoBox(
not_null<PeerData*> peer, not_null<PeerData*> peer,
not_null<Window::SessionNavigation*> navigation, std::shared_ptr<ChatHelpers::Show> show,
const style::ShortInfoBox *stOverride) { const style::ShortInfoBox *stOverride) {
const auto open = [=] { navigation->showPeerHistory(peer); }; const auto open = [=] {
if (const auto window = show->resolveWindow()) {
window->showPeerHistory(peer);
}
};
const auto videoIsPaused = [=] { const auto videoIsPaused = [=] {
return navigation->parentController()->isGifPausedAtLeastFor( return show->paused(Window::GifPauseReason::Layer);
Window::GifPauseReason::Layer);
}; };
auto menuFiller = [=](Ui::Menu::MenuCallback addAction) { auto menuFiller = [=](Ui::Menu::MenuCallback addAction) {
const auto controller = navigation->parentController();
const auto peerSeparateId = Window::SeparateId(peer); const auto peerSeparateId = Window::SeparateId(peer);
if (controller->windowId() != peerSeparateId) { const auto window = show->resolveWindow();
if (window && window->windowId() != peerSeparateId) {
addAction(tr::lng_context_new_window(tr::now), [=] { addAction(tr::lng_context_new_window(tr::now), [=] {
Ui::PreventDelayedActivation(); Ui::PreventDelayedActivation();
controller->showInNewWindow(peer); window->showInNewWindow(peer);
}, &st::menuIconNewWindow); }, &st::menuIconNewWindow);
} }
}; };
@ -511,6 +514,13 @@ object_ptr<Ui::BoxContent> PrepareShortInfoBox(
stOverride); stOverride);
} }
object_ptr<Ui::BoxContent> PrepareShortInfoBox(
not_null<PeerData*> peer,
not_null<Window::SessionNavigation*> navigation,
const style::ShortInfoBox *stOverride) {
return PrepareShortInfoBox(peer, navigation->uiShow(), stOverride);
}
rpl::producer<QString> PrepareShortInfoStatus(not_null<PeerData*> peer) { rpl::producer<QString> PrepareShortInfoStatus(not_null<PeerData*> peer) {
return StatusValue(peer); return StatusValue(peer);
} }

View file

@ -16,6 +16,10 @@ struct ShortInfoCover;
struct ShortInfoBox; struct ShortInfoBox;
} // namespace style } // namespace style
namespace ChatHelpers {
class Show;
} // namespace ChatHelpers
namespace Ui::Menu { namespace Ui::Menu {
struct MenuCallback; struct MenuCallback;
} // namespace Ui::Menu } // namespace Ui::Menu
@ -42,6 +46,11 @@ struct PreparedShortInfoUserpic {
Fn<void(Ui::Menu::MenuCallback)> menuFiller, Fn<void(Ui::Menu::MenuCallback)> menuFiller,
const style::ShortInfoBox *stOverride = nullptr); const style::ShortInfoBox *stOverride = nullptr);
[[nodiscard]] object_ptr<Ui::BoxContent> PrepareShortInfoBox(
not_null<PeerData*> peer,
std::shared_ptr<ChatHelpers::Show> show,
const style::ShortInfoBox *stOverride = nullptr);
[[nodiscard]] object_ptr<Ui::BoxContent> PrepareShortInfoBox( [[nodiscard]] object_ptr<Ui::BoxContent> PrepareShortInfoBox(
not_null<PeerData*> peer, not_null<PeerData*> peer,
not_null<Window::SessionNavigation*> navigation, not_null<Window::SessionNavigation*> navigation,

View file

@ -1139,8 +1139,7 @@ void PreviewBox(
button->resizeToWidth(width); button->resizeToWidth(width);
if (!descriptor.fromSettings) { if (!descriptor.fromSettings) {
button->setClickedCallback([=] { button->setClickedCallback([=] {
const auto window = show->resolveWindow( const auto window = show->resolveWindow();
ChatHelpers::WindowUsage::PremiumPromo);
if (!window) { if (!window) {
return; return;
} }

View file

@ -773,9 +773,7 @@ void StickerSetBox::updateButtons() {
- st.buttonPadding.left() - st.buttonPadding.left()
- st.buttonPadding.left()); - st.buttonPadding.left());
button->setClickedCallback([=] { button->setClickedCallback([=] {
using namespace ChatHelpers; if (const auto window = _show->resolveWindow()) {
const auto usage = WindowUsage::PremiumPromo;
if (const auto window = _show->resolveWindow(usage)) {
Settings::ShowPremium(window, u"animated_emoji"_q); Settings::ShowPremium(window, u"animated_emoji"_q);
} }
}); });

View file

@ -19,7 +19,7 @@ rpl::producer<bool> Show::adjustShadowLeft() const {
} }
ResolveWindow ResolveWindowDefault() { ResolveWindow ResolveWindowDefault() {
return [](not_null<Main::Session*> session, WindowUsage usage) return [](not_null<Main::Session*> session)
-> Window::SessionController* { -> Window::SessionController* {
const auto check = [&](Window::Controller *window) { const auto check = [&](Window::Controller *window) {
if (const auto controller = window->sessionController()) { if (const auto controller = window->sessionController()) {
@ -45,8 +45,8 @@ ResolveWindow ResolveWindowDefault() {
}; };
} }
Window::SessionController *Show::resolveWindow(WindowUsage usage) const { Window::SessionController *Show::resolveWindow() const {
return ResolveWindowDefault()(&session(), usage); return ResolveWindowDefault()(&session());
} }
} // namespace ChatHelpers } // namespace ChatHelpers

View file

@ -40,13 +40,8 @@ enum class PauseReason {
using PauseReasons = base::flags<PauseReason>; using PauseReasons = base::flags<PauseReason>;
inline constexpr bool is_flag_type(PauseReason) { return true; }; inline constexpr bool is_flag_type(PauseReason) { return true; };
enum class WindowUsage {
PremiumPromo,
};
using ResolveWindow = Fn<Window::SessionController*( using ResolveWindow = Fn<Window::SessionController*(
not_null<Main::Session*>, not_null<Main::Session*>)>;
WindowUsage)>;
[[nodiscard]] ResolveWindow ResolveWindowDefault(); [[nodiscard]] ResolveWindow ResolveWindowDefault();
class Show : public Main::SessionShow { class Show : public Main::SessionShow {
@ -68,8 +63,7 @@ public:
virtual void processChosenSticker(FileChosen &&chosen) const = 0; virtual void processChosenSticker(FileChosen &&chosen) const = 0;
[[nodiscard]] virtual Window::SessionController *resolveWindow( [[nodiscard]] virtual Window::SessionController *resolveWindow() const;
WindowUsage) const;
}; };
} // namespace ChatHelpers } // namespace ChatHelpers

View file

@ -1751,7 +1751,6 @@ void EmojiListWidget::mouseReleaseEvent(QMouseEvent *e) {
const auto id = hasColorButton(button->section) const auto id = hasColorButton(button->section)
? 0 ? 0
: _custom[button->section - _staticCount].id; : _custom[button->section - _staticCount].id;
const auto usage = ChatHelpers::WindowUsage::PremiumPromo;
if (hasColorButton(button->section)) { if (hasColorButton(button->section)) {
_pickerSelected = pressed; _pickerSelected = pressed;
showPicker(); showPicker();
@ -1759,7 +1758,7 @@ void EmojiListWidget::mouseReleaseEvent(QMouseEvent *e) {
removeSet(id); removeSet(id);
} else if (hasAddButton(button->section)) { } else if (hasAddButton(button->section)) {
_localSetsManager->install(id); _localSetsManager->install(id);
} else if (const auto resolved = _show->resolveWindow(usage)) { } else if (const auto resolved = _show->resolveWindow()) {
_jumpedToPremium.fire({}); _jumpedToPremium.fire({});
switch (_mode) { switch (_mode) {
case Mode::Full: case Mode::Full:

View file

@ -237,8 +237,7 @@ StickersListWidget::StickersListWidget(
} }
_settings->addClickHandler([=] { _settings->addClickHandler([=] {
if (const auto window = _show->resolveWindow( if (const auto window = _show->resolveWindow()) {
WindowUsage::PremiumPromo)) {
// While media viewer can't show StickersBox. // While media viewer can't show StickersBox.
using Section = StickersBox::Section; using Section = StickersBox::Section;
window->show( window->show(

View file

@ -1061,8 +1061,7 @@ void TabbedSelector::checkRestrictedPeer() {
st::stickersRestrictedLabel); st::stickersRestrictedLabel);
const auto lifting = error.boostsToLift; const auto lifting = error.boostsToLift;
_restrictedLabel->setClickHandlerFilter([=](auto...) { _restrictedLabel->setClickHandlerFilter([=](auto...) {
const auto window = show->resolveWindow( const auto window = show->resolveWindow();
ChatHelpers::WindowUsage::PremiumPromo);
window->resolveBoostState(peer->asChannel(), lifting); window->resolveBoostState(peer->asChannel(), lifting);
return false; return false;
}); });

View file

@ -1355,45 +1355,7 @@ bool ResolveUniqueGift(
if (slug.isEmpty()) { if (slug.isEmpty()) {
return false; return false;
} }
struct Request { ResolveAndShowUniqueGift(controller->uiShow(), slug);
base::weak_ptr<Window::SessionController> weak;
QString slug;
mtpRequestId id = 0;
};
static auto request = Request();
if (request.weak.get() == controller && request.slug == slug) {
return true;
} else if (const auto strong = request.weak.get()) {
strong->session().api().request(request.id).cancel();
}
const auto weak = request.weak = controller;
request.slug = slug;
const auto clear = [slug](not_null<Window::SessionController*> window) {
if (request.weak.get() == window && request.slug == slug) {
request = {};
}
};
request.id = controller->session().api().request(
MTPpayments_GetUniqueStarGift(MTP_string(slug))
).done([=](const MTPpayments_UniqueStarGift &result) {
if (const auto strong = weak.get()) {
clear(strong);
const auto &data = result.data();
const auto session = &strong->session();
session->data().processUsers(data.vusers());
if (const auto gift = Api::FromTL(session, data.vgift())) {
using namespace ::Settings;
strong->show(Box(GlobalStarGiftBox, strong, *gift));
}
}
}).fail([=](const MTP::Error &error) {
if (const auto strong = weak.get()) {
clear(strong);
strong->showToast(u"Error: "_q + error.type());
}
}).send();
return true; return true;
} }
@ -1738,4 +1700,44 @@ bool StartUrlRequiresActivate(const QString &url) {
: !InternalPassportLink(url); : !InternalPassportLink(url);
} }
void ResolveAndShowUniqueGift(
std::shared_ptr<ChatHelpers::Show> show,
const QString &slug) {
struct Request {
base::weak_ptr<Main::Session> weak;
QString slug;
mtpRequestId id = 0;
};
static auto request = Request();
const auto session = &show->session();
if (request.weak.get() == session && request.slug == slug) {
return;
} else if (const auto strong = request.weak.get()) {
strong->api().request(request.id).cancel();
}
request.weak = session;
request.slug = slug;
const auto clear = [=] {
if (request.weak.get() == session && request.slug == slug) {
request = {};
}
};
request.id = session->api().request(
MTPpayments_GetUniqueStarGift(MTP_string(slug))
).done([=](const MTPpayments_UniqueStarGift &result) {
clear();
const auto &data = result.data();
session->data().processUsers(data.vusers());
if (const auto gift = Api::FromTL(session, data.vgift())) {
using namespace ::Settings;
show->show(Box(GlobalStarGiftBox, show, *gift));
}
}).fail([=](const MTP::Error &error) {
clear();
show->showToast(u"Error: "_q + error.type());
}).send();
}
} // namespace Core } // namespace Core

View file

@ -11,6 +11,10 @@ namespace qthelp {
class RegularExpressionMatch; class RegularExpressionMatch;
} // namespace qthelp } // namespace qthelp
namespace ChatHelpers {
class Show;
} // namespace ChatHelpers
namespace Window { namespace Window {
class SessionController; class SessionController;
} // namespace Window } // namespace Window
@ -34,4 +38,8 @@ struct LocalUrlHandler {
[[nodiscard]] bool StartUrlRequiresActivate(const QString &url); [[nodiscard]] bool StartUrlRequiresActivate(const QString &url);
void ResolveAndShowUniqueGift(
std::shared_ptr<ChatHelpers::Show> show,
const QString &slug);
} // namespace Core } // namespace Core

View file

@ -416,8 +416,7 @@ void ShowSendErrorToast(
return; return;
} }
const auto boost = [=] { const auto boost = [=] {
const auto window = show->resolveWindow( const auto window = show->resolveWindow();
ChatHelpers::WindowUsage::PremiumPromo);
window->resolveBoostState(peer->asChannel(), error.boostsToLift); window->resolveBoostState(peer->asChannel(), error.boostsToLift);
}; };
show->showToast({ show->showToast({

View file

@ -158,6 +158,10 @@ using UpdateFlag = StoryUpdate::Flag;
}); });
}, [&](const MTPDmediaAreaWeather &data) { }, [&](const MTPDmediaAreaWeather &data) {
}, [&](const MTPDmediaAreaStarGift &data) { }, [&](const MTPDmediaAreaStarGift &data) {
result.emplace(UrlArea{
.area = ParseArea(data.vcoordinates()),
.url = u"tg://nft?slug="_q + qs(data.vslug()),
});
}, [&](const MTPDinputMediaAreaChannelPost &data) { }, [&](const MTPDinputMediaAreaChannelPost &data) {
LOG(("API Error: Unexpected inputMediaAreaChannelPost from API.")); LOG(("API Error: Unexpected inputMediaAreaChannelPost from API."));
}, [&](const MTPDinputMediaAreaVenue &data) { }, [&](const MTPDinputMediaAreaVenue &data) {

View file

@ -88,8 +88,7 @@ void MaybeShowPremiumToast(
return; return;
} }
const auto filter = [=](const auto ...) { const auto filter = [=](const auto ...) {
const auto usage = ChatHelpers::WindowUsage::PremiumPromo; if (const auto controller = show->resolveWindow()) {
if (const auto controller = show->resolveWindow(usage)) {
Settings::ShowPremium(controller, ref); Settings::ShowPremium(controller, ref);
} }
return false; return false;

View file

@ -178,8 +178,7 @@ object_ptr<Ui::BoxContent> MakeSendErrorBox(
Expects(peer->isChannel()); Expects(peer->isChannel());
const auto window = ChatHelpers::ResolveWindowDefault()( const auto window = ChatHelpers::ResolveWindowDefault()(
&peer->session(), &peer->session());
ChatHelpers::WindowUsage::PremiumPromo);
window->resolveBoostState(peer->asChannel(), lifting); window->resolveBoostState(peer->asChannel(), lifting);
return false; return false;
}; };

View file

@ -2317,8 +2317,7 @@ void SetupRestrictionView(
tr::lng_restricted_boost_group(tr::now), tr::lng_restricted_boost_group(tr::now),
st::historyComposeButton); st::historyComposeButton);
state->button->setClickedCallback([=] { state->button->setClickedCallback([=] {
const auto window = show->resolveWindow( const auto window = show->resolveWindow();
ChatHelpers::WindowUsage::PremiumPromo);
window->resolveBoostState(peer->asChannel(), lifting); window->resolveBoostState(peer->asChannel(), lifting);
}); });
} else if (value.type == Type::Rights) { } else if (value.type == Type::Rights) {

View file

@ -479,8 +479,7 @@ bool CheckEmojiStatusPremium(not_null<UserData*> bot) {
return true; return true;
} }
const auto window = ChatHelpers::ResolveWindowDefault()( const auto window = ChatHelpers::ResolveWindowDefault()(
&bot->session(), &bot->session());
ChatHelpers::WindowUsage::PremiumPromo);
if (window) { if (window) {
ShowPremiumPreviewBox(window, PremiumFeature::EmojiStatus); ShowPremiumPreviewBox(window, PremiumFeature::EmojiStatus);
window->window().activate(); window->window().activate();

View file

@ -1347,6 +1347,7 @@ void MainWidget::showHistory(
} }
if (peerId && params.activation != anim::activation::background) { if (peerId && params.activation != anim::activation::background) {
Core::App().hideMediaView();
_controller->window().activate(); _controller->window().activate();
} }

View file

@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h" #include "core/application.h"
#include "core/click_handler_types.h" #include "core/click_handler_types.h"
#include "core/core_settings.h" #include "core/core_settings.h"
#include "core/local_url_handlers.h"
#include "core/update_checker.h" #include "core/update_checker.h"
#include "data/data_changes.h" #include "data/data_changes.h"
#include "data/data_document.h" #include "data/data_document.h"
@ -1274,11 +1275,12 @@ ClickHandlerPtr Controller::lookupAreaHandler(QPoint point) const {
}); });
} }
} }
const auto weak = base::make_weak(this);
for (const auto &url : _urlAreas) { for (const auto &url : _urlAreas) {
_areas.push_back({ _areas.push_back({
.original = url.area.geometry, .original = url.area.geometry,
.rotation = url.area.rotation, .rotation = url.area.rotation,
.handler = std::make_shared<HiddenUrlClickHandler>(url.url), .handler = MakeUrlAreaHandler(weak, url.url),
}); });
} }
for (const auto &weather : _weatherAreas) { for (const auto &weather : _weatherAreas) {
@ -1940,4 +1942,34 @@ ClickHandlerPtr MakeChannelPostHandler(
})); }));
} }
ClickHandlerPtr MakeUrlAreaHandler(
base::weak_ptr<Controller> weak,
const QString &url) {
class Handler final : public HiddenUrlClickHandler {
public:
Handler(const QString &url, base::weak_ptr<Controller> weak)
: HiddenUrlClickHandler(url), _weak(weak) {
}
void onClick(ClickContext context) const override {
const auto raw = url();
const auto strong = _weak.get();
const auto prefix = u"tg://nft?slug="_q;
if (raw.startsWith(prefix) && strong) {
const auto slug = raw.mid(
prefix.size()
).split('&').front().split('#').front();
Core::ResolveAndShowUniqueGift(strong->uiShow(), slug);
} else {
HiddenUrlClickHandler::onClick(context);
}
}
private:
base::weak_ptr<Controller> _weak;
};
return std::make_shared<Handler>(url, weak);
}
} // namespace Media::Stories } // namespace Media::Stories

View file

@ -349,5 +349,8 @@ void ReportRequested(
[[nodiscard]] ClickHandlerPtr MakeChannelPostHandler( [[nodiscard]] ClickHandlerPtr MakeChannelPostHandler(
not_null<Main::Session*> session, not_null<Main::Session*> session,
FullMsgId item); FullMsgId item);
[[nodiscard]] ClickHandlerPtr MakeUrlAreaHandler(
base::weak_ptr<Controller> weak,
const QString &url);
} // namespace Media::Stories } // namespace Media::Stories

View file

@ -350,8 +350,7 @@ struct Feature {
box->closeBox(); box->closeBox();
} else if (!now.premium) { } else if (!now.premium) {
data->requested = false; data->requested = false;
const auto usage = ChatHelpers::WindowUsage::PremiumPromo; if (const auto window = show->resolveWindow()) {
if (const auto window = show->resolveWindow(usage)) {
ShowPremiumPreviewBox(window, PremiumFeature::Stories); ShowPremiumPreviewBox(window, PremiumFeature::Stories);
window->window().activate(); window->window().activate();
} }

View file

@ -1332,8 +1332,7 @@ void OverlayWidget::checkForSaveLoaded() {
void OverlayWidget::showPremiumDownloadPromo() { void OverlayWidget::showPremiumDownloadPromo() {
const auto filter = [=](const auto &...) { const auto filter = [=](const auto &...) {
const auto usage = ChatHelpers::WindowUsage::PremiumPromo; if (const auto window = uiShow()->resolveWindow()) {
if (const auto window = uiShow()->resolveWindow(usage)) {
ShowPremiumPreviewBox(window, PremiumFeature::Stories); ShowPremiumPreviewBox(window, PremiumFeature::Stories);
window->window().activate(); window->window().activate();
} }

View file

@ -522,8 +522,7 @@ void EffectPreview::setupSend(Details details) {
}, _actionWithEffect); }, _actionWithEffect);
} else { } else {
_premiumPromoLabel->entity()->setClickHandlerFilter([=](auto&&...) { _premiumPromoLabel->entity()->setClickHandlerFilter([=](auto&&...) {
const auto window = _show->resolveWindow( const auto window = _show->resolveWindow();
ChatHelpers::WindowUsage::PremiumPromo);
if (window) { if (window) {
if (const auto onstack = _close) { if (const auto onstack = _close) {
onstack(); onstack();

View file

@ -303,9 +303,7 @@ rpl::producer<std::shared_ptr<StickerPlayer>> IconPlayerValue(
}, right->lifetime()); }, right->lifetime());
raw->setClickedCallback([=] { raw->setClickedCallback([=] {
const auto controller = show->resolveWindow( if (const auto controller = show->resolveWindow()) {
ChatHelpers::WindowUsage::PremiumPromo);
if (controller) {
state->panel.show({ state->panel.show({
.controller = controller, .controller = controller,
.button = right, .button = right,

View file

@ -170,29 +170,24 @@ private:
}; };
void ToggleStarGiftSaved( void ToggleStarGiftSaved(
not_null<Window::SessionController*> window, std::shared_ptr<ChatHelpers::Show> show,
not_null<UserData*> sender, not_null<UserData*> sender,
MsgId itemId, MsgId itemId,
bool save, bool save,
Fn<void(bool)> done) { Fn<void(bool)> done) {
using Flag = MTPpayments_SaveStarGift::Flag; using Flag = MTPpayments_SaveStarGift::Flag;
const auto api = &window->session().api(); const auto api = &show->session().api();
const auto weak = base::make_weak(window);
api->request(MTPpayments_SaveStarGift( api->request(MTPpayments_SaveStarGift(
MTP_flags(save ? Flag(0) : Flag::f_unsave), MTP_flags(save ? Flag(0) : Flag::f_unsave),
MTP_int(itemId.bare) MTP_int(itemId.bare)
)).done([=] { )).done([=] {
done(true); done(true);
if (const auto strong = weak.get()) { show->showToast((save
strong->showToast((save
? tr::lng_gift_display_done ? tr::lng_gift_display_done
: tr::lng_gift_display_done_hide)(tr::now)); : tr::lng_gift_display_done_hide)(tr::now));
}
}).fail([=](const MTP::Error &error) { }).fail([=](const MTP::Error &error) {
done(false); done(false);
if (const auto strong = weak.get()) { show->showToast(error.type());
strong->showToast(error.type());
}
}).send(); }).send();
} }
@ -229,36 +224,33 @@ void ConfirmConvertStarGift(
} }
void ConvertStarGift( void ConvertStarGift(
not_null<Window::SessionController*> window, std::shared_ptr<ChatHelpers::Show> show,
not_null<UserData*> sender, not_null<UserData*> sender,
MsgId itemId, MsgId itemId,
int stars, int stars,
Fn<void(bool)> done) { Fn<void(bool)> done) {
const auto api = &window->session().api(); const auto api = &show->session().api();
const auto weak = base::make_weak(window);
api->request(MTPpayments_ConvertStarGift( api->request(MTPpayments_ConvertStarGift(
MTP_int(itemId) MTP_int(itemId)
)).done([=] { )).done([=] {
if (const auto strong = weak.get()) { if (const auto window = show->resolveWindow()) {
strong->showSettings(Settings::CreditsId()); window->showSettings(Settings::CreditsId());
strong->showToast(tr::lng_gift_got_stars( }
show->showToast(tr::lng_gift_got_stars(
tr::now, tr::now,
lt_count, lt_count,
stars, stars,
Ui::Text::RichLangValue)); Ui::Text::RichLangValue));
}
done(true); done(true);
}).fail([=](const MTP::Error &error) { }).fail([=](const MTP::Error &error) {
if (const auto strong = weak.get()) { show->showToast(error.type());
strong->showToast(error.type());
}
done(false); done(false);
}).send(); }).send();
} }
void AddViewMediaHandler( void AddViewMediaHandler(
not_null<Ui::RpWidget*> thumb, not_null<Ui::RpWidget*> thumb,
not_null<Window::SessionController*> controller, std::shared_ptr<ChatHelpers::Show> show,
const Data::CreditsHistoryEntry &e) { const Data::CreditsHistoryEntry &e) {
if (e.extended.empty()) { if (e.extended.empty()) {
return; return;
@ -277,7 +269,7 @@ void AddViewMediaHandler(
bool over = false; bool over = false;
}; };
const auto state = thumb->lifetime().make_state<State>(); const auto state = thumb->lifetime().make_state<State>();
const auto session = &controller->session(); const auto session = &show->session();
const auto owner = &session->data(); const auto owner = &session->data();
const auto peerId = e.barePeerId const auto peerId = e.barePeerId
? PeerId(e.barePeerId) ? PeerId(e.barePeerId)
@ -315,24 +307,27 @@ void AddViewMediaHandler(
.extendedMedia = std::move(fake), .extendedMedia = std::move(fake),
.isPaidMedia = true, .isPaidMedia = true,
})); }));
const auto showMedia = crl::guard(controller, [=] { const auto showMedia = [=] {
if (const auto media = state->item->media()) { const auto window = show->resolveWindow();
if (!window) {
return;
} else if (const auto media = state->item->media()) {
if (const auto invoice = media->invoice()) { if (const auto invoice = media->invoice()) {
if (!invoice->extendedMedia.empty()) { if (!invoice->extendedMedia.empty()) {
const auto first = invoice->extendedMedia[0].get(); const auto first = invoice->extendedMedia[0].get();
if (const auto photo = first->photo()) { if (const auto photo = first->photo()) {
controller->openPhoto(photo, { window->openPhoto(photo, {
.id = state->item->fullId(), .id = state->item->fullId(),
}); });
} else if (const auto document = first->document()) { } else if (const auto document = first->document()) {
controller->openDocument(document, true, { window->openDocument(document, true, {
.id = state->item->fullId(), .id = state->item->fullId(),
}); });
} }
} }
} }
} }
}); };
thumb->events() | rpl::start_with_next([=](not_null<QEvent*> e) { thumb->events() | rpl::start_with_next([=](not_null<QEvent*> e) {
if (e->type() == QEvent::MouseButtonPress) { if (e->type() == QEvent::MouseButtonPress) {
const auto mouse = static_cast<QMouseEvent*>(e.get()); const auto mouse = static_cast<QMouseEvent*>(e.get());
@ -780,7 +775,7 @@ void BoostCreditsBox(
Ui::AddSkip(content); Ui::AddSkip(content);
} }
AddCreditsBoostTable(controller, content, b); AddCreditsBoostTable(controller->uiShow(), content, b);
Ui::AddSkip(content); Ui::AddSkip(content);
box->addRow(object_ptr<Ui::CenterWrap<>>( box->addRow(object_ptr<Ui::CenterWrap<>>(
@ -831,28 +826,21 @@ void ProcessReceivedSubscriptions(
} }
void FillUniqueGiftMenu( void FillUniqueGiftMenu(
not_null<Window::SessionController*> controller, std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::PopupMenu*> menu, not_null<Ui::PopupMenu*> menu,
const Data::CreditsHistoryEntry &e) { const Data::CreditsHistoryEntry &e) {
Expects(e.uniqueGift != nullptr); Expects(e.uniqueGift != nullptr);
const auto unique = e.uniqueGift; const auto unique = e.uniqueGift;
const auto show = controller->uiShow();
const auto weak = base::make_weak(controller);
const auto local = u"nft/"_q + unique->slug; const auto local = u"nft/"_q + unique->slug;
const auto url = controller->session().createInternalLinkFull(local); const auto url = show->session().createInternalLinkFull(local);
menu->addAction(tr::lng_context_copy_link(tr::now), [=] { menu->addAction(tr::lng_context_copy_link(tr::now), [=] {
TextUtilities::SetClipboardText({ url }); TextUtilities::SetClipboardText({ url });
if (const auto strong = weak.get()) { show->showToast(tr::lng_channel_public_link_copied(tr::now));
strong->showToast(
tr::lng_channel_public_link_copied(tr::now));
}
}, &st::menuIconLink); }, &st::menuIconLink);
menu->addAction(tr::lng_chat_link_share(tr::now), [=] { menu->addAction(tr::lng_chat_link_share(tr::now), [=] {
if (const auto strong = weak.get()) { FastShareLink(show, url);
FastShareLink(strong, url);
}
}, &st::menuIconShare); }, &st::menuIconShare);
const auto messageId = MsgId(e.bareMsgId); const auto messageId = MsgId(e.bareMsgId);
@ -861,20 +849,23 @@ void FillUniqueGiftMenu(
&& (unique->starsForTransfer >= 0); && (unique->starsForTransfer >= 0);
if (transfer) { if (transfer) {
menu->addAction(tr::lng_gift_transfer_button(tr::now), [=] { menu->addAction(tr::lng_gift_transfer_button(tr::now), [=] {
if (const auto strong = weak.get()) { if (const auto window = show->resolveWindow()) {
ShowTransferGiftBox(strong, unique, messageId); ShowTransferGiftBox(window, unique, messageId);
} }
}, &st::menuIconReplace); }, &st::menuIconReplace);
} }
} }
void ReceiptCreditsBox( void GenericCreditsEntryBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> controller, std::shared_ptr<ChatHelpers::Show> show,
const Data::CreditsHistoryEntry &e, const Data::CreditsHistoryEntry &e,
const Data::SubscriptionEntry &s) { const Data::SubscriptionEntry &s) {
const auto item = controller->session().data().message( const auto session = &show->session();
PeerId(e.barePeerId), MsgId(e.bareMsgId)); const auto owner = &session->data();
const auto item = owner->message(
PeerId(e.barePeerId),
MsgId(e.bareMsgId));
const auto isStarGift = e.stargift || e.soldOutInfo; const auto isStarGift = e.stargift || e.soldOutInfo;
const auto creditsHistoryStarGift = isStarGift && !e.id.isEmpty(); const auto creditsHistoryStarGift = isStarGift && !e.id.isEmpty();
const auto sentStarGift = creditsHistoryStarGift && !e.in; const auto sentStarGift = creditsHistoryStarGift && !e.in;
@ -883,10 +874,10 @@ void ReceiptCreditsBox(
const auto starGiftSender = (isStarGift && item) const auto starGiftSender = (isStarGift && item)
? item->history()->peer->asUser() ? item->history()->peer->asUser()
: (isStarGift && e.in) : (isStarGift && e.in)
? controller->session().data().peer(PeerId(e.barePeerId))->asUser() ? owner->peer(PeerId(e.barePeerId))->asUser()
: nullptr; : nullptr;
const auto convertLast = base::unixtime::serialize(e.date) const auto convertLast = base::unixtime::serialize(e.date)
+ controller->session().appConfig().stargiftConvertPeriodMax(); + session->appConfig().stargiftConvertPeriodMax();
const auto timeLeft = int64(convertLast) - int64(base::unixtime::now()); const auto timeLeft = int64(convertLast) - int64(base::unixtime::now());
const auto timeExceeded = (timeLeft <= 0); const auto timeExceeded = (timeLeft <= 0);
const auto uniqueGift = e.uniqueGift.get(); const auto uniqueGift = e.uniqueGift.get();
@ -912,21 +903,20 @@ void ReceiptCreditsBox(
using Type = Data::CreditsHistoryEntry::PeerType; using Type = Data::CreditsHistoryEntry::PeerType;
const auto &stUser = st::boostReplaceUserpic; const auto &stUser = st::boostReplaceUserpic;
const auto session = &controller->session();
const auto isPrize = e.bareGiveawayMsgId > 0; const auto isPrize = e.bareGiveawayMsgId > 0;
const auto starGiftSticker = (isStarGift && e.bareGiftStickerId) const auto starGiftSticker = (isStarGift && e.bareGiftStickerId)
? session->data().document(e.bareGiftStickerId).get() ? owner->document(e.bareGiftStickerId).get()
: nullptr; : nullptr;
const auto peer = isPrize const auto peer = isPrize
? nullptr ? nullptr
: (s.barePeerId) : (s.barePeerId)
? session->data().peer(PeerId(s.barePeerId)).get() ? owner->peer(PeerId(s.barePeerId)).get()
: (e.peerType == Type::PremiumBot) : (e.peerType == Type::PremiumBot)
? nullptr ? nullptr
: e.bareActorId : e.bareActorId
? session->data().peer(PeerId(e.bareActorId)).get() ? owner->peer(PeerId(e.bareActorId)).get()
: e.barePeerId : e.barePeerId
? session->data().peer(PeerId(e.barePeerId)).get() ? owner->peer(PeerId(e.barePeerId)).get()
: nullptr; : nullptr;
if (uniqueGift) { if (uniqueGift) {
box->setNoContentMargin(true); box->setNoContentMargin(true);
@ -936,13 +926,13 @@ void ReceiptCreditsBox(
AddSkip(content, st::defaultVerticalListSkip * 2); AddSkip(content, st::defaultVerticalListSkip * 2);
AddUniqueCloseButton(box, [=](not_null<Ui::PopupMenu*> menu) { AddUniqueCloseButton(box, [=](not_null<Ui::PopupMenu*> menu) {
FillUniqueGiftMenu(controller, menu, e); FillUniqueGiftMenu(show, menu, e);
}); });
} else if (const auto callback = Ui::PaintPreviewCallback(session, e)) { } else if (const auto callback = Ui::PaintPreviewCallback(session, e)) {
const auto thumb = content->add(object_ptr<Ui::CenterWrap<>>( const auto thumb = content->add(object_ptr<Ui::CenterWrap<>>(
content, content,
GenericEntryPhoto(content, callback, stUser.photoSize))); GenericEntryPhoto(content, callback, stUser.photoSize)));
AddViewMediaHandler(thumb->entity(), controller, e); AddViewMediaHandler(thumb->entity(), show, e);
} else if (s.photoId || (e.photoId && !e.subscriptionUntil.isNull())) { } else if (s.photoId || (e.photoId && !e.subscriptionUntil.isNull())) {
if (!(s.cancelled || s.expired || s.cancelledByBot)) { if (!(s.cancelled || s.expired || s.cancelledByBot)) {
const auto widget = Ui::CreateChild<Ui::RpWidget>(content); const auto widget = Ui::CreateChild<Ui::RpWidget>(content);
@ -952,7 +942,7 @@ void ReceiptCreditsBox(
const auto photoId = s.photoId ? s.photoId : e.photoId; const auto photoId = s.photoId ? s.photoId : e.photoId;
const auto callback = [=](Fn<void()> update) { const auto callback = [=](Fn<void()> update) {
return Ui::GenerateCreditsPaintEntryCallback( return Ui::GenerateCreditsPaintEntryCallback(
session->data().photo(photoId), owner->photo(photoId),
std::move(update)); std::move(update));
}; };
content->add(object_ptr<Ui::CenterWrap<>>( content->add(object_ptr<Ui::CenterWrap<>>(
@ -1132,7 +1122,7 @@ void ReceiptCreditsBox(
tr::lng_credits_subscription_subtitle( tr::lng_credits_subscription_subtitle(
tr::now, tr::now,
lt_emoji, lt_emoji,
session->data().customEmojiManager().creditsEmoji(), owner->customEmojiManager().creditsEmoji(),
lt_cost, lt_cost,
{ QString::number(s.subscription.credits) }, { QString::number(s.subscription.credits) },
Ui::Text::WithEntities), Ui::Text::WithEntities),
@ -1147,7 +1137,7 @@ void ReceiptCreditsBox(
: QString(kMinus)) : QString(kMinus))
.append(Lang::FormatStarsAmountDecimal(e.credits.abs())) .append(Lang::FormatStarsAmountDecimal(e.credits.abs()))
.append(QChar(' ')) .append(QChar(' '))
.append(session->data().customEmojiManager().creditsEmoji()); .append(owner->customEmojiManager().creditsEmoji());
text->setMarkedText( text->setMarkedText(
st::semiboldTextStyle, st::semiboldTextStyle,
std::move(t), std::move(t),
@ -1280,7 +1270,7 @@ void ReceiptCreditsBox(
} else if (e.gift || isPrize) { } else if (e.gift || isPrize) {
Ui::AddSkip(content); Ui::AddSkip(content);
const auto arrow = Ui::Text::SingleCustomEmoji( const auto arrow = Ui::Text::SingleCustomEmoji(
session->data().customEmojiManager().registerInternalEmoji( owner->customEmojiManager().registerInternalEmoji(
st::topicButtonArrow, st::topicButtonArrow,
st::channelEarnLearnArrowMargins, st::channelEarnLearnArrowMargins,
true)); true));
@ -1320,20 +1310,14 @@ void ReceiptCreditsBox(
rpl::variable<bool> convertButtonBusy; rpl::variable<bool> convertButtonBusy;
}; };
const auto state = box->lifetime().make_state<State>(); const auto state = box->lifetime().make_state<State>();
const auto weakWindow = base::make_weak(controller);
const auto toggleVisibility = [=, weak = Ui::MakeWeak(box)](bool save) { const auto toggleVisibility = [=, weak = Ui::MakeWeak(box)](bool save) {
const auto window = weakWindow.get();
const auto showSection = !e.fromGiftsList; const auto showSection = !e.fromGiftsList;
const auto itemId = MsgId(e.bareMsgId); const auto itemId = MsgId(e.bareMsgId);
if (!window) {
return;
}
const auto done = [=](bool ok) { const auto done = [=](bool ok) {
if (const auto window = weakWindow.get()) {
if (ok) { if (ok) {
using GiftAction = Data::GiftUpdate::Action; using GiftAction = Data::GiftUpdate::Action;
window->session().data().notifyGiftUpdate({ show->session().data().notifyGiftUpdate({
.itemId = FullMsgId( .itemId = FullMsgId(
starGiftSender->id, starGiftSender->id,
itemId), itemId),
@ -1342,6 +1326,7 @@ void ReceiptCreditsBox(
: GiftAction::Unsave), : GiftAction::Unsave),
}); });
if (showSection) { if (showSection) {
if (const auto window = show->resolveWindow()) {
window->showSection( window->showSection(
std::make_shared<Info::Memento>( std::make_shared<Info::Memento>(
window->session().user(), window->session().user(),
@ -1357,19 +1342,14 @@ void ReceiptCreditsBox(
} }
} }
}; };
ToggleStarGiftSaved( ToggleStarGiftSaved(show, starGiftSender, itemId, save, done);
window,
starGiftSender,
itemId,
save,
done);
}; };
const auto upgradeGuard = std::make_shared<bool>(); const auto upgradeGuard = std::make_shared<bool>();
const auto upgrade = [=] { const auto upgrade = [=] {
if (const auto window = weakWindow.get()) {
const auto itemId = MsgId(e.bareMsgId); const auto itemId = MsgId(e.bareMsgId);
if (*upgradeGuard) { const auto window = show->resolveWindow();
if (!window || *upgradeGuard) {
return; return;
} }
*upgradeGuard = true; *upgradeGuard = true;
@ -1389,7 +1369,6 @@ void ReceiptCreditsBox(
.addDetailsDefault = (giftToSelf .addDetailsDefault = (giftToSelf
|| (e.starsUpgradedBySender && !e.anonymous)), || (e.starsUpgradedBySender && !e.anonymous)),
}); });
}
}; };
const auto canUpgrade = e.stargiftId const auto canUpgrade = e.stargiftId
&& e.canUpgradeGift && e.canUpgradeGift
@ -1402,27 +1381,24 @@ void ReceiptCreditsBox(
const auto stars = e.starsConverted; const auto stars = e.starsConverted;
const auto days = canConvert ? ((timeLeft + 86399) / 86400) : 0; const auto days = canConvert ? ((timeLeft + 86399) / 86400) : 0;
const auto name = starGiftSender->shortName(); const auto name = starGiftSender->shortName();
ConfirmConvertStarGift(box->uiShow(), name, stars, days, [=] { ConfirmConvertStarGift(show, name, stars, days, [=] {
if (state->convertButtonBusy.current() if (state->convertButtonBusy.current()
|| state->confirmButtonBusy.current()) { || state->confirmButtonBusy.current()) {
return; return;
} }
state->convertButtonBusy = true; state->convertButtonBusy = true;
const auto window = weakWindow.get();
const auto itemId = MsgId(e.bareMsgId); const auto itemId = MsgId(e.bareMsgId);
if (window && stars) { if (stars) {
const auto done = [=](bool ok) { const auto done = [=](bool ok) {
if (const auto window = weakWindow.get()) {
if (ok) { if (ok) {
using GiftAction = Data::GiftUpdate::Action; using GiftAction = Data::GiftUpdate::Action;
window->session().data().notifyGiftUpdate({ show->session().data().notifyGiftUpdate({
.itemId = FullMsgId( .itemId = FullMsgId(
starGiftSender->id, starGiftSender->id,
itemId), itemId),
.action = GiftAction::Convert, .action = GiftAction::Convert,
}); });
} }
}
if (const auto strong = weak.data()) { if (const auto strong = weak.data()) {
if (ok) { if (ok) {
strong->closeBox(); strong->closeBox();
@ -1432,7 +1408,7 @@ void ReceiptCreditsBox(
} }
}; };
ConvertStarGift( ConvertStarGift(
window, show,
starGiftSender, starGiftSender,
itemId, itemId,
stars, stars,
@ -1445,15 +1421,15 @@ void ReceiptCreditsBox(
&& !e.giftRefunded; && !e.giftRefunded;
AddStarGiftTable( AddStarGiftTable(
controller, show,
content, content,
e, e,
canToggle ? toggleVisibility : Fn<void(bool)>(), canToggle ? toggleVisibility : Fn<void(bool)>(),
canConvert ? convert : Fn<void()>(), canConvert ? convert : Fn<void()>(),
canUpgrade ? upgrade : Fn<void()>()); canUpgrade ? upgrade : Fn<void()>());
} else { } else {
AddCreditsHistoryEntryTable(controller, content, e); AddCreditsHistoryEntryTable(show, content, e);
AddSubscriptionEntryTable(controller, content, s); AddSubscriptionEntryTable(show, content, s);
} }
Ui::AddSkip(content); Ui::AddSkip(content);
@ -1565,7 +1541,7 @@ void ReceiptCreditsBox(
: tr::lng_box_ok())); : tr::lng_box_ok()));
const auto send = [=, weak = Ui::MakeWeak(box)] { const auto send = [=, weak = Ui::MakeWeak(box)] {
if (toRejoin) { if (toRejoin) {
if (const auto window = weakWindow.get()) { if (const auto window = show->resolveWindow()) {
const auto finish = [=](Payments::CheckoutResult&&) { const auto finish = [=](Payments::CheckoutResult&&) {
ProcessReceivedSubscriptions(weak, session); ProcessReceivedSubscriptions(weak, session);
}; };
@ -1578,9 +1554,11 @@ void ReceiptCreditsBox(
finish)); finish));
} }
} else if (toRenew && s.expired) { } else if (toRenew && s.expired) {
Api::CheckChatInvite(controller, s.inviteHash, nullptr, [=] { if (const auto window = show->resolveWindow()) {
Api::CheckChatInvite(window, s.inviteHash, nullptr, [=] {
ProcessReceivedSubscriptions(weak, session); ProcessReceivedSubscriptions(weak, session);
}); });
}
} else { } else {
const auto done = [=] { const auto done = [=] {
ProcessReceivedSubscriptions(weak, session); ProcessReceivedSubscriptions(weak, session);
@ -1638,6 +1616,14 @@ void ReceiptCreditsBox(
}, button->lifetime()); }, button->lifetime());
} }
void ReceiptCreditsBox(
not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> controller,
const Data::CreditsHistoryEntry &e,
const Data::SubscriptionEntry &s) {
GenericCreditsEntryBox(box, controller->uiShow(), e, s);
}
void GiftedCreditsBox( void GiftedCreditsBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
@ -1691,12 +1677,12 @@ void CreditsPrizeBox(
void GlobalStarGiftBox( void GlobalStarGiftBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> controller, std::shared_ptr<ChatHelpers::Show> show,
const Data::StarGift &data) { const Data::StarGift &data) {
const auto ownerId = data.unique ? data.unique->ownerId.value : 0; const auto ownerId = data.unique ? data.unique->ownerId.value : 0;
Settings::ReceiptCreditsBox( Settings::GenericCreditsEntryBox(
box, box,
controller, show,
Data::CreditsHistoryEntry{ Data::CreditsHistoryEntry{
.credits = StarsAmount(data.stars), .credits = StarsAmount(data.stars),
.bareGiftStickerId = data.document->id, .bareGiftStickerId = data.document->id,
@ -1708,7 +1694,7 @@ void GlobalStarGiftBox(
.limitedLeft = data.limitedLeft, .limitedLeft = data.limitedLeft,
.stargift = true, .stargift = true,
.fromGiftSlug = true, .fromGiftSlug = true,
.in = (ownerId == controller->session().userPeerId().value), .in = (ownerId == show->session().userPeerId().value),
.gift = true, .gift = true,
}, },
Data::SubscriptionEntry()); Data::SubscriptionEntry());

View file

@ -12,6 +12,10 @@ class object_ptr;
class PeerData; class PeerData;
namespace ChatHelpers {
class Show;
} // namespace ChatHelpers
namespace Data { namespace Data {
struct Boost; struct Boost;
struct CreditsHistoryEntry; struct CreditsHistoryEntry;
@ -77,6 +81,11 @@ void AddWithdrawalWidget(
bool withdrawalEnabled, bool withdrawalEnabled,
rpl::producer<QString> usdValue); rpl::producer<QString> usdValue);
void GenericCreditsEntryBox(
not_null<Ui::GenericBox*> box,
std::shared_ptr<ChatHelpers::Show> show,
const Data::CreditsHistoryEntry &e,
const Data::SubscriptionEntry &s);
void ReceiptCreditsBox( void ReceiptCreditsBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
@ -100,7 +109,7 @@ void CreditsPrizeBox(
TimeId date); TimeId date);
void GlobalStarGiftBox( void GlobalStarGiftBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> controller, std::shared_ptr<ChatHelpers::Show> show,
const Data::StarGift &data); const Data::StarGift &data);
void UserStarGiftBox( void UserStarGiftBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,

View file

@ -1376,19 +1376,17 @@ void ShowPremiumPromoToast(
TextWithEntities textWithLink, TextWithEntities textWithLink,
const QString &ref) { const QString &ref) {
ShowPremiumPromoToast(show, [=]( ShowPremiumPromoToast(show, [=](
not_null<Main::Session*> session, not_null<Main::Session*> session) {
ChatHelpers::WindowUsage usage) {
Expects(&show->session() == session); Expects(&show->session() == session);
return show->resolveWindow(usage); return show->resolveWindow();
}, std::move(textWithLink), ref); }, std::move(textWithLink), ref);
} }
void ShowPremiumPromoToast( void ShowPremiumPromoToast(
std::shared_ptr<Main::SessionShow> show, std::shared_ptr<Main::SessionShow> show,
Fn<Window::SessionController*( Fn<Window::SessionController*(
not_null<Main::Session*>, not_null<Main::Session*>)> resolveWindow,
ChatHelpers::WindowUsage)> resolveWindow,
TextWithEntities textWithLink, TextWithEntities textWithLink,
const QString &ref) { const QString &ref) {
using WeakToast = base::weak_ptr<Ui::Toast::Instance>; using WeakToast = base::weak_ptr<Ui::Toast::Instance>;
@ -1403,8 +1401,7 @@ void ShowPremiumPromoToast(
strong->hideAnimated(); strong->hideAnimated();
(*toast) = nullptr; (*toast) = nullptr;
if (const auto controller = resolveWindow( if (const auto controller = resolveWindow(
&show->session(), &show->session())) {
ChatHelpers::WindowUsage::PremiumPromo)) {
Settings::ShowPremium(controller, ref); Settings::ShowPremium(controller, ref);
} }
return true; return true;
@ -1476,12 +1473,10 @@ not_null<Ui::GradientButton*> CreateSubscribeButton(
Expects(args.show || args.controller); Expects(args.show || args.controller);
auto show = args.show ? std::move(args.show) : args.controller->uiShow(); auto show = args.show ? std::move(args.show) : args.controller->uiShow();
auto resolve = [show]( auto resolve = [show](not_null<Main::Session*> session) {
not_null<Main::Session*> session,
ChatHelpers::WindowUsage usage) {
Expects(session == &show->session()); Expects(session == &show->session());
return show->resolveWindow(usage); return show->resolveWindow();
}; };
return CreateSubscribeButton( return CreateSubscribeButton(
std::move(show), std::move(show),
@ -1492,8 +1487,7 @@ not_null<Ui::GradientButton*> CreateSubscribeButton(
not_null<Ui::GradientButton*> CreateSubscribeButton( not_null<Ui::GradientButton*> CreateSubscribeButton(
std::shared_ptr<::Main::SessionShow> show, std::shared_ptr<::Main::SessionShow> show,
Fn<Window::SessionController*( Fn<Window::SessionController*(
not_null<::Main::Session*>, not_null<::Main::Session*>)> resolveWindow,
ChatHelpers::WindowUsage)> resolveWindow,
SubscribeButtonArgs &&args) { SubscribeButtonArgs &&args) {
const auto result = Ui::CreateChild<Ui::GradientButton>( const auto result = Ui::CreateChild<Ui::GradientButton>(
args.parent.get(), args.parent.get(),
@ -1508,8 +1502,7 @@ not_null<Ui::GradientButton*> CreateSubscribeButton(
computeRef = args.computeRef, computeRef = args.computeRef,
computeBotUrl = args.computeBotUrl] { computeBotUrl = args.computeBotUrl] {
const auto window = resolveWindow( const auto window = resolveWindow(
&show->session(), &show->session());
ChatHelpers::WindowUsage::PremiumPromo);
if (!window) { if (!window) {
return; return;
} else if (promo) { } else if (promo) {

View file

@ -18,7 +18,6 @@ struct RoundButton;
namespace ChatHelpers { namespace ChatHelpers {
class Show; class Show;
enum class WindowUsage;
} // namespace ChatHelpers } // namespace ChatHelpers
namespace Ui { namespace Ui {
@ -66,9 +65,7 @@ void ShowPremiumPromoToast(
const QString &ref); const QString &ref);
void ShowPremiumPromoToast( void ShowPremiumPromoToast(
std::shared_ptr<::Main::SessionShow> show, std::shared_ptr<::Main::SessionShow> show,
Fn<Window::SessionController*( Fn<Window::SessionController*(not_null<::Main::Session*>)> resolveWindow,
not_null<::Main::Session*>,
ChatHelpers::WindowUsage)> resolveWindow,
TextWithEntities textWithLink, TextWithEntities textWithLink,
const QString &ref); const QString &ref);
@ -95,9 +92,7 @@ struct SubscribeButtonArgs final {
[[nodiscard]] not_null<Ui::GradientButton*> CreateSubscribeButton( [[nodiscard]] not_null<Ui::GradientButton*> CreateSubscribeButton(
std::shared_ptr<::Main::SessionShow> show, std::shared_ptr<::Main::SessionShow> show,
Fn<Window::SessionController*( Fn<Window::SessionController*(not_null<::Main::Session*>)> resolveWindow,
not_null<::Main::Session*>,
ChatHelpers::WindowUsage)> resolveWindow,
SubscribeButtonArgs &&args); SubscribeButtonArgs &&args);
[[nodiscard]] std::vector<PremiumFeature> PremiumFeaturesOrder( [[nodiscard]] std::vector<PremiumFeature> PremiumFeaturesOrder(