Jump to giveaway link from gift code box.

This commit is contained in:
John Preston 2023-10-11 13:47:21 +04:00
parent 981babf302
commit 714dae054a
6 changed files with 38 additions and 13 deletions

View File

@ -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";

View File

@ -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(),
};
}

View File

@ -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;

View File

@ -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<Ui::FlatLabel*> AddTableRow(
not_null<Ui::TableLayout*> table,
rpl::producer<QString> label,
rpl::producer<QString> value) {
rpl::producer<TextWithEntities> value) {
auto widget = object_ptr<Ui::FlatLabel>(
table,
std::move(value),
st::giveawayGiftCodeValue);
const auto result = widget.data();
AddTableRow(
table,
std::move(label),
object_ptr<Ui::FlatLabel>(
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);
}

View File

@ -17,7 +17,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_premium.h"
namespace Ui {
namespace {
void StartFireworks(not_null<QWidget*> parent) {
const auto result = Ui::CreateChild<RpWidget>(parent.get());
@ -37,8 +36,6 @@ void StartFireworks(not_null<QWidget*> parent) {
}, lifetime);
}
} // namespace
void BoostBox(
not_null<GenericBox*> box,
BoostBoxData data,

View File

@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Ui {
void StartFireworks(not_null<QWidget*> parent);
class GenericBox;
class VerticalLayout;