Skip to content

Commit

Permalink
Support tg://premium_multigift links.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jan 1, 2024
1 parent a30d0ec commit a4d7309
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
11 changes: 6 additions & 5 deletions Telegram/SourceFiles/boxes/gift_premium_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ void GiftsBox(
not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> controller,
std::vector<not_null<UserData*>> users,
not_null<Api::PremiumGiftCodeOptions*> api) {
not_null<Api::PremiumGiftCodeOptions*> api,
const QString &ref) {
Expects(!users.empty());

const auto boxWidth = st::boxWideWidth;
Expand Down Expand Up @@ -591,7 +592,7 @@ void GiftsBox(
Settings::AddSummaryPremium(
content,
controller,
u"gift"_q,
ref,
std::move(buttonCallback));
}

Expand All @@ -614,7 +615,7 @@ void GiftsBox(
auto raw = Settings::CreateSubscribeButton({
controller,
box,
[] { return u"gift"_q; },
[=] { return ref; },
rpl::combine(
state->buttonText.events(),
state->confirmButtonBusy.value(),
Expand Down Expand Up @@ -876,7 +877,7 @@ void GiftPremiumValidator::cancel() {
_requestId = 0;
}

void GiftPremiumValidator::showChoosePeerBox() {
void GiftPremiumValidator::showChoosePeerBox(const QString &ref) {
if (_manyGiftsLifetime) {
return;
}
Expand Down Expand Up @@ -936,7 +937,7 @@ void GiftPremiumValidator::showChoosePeerBox() {
}) | ranges::to<std::vector<not_null<UserData*>>>();
if (!users.empty()) {
const auto giftBox = show->show(
Box(GiftsBox, _controller, users, api));
Box(GiftsBox, _controller, users, api, ref));
giftBox->boxClosing(
) | rpl::start_with_next([=] {
_manyGiftsLifetime.destroy();
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/boxes/gift_premium_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GiftPremiumValidator final {
GiftPremiumValidator(not_null<Window::SessionController*> controller);

void showBox(not_null<UserData*> user);
void showChoosePeerBox();
void showChoosePeerBox(const QString &ref);
void cancel();

private:
Expand Down
19 changes: 19 additions & 0 deletions Telegram/SourceFiles/core/local_url_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,21 @@ bool ResolvePremiumOffer(
return true;
}

bool ResolvePremiumMultigift(
Window::SessionController *controller,
const Match &match,
const QVariant &context) {
if (!controller) {
return false;
}
const auto params = url_parse_params(
match->captured(1).mid(1),
qthelp::UrlParamNameTransform::ToLower);
controller->showGiftPremiumsBox(params.value(u"ref"_q, u"gift_url"_q));
controller->window().activate();
return true;
}

bool ResolveLoginCode(
Window::SessionController *controller,
const Match &match,
Expand Down Expand Up @@ -968,6 +983,10 @@ const std::vector<LocalUrlHandler> &LocalUrlHandlers() {
u"premium_offer/?(\\?.+)?(#|$)"_q,
ResolvePremiumOffer,
},
{
u"^premium_multigift/?\\?(.+)(#|$)"_q,
ResolvePremiumMultigift,
},
{
u"^login/?(\\?code=([0-9]+))(&|$)"_q,
ResolveLoginCode
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/settings/settings_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void SetupPremium(
{ .icon = &st::menuIconGiftPremium }
);
button->addClickHandler([=] {
controller->showGiftPremiumsBox();
controller->showGiftPremiumsBox(u"gift"_q);
});
constexpr auto kNewExpiresAt = int(1735689600);
if (base::unixtime::now() < kNewExpiresAt) {
Expand Down
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/window/window_session_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,8 +1218,8 @@ void SessionController::showGiftPremiumBox(UserData *user) {
}
}

void SessionController::showGiftPremiumsBox() {
_giftPremiumValidator.showChoosePeerBox();
void SessionController::showGiftPremiumsBox(const QString &ref) {
_giftPremiumValidator.showChoosePeerBox(ref);
}

void SessionController::init() {
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/window/window_session_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class SessionController : public SessionNavigation {

void showEditPeerBox(PeerData *peer);
void showGiftPremiumBox(UserData *user);
void showGiftPremiumsBox();
void showGiftPremiumsBox(const QString &ref);

void enableGifPauseReason(GifPauseReason reason);
void disableGifPauseReason(GifPauseReason reason);
Expand Down

0 comments on commit a4d7309

Please sign in to comment.