diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index a6e68c037..2f1f55dff 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2130,6 +2130,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_gift_link_gift_premium" = "Telegram Premium {duration}"; "lng_gift_link_label_reason" = "Reason"; "lng_gift_link_reason_giveaway" = "Giveaway"; +"lng_gift_link_reason_chosen" = "You were selected by the channel"; "lng_gift_link_label_date" = "Date"; "lng_gift_link_also_send" = "You can also {link} to a friend as a gift."; "lng_gift_link_also_send_link" = "send this link"; diff --git a/Telegram/SourceFiles/api/api_premium.cpp b/Telegram/SourceFiles/api/api_premium.cpp index 433660b0d..23eb237a5 100644 --- a/Telegram/SourceFiles/api/api_premium.cpp +++ b/Telegram/SourceFiles/api/api_premium.cpp @@ -23,9 +23,11 @@ namespace { return { .from = peerFromMTP(data.vfrom_id()), .to = data.vto_id() ? peerFromUser(*data.vto_id()) : PeerId(), + .giveawayId = data.vgiveaway_msg_id().value_or_empty(), .date = data.vdate().v, .used = data.vused_date().value_or_empty(), .months = data.vmonths().v, + .giveaway = data.is_via_giveaway(), }; } diff --git a/Telegram/SourceFiles/api/api_premium.h b/Telegram/SourceFiles/api/api_premium.h index 62c7b4c9a..af7b2b14c 100644 --- a/Telegram/SourceFiles/api/api_premium.h +++ b/Telegram/SourceFiles/api/api_premium.h @@ -21,9 +21,11 @@ namespace Api { struct GiftCode { PeerId from = 0; PeerId to = 0; + MsgId giveawayId = 0; TimeId date = 0; TimeId used = 0; // 0 if not used. int months = 0; + bool giveaway = false; explicit operator bool() const { return months != 0; diff --git a/Telegram/SourceFiles/boxes/gift_premium_box.cpp b/Telegram/SourceFiles/boxes/gift_premium_box.cpp index 94ff50e13..092260711 100644 --- a/Telegram/SourceFiles/boxes/gift_premium_box.cpp +++ b/Telegram/SourceFiles/boxes/gift_premium_box.cpp @@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "settings/settings_premium.h" #include "ui/basic_click_handlers.h" // UrlClickHandler::Open. +#include "ui/boxes/boost_box.h" // StartFireworks. #include "ui/controls/userpic_button.h" #include "ui/effects/premium_graphics.h" #include "ui/effects/premium_stars_colored.h" @@ -371,18 +372,21 @@ void AddTableRow( valueMargins); } -void AddTableRow( +not_null AddTableRow( not_null table, rpl::producer label, - rpl::producer value) { + rpl::producer value) { + auto widget = object_ptr( + table, + std::move(value), + st::giveawayGiftCodeValue); + const auto result = widget.data(); AddTableRow( table, std::move(label), - object_ptr( - table, - std::move(value), - st::giveawayGiftCodeValue), + std::move(widget), st::giveawayGiftCodeValueMargin); + return result; } void AddTableRow( @@ -524,16 +528,31 @@ void GiftCodeBox( tr::lng_gift_link_label_gift(), tr::lng_gift_link_gift_premium( lt_duration, - GiftDurationValue(current.months))); - AddTableRow( + GiftDurationValue(current.months) | Ui::Text::ToWithEntities(), + Ui::Text::WithEntities)); + const auto reason = AddTableRow( table, tr::lng_gift_link_label_reason(), - tr::lng_gift_link_reason_giveaway()); + (current.giveawayId + ? (tr::lng_gift_link_reason_giveaway() | Ui::Text::ToLink()) + : current.giveaway + ? (tr::lng_gift_link_reason_giveaway( + Ui::Text::WithEntities + ) | rpl::type_erased()) + : tr::lng_gift_link_reason_chosen(Ui::Text::WithEntities))); + reason->setClickHandlerFilter([=](const auto &...) { + controller->showPeerHistory( + current.from, + Window::SectionShow::Way::Forward, + current.giveawayId); + return false; + }); if (current.date) { AddTableRow( table, tr::lng_gift_link_label_date(), - rpl::single(langDateTime(base::unixtime::parse(current.date)))); + rpl::single(Ui::Text::WithEntities( + langDateTime(base::unixtime::parse(current.date))))); } auto shareLink = tr::lng_gift_link_also_send_link( @@ -590,6 +609,8 @@ void GiftCodeBox( auto copy = state->data.current(); copy.used = base::unixtime::now(); state->data = std::move(copy); + + Ui::StartFireworks(box->parentWidget()); } else { box->uiShow()->showToast(error); } diff --git a/Telegram/SourceFiles/ui/boxes/boost_box.cpp b/Telegram/SourceFiles/ui/boxes/boost_box.cpp index abae42f21..20e2e71b6 100644 --- a/Telegram/SourceFiles/ui/boxes/boost_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/boost_box.cpp @@ -17,7 +17,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_premium.h" namespace Ui { -namespace { void StartFireworks(not_null parent) { const auto result = Ui::CreateChild(parent.get()); @@ -37,8 +36,6 @@ void StartFireworks(not_null parent) { }, lifetime); } -} // namespace - void BoostBox( not_null box, BoostBoxData data, diff --git a/Telegram/SourceFiles/ui/boxes/boost_box.h b/Telegram/SourceFiles/ui/boxes/boost_box.h index e35178fac..2c688acda 100644 --- a/Telegram/SourceFiles/ui/boxes/boost_box.h +++ b/Telegram/SourceFiles/ui/boxes/boost_box.h @@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui { +void StartFireworks(not_null parent); + class GenericBox; class VerticalLayout;