Add giveaway prize service message layout.
This commit is contained in:
parent
caca679336
commit
a77131dfd6
|
@ -2119,6 +2119,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_gift_link_used_title" = "Used Gift Link";
|
"lng_gift_link_used_title" = "Used Gift Link";
|
||||||
"lng_gift_link_used_about" = "This link was used to activate\na **Telegram Premium** subscription.";
|
"lng_gift_link_used_about" = "This link was used to activate\na **Telegram Premium** subscription.";
|
||||||
"lng_gift_link_used_footer" = "This link was used on {date}.";
|
"lng_gift_link_used_footer" = "This link was used on {date}.";
|
||||||
|
"lng_gift_link_expired" = "Gift code link expired";
|
||||||
|
|
||||||
"lng_accounts_limit_title" = "Limit Reached";
|
"lng_accounts_limit_title" = "Limit Reached";
|
||||||
"lng_accounts_limit1#one" = "You have reached the limit of **{count}** connected accounts.";
|
"lng_accounts_limit1#one" = "You have reached the limit of **{count}** connected accounts.";
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace {
|
||||||
.from = peerFromMTP(data.vfrom_id()),
|
.from = peerFromMTP(data.vfrom_id()),
|
||||||
.to = data.vto_id() ? peerFromUser(*data.vto_id()) : PeerId(),
|
.to = data.vto_id() ? peerFromUser(*data.vto_id()) : PeerId(),
|
||||||
.date = data.vdate().v,
|
.date = data.vdate().v,
|
||||||
.used = false,// data.vused_date().value_or_empty(),
|
.used = data.vused_date().value_or_empty(),
|
||||||
.months = data.vmonths().v,
|
.months = data.vmonths().v,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,10 +287,7 @@ struct GiftCodeLink {
|
||||||
const auto available = outer - skipRight - skipLeft;
|
const auto available = outer - skipRight - skipLeft;
|
||||||
const auto use = std::min(textWidth, available);
|
const auto use = std::min(textWidth, available);
|
||||||
state->label.resizeToWidth(use);
|
state->label.resizeToWidth(use);
|
||||||
const auto left = (outer >= 2 * skipRight + textWidth)
|
state->label.move(outer - skipRight - use - skipLeft, 0);
|
||||||
? ((outer - textWidth) / 2)
|
|
||||||
: (outer - skipRight - use - skipLeft);
|
|
||||||
state->label.move(left, 0);
|
|
||||||
}, raw->lifetime());
|
}, raw->lifetime());
|
||||||
|
|
||||||
raw->paintRequest() | rpl::start_with_next([=] {
|
raw->paintRequest() | rpl::start_with_next([=] {
|
||||||
|
@ -516,10 +513,12 @@ void GiftCodeBox(
|
||||||
table,
|
table,
|
||||||
tr::lng_gift_link_label_reason(),
|
tr::lng_gift_link_label_reason(),
|
||||||
tr::lng_gift_link_reason_giveaway());
|
tr::lng_gift_link_reason_giveaway());
|
||||||
AddTableRow(
|
if (current.date) {
|
||||||
table,
|
AddTableRow(
|
||||||
tr::lng_gift_link_label_date(),
|
table,
|
||||||
rpl::single(langDateTime(base::unixtime::parse(current.date))));
|
tr::lng_gift_link_label_date(),
|
||||||
|
rpl::single(langDateTime(base::unixtime::parse(current.date))));
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -584,3 +583,18 @@ void GiftCodeBox(
|
||||||
button->resizeToWidth(buttonWidth);
|
button->resizeToWidth(buttonWidth);
|
||||||
}, button->lifetime());
|
}, button->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResolveGiftCode(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
const QString &slug) {
|
||||||
|
const auto done = [=](Api::GiftCode code) {
|
||||||
|
if (!code) {
|
||||||
|
controller->showToast(tr::lng_gift_link_expired(tr::now));
|
||||||
|
} else {
|
||||||
|
controller->show(Box(GiftCodeBox, controller, slug));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
controller->session().api().premium().checkGiftCode(
|
||||||
|
slug,
|
||||||
|
crl::guard(controller, done));
|
||||||
|
}
|
||||||
|
|
|
@ -42,3 +42,6 @@ void GiftCodeBox(
|
||||||
not_null<Ui::GenericBox*> box,
|
not_null<Ui::GenericBox*> box,
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
const QString &slug);
|
const QString &slug);
|
||||||
|
void ResolveGiftCode(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
const QString &slug);
|
||||||
|
|
|
@ -351,17 +351,7 @@ bool ResolveUsernameOrPhone(
|
||||||
const auto appnameParam = params.value(u"appname"_q);
|
const auto appnameParam = params.value(u"appname"_q);
|
||||||
|
|
||||||
if (domainParam == u"giftcode"_q && !appnameParam.isEmpty()) {
|
if (domainParam == u"giftcode"_q && !appnameParam.isEmpty()) {
|
||||||
const auto done = [=](Api::GiftCode code) {
|
ResolveGiftCode(controller, appnameParam);
|
||||||
if (!code) {
|
|
||||||
controller->showToast(u"Gift code link expired"_q);
|
|
||||||
} else {
|
|
||||||
controller->show(
|
|
||||||
Box(GiftCodeBox, controller, appnameParam));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
controller->session().api().premium().checkGiftCode(
|
|
||||||
appnameParam,
|
|
||||||
crl::guard(controller, done));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1908,21 +1908,28 @@ MediaGiftBox::MediaGiftBox(
|
||||||
not_null<HistoryItem*> parent,
|
not_null<HistoryItem*> parent,
|
||||||
not_null<PeerData*> from,
|
not_null<PeerData*> from,
|
||||||
int months)
|
int months)
|
||||||
|
: MediaGiftBox(parent, from, GiftCode{ .months = months }) {
|
||||||
|
}
|
||||||
|
|
||||||
|
MediaGiftBox::MediaGiftBox(
|
||||||
|
not_null<HistoryItem*> parent,
|
||||||
|
not_null<PeerData*> from,
|
||||||
|
GiftCode data)
|
||||||
: Media(parent)
|
: Media(parent)
|
||||||
, _from(from)
|
, _from(from)
|
||||||
, _months(months) {
|
, _data(std::move(data)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Media> MediaGiftBox::clone(not_null<HistoryItem*> parent) {
|
std::unique_ptr<Media> MediaGiftBox::clone(not_null<HistoryItem*> parent) {
|
||||||
return std::make_unique<MediaGiftBox>(parent, _from, _months);
|
return std::make_unique<MediaGiftBox>(parent, _from, _data);
|
||||||
}
|
}
|
||||||
|
|
||||||
not_null<PeerData*> MediaGiftBox::from() const {
|
not_null<PeerData*> MediaGiftBox::from() const {
|
||||||
return _from;
|
return _from;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MediaGiftBox::months() const {
|
const GiftCode &MediaGiftBox::data() const {
|
||||||
return _months;
|
return _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextWithEntities MediaGiftBox::notificationText() const {
|
TextWithEntities MediaGiftBox::notificationText() const {
|
||||||
|
@ -1954,14 +1961,6 @@ std::unique_ptr<HistoryView::Media> MediaGiftBox::createView(
|
||||||
std::make_unique<HistoryView::PremiumGift>(message, this));
|
std::make_unique<HistoryView::PremiumGift>(message, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MediaGiftBox::activated() const {
|
|
||||||
return _activated;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MediaGiftBox::setActivated(bool activated) {
|
|
||||||
_activated = activated;
|
|
||||||
}
|
|
||||||
|
|
||||||
MediaWallPaper::MediaWallPaper(
|
MediaWallPaper::MediaWallPaper(
|
||||||
not_null<HistoryItem*> parent,
|
not_null<HistoryItem*> parent,
|
||||||
const WallPaper &paper)
|
const WallPaper &paper)
|
||||||
|
|
|
@ -98,6 +98,13 @@ struct Giveaway {
|
||||||
bool all = false;
|
bool all = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct GiftCode {
|
||||||
|
QString slug;
|
||||||
|
ChannelData *channel = nullptr;
|
||||||
|
int months = 0;
|
||||||
|
bool viaGiveaway = false;
|
||||||
|
};
|
||||||
|
|
||||||
class Media {
|
class Media {
|
||||||
public:
|
public:
|
||||||
Media(not_null<HistoryItem*> parent);
|
Media(not_null<HistoryItem*> parent);
|
||||||
|
@ -526,14 +533,15 @@ public:
|
||||||
not_null<HistoryItem*> parent,
|
not_null<HistoryItem*> parent,
|
||||||
not_null<PeerData*> from,
|
not_null<PeerData*> from,
|
||||||
int months);
|
int months);
|
||||||
|
MediaGiftBox(
|
||||||
|
not_null<HistoryItem*> parent,
|
||||||
|
not_null<PeerData*> from,
|
||||||
|
GiftCode data);
|
||||||
|
|
||||||
std::unique_ptr<Media> clone(not_null<HistoryItem*> parent) override;
|
std::unique_ptr<Media> clone(not_null<HistoryItem*> parent) override;
|
||||||
|
|
||||||
[[nodiscard]] not_null<PeerData*> from() const;
|
[[nodiscard]] not_null<PeerData*> from() const;
|
||||||
[[nodiscard]] int months() const;
|
[[nodiscard]] const GiftCode &data() const;
|
||||||
|
|
||||||
[[nodiscard]] bool activated() const;
|
|
||||||
void setActivated(bool activated);
|
|
||||||
|
|
||||||
TextWithEntities notificationText() const override;
|
TextWithEntities notificationText() const override;
|
||||||
QString pinnedTextSubstring() const override;
|
QString pinnedTextSubstring() const override;
|
||||||
|
@ -548,8 +556,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
not_null<PeerData*> _from;
|
not_null<PeerData*> _from;
|
||||||
int _months = 0;
|
GiftCode _data;
|
||||||
bool _activated = false;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4612,6 +4612,21 @@ void HistoryItem::applyAction(const MTPMessageAction &action) {
|
||||||
if (const auto paper = Data::WallPaper::Create(session, attached)) {
|
if (const auto paper = Data::WallPaper::Create(session, attached)) {
|
||||||
_media = std::make_unique<Data::MediaWallPaper>(this, *paper);
|
_media = std::make_unique<Data::MediaWallPaper>(this, *paper);
|
||||||
}
|
}
|
||||||
|
}, [&](const MTPDmessageActionGiftCode &data) {
|
||||||
|
const auto boostedId = data.vboost_peer()
|
||||||
|
? peerToChannel(peerFromMTP(*data.vboost_peer()))
|
||||||
|
: ChannelId();
|
||||||
|
_media = std::make_unique<Data::MediaGiftBox>(
|
||||||
|
this,
|
||||||
|
_from,
|
||||||
|
Data::GiftCode{
|
||||||
|
.slug = qs(data.vslug()),
|
||||||
|
.channel = (peerIsChannel(boostedId)
|
||||||
|
? history()->owner().channel(boostedId).get()
|
||||||
|
: nullptr),
|
||||||
|
.months = data.vmonths().v,
|
||||||
|
.viaGiveaway = data.is_via_giveaway(),
|
||||||
|
});
|
||||||
}, [](const auto &) {
|
}, [](const auto &) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "history/view/media/history_view_premium_gift.h"
|
#include "history/view/media/history_view_premium_gift.h"
|
||||||
|
|
||||||
|
#include "boxes/gift_premium_box.h" // ResolveGiftCode
|
||||||
#include "chat_helpers/stickers_gift_box_pack.h"
|
#include "chat_helpers/stickers_gift_box_pack.h"
|
||||||
#include "core/click_handler_types.h" // ClickHandlerContext
|
#include "core/click_handler_types.h" // ClickHandlerContext
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
|
#include "data/data_channel.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "history/view/history_view_element.h"
|
#include "history/view/history_view_element.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "settings/settings_premium.h" // Settings::ShowGiftPremium
|
#include "settings/settings_premium.h" // Settings::ShowGiftPremium
|
||||||
|
#include "ui/text/text_utilities.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
|
|
||||||
|
@ -37,7 +40,8 @@ PremiumGift::PremiumGift(
|
||||||
not_null<Element*> parent,
|
not_null<Element*> parent,
|
||||||
not_null<Data::MediaGiftBox*> gift)
|
not_null<Data::MediaGiftBox*> gift)
|
||||||
: _parent(parent)
|
: _parent(parent)
|
||||||
, _gift(gift) {
|
, _gift(gift)
|
||||||
|
, _data(gift->data()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PremiumGift::~PremiumGift() = default;
|
PremiumGift::~PremiumGift() = default;
|
||||||
|
@ -51,27 +55,59 @@ QSize PremiumGift::size() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PremiumGift::title() {
|
QString PremiumGift::title() {
|
||||||
return tr::lng_premium_summary_title(tr::now);
|
return _data.slug.isEmpty()
|
||||||
|
? tr::lng_premium_summary_title(tr::now)
|
||||||
|
: tr::lng_prize_title(tr::now);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextWithEntities PremiumGift::subtitle() {
|
TextWithEntities PremiumGift::subtitle() {
|
||||||
return { FormatGiftMonths(_gift->months()) };
|
if (_data.slug.isEmpty()) {
|
||||||
|
return { FormatGiftMonths(_data.months) };
|
||||||
|
}
|
||||||
|
const auto duration = (_data.months < 12)
|
||||||
|
? tr::lng_months(tr::now, lt_count, _data.months)
|
||||||
|
: tr::lng_years(tr::now, lt_count, _data.months / 12);
|
||||||
|
const auto name = _data.channel ? _data.channel->name() : "channel";
|
||||||
|
auto result = (_data.viaGiveaway
|
||||||
|
? tr::lng_prize_about
|
||||||
|
: tr::lng_prize_gift_about)(
|
||||||
|
tr::now,
|
||||||
|
lt_channel,
|
||||||
|
Ui::Text::Bold(name),
|
||||||
|
Ui::Text::RichLangValue);
|
||||||
|
result.append("\n\n");
|
||||||
|
result.append((_data.viaGiveaway
|
||||||
|
? tr::lng_prize_duration
|
||||||
|
: tr::lng_prize_gift_duration)(
|
||||||
|
tr::now,
|
||||||
|
lt_duration,
|
||||||
|
Ui::Text::Bold(duration),
|
||||||
|
Ui::Text::RichLangValue));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PremiumGift::button() {
|
QString PremiumGift::button() {
|
||||||
return tr::lng_sticker_premium_view(tr::now);
|
return _data.slug.isEmpty()
|
||||||
|
? tr::lng_sticker_premium_view(tr::now)
|
||||||
|
: tr::lng_prize_open(tr::now);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClickHandlerPtr PremiumGift::createViewLink() {
|
ClickHandlerPtr PremiumGift::createViewLink() {
|
||||||
const auto from = _gift->from();
|
const auto from = _gift->from();
|
||||||
const auto to = _parent->history()->peer;
|
const auto to = _parent->history()->peer;
|
||||||
const auto months = _gift->months();
|
const auto data = _gift->data();
|
||||||
return std::make_shared<LambdaClickHandler>([=](ClickContext context) {
|
return std::make_shared<LambdaClickHandler>([=](ClickContext context) {
|
||||||
const auto my = context.other.value<ClickHandlerContext>();
|
const auto my = context.other.value<ClickHandlerContext>();
|
||||||
if (const auto controller = my.sessionWindow.get()) {
|
if (const auto controller = my.sessionWindow.get()) {
|
||||||
const auto me = (from->id == controller->session().userPeerId());
|
if (data.slug.isEmpty()) {
|
||||||
const auto peer = me ? to : from;
|
const auto selfId = controller->session().userPeerId();
|
||||||
Settings::ShowGiftPremium(controller, peer, months, me);
|
const auto self = (from->id == selfId);
|
||||||
|
const auto peer = self ? to : from;
|
||||||
|
const auto months = data.months;
|
||||||
|
Settings::ShowGiftPremium(controller, peer, months, self);
|
||||||
|
} else {
|
||||||
|
ResolveGiftCode(controller, data.slug);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -91,6 +127,10 @@ void PremiumGift::draw(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PremiumGift::hideServiceText() {
|
||||||
|
return !_data.slug.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
void PremiumGift::stickerClearLoopPlayed() {
|
void PremiumGift::stickerClearLoopPlayed() {
|
||||||
if (_sticker) {
|
if (_sticker) {
|
||||||
_sticker->stickerClearLoopPlayed();
|
_sticker->stickerClearLoopPlayed();
|
||||||
|
@ -120,8 +160,9 @@ void PremiumGift::ensureStickerCreated() const {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto &session = _parent->history()->session();
|
const auto &session = _parent->history()->session();
|
||||||
|
const auto months = _gift->data().months;
|
||||||
auto &packs = session.giftBoxStickersPacks();
|
auto &packs = session.giftBoxStickersPacks();
|
||||||
if (const auto document = packs.lookup(_gift->months())) {
|
if (const auto document = packs.lookup(months)) {
|
||||||
if (const auto sticker = document->sticker()) {
|
if (const auto sticker = document->sticker()) {
|
||||||
const auto skipPremiumEffect = false;
|
const auto skipPremiumEffect = false;
|
||||||
_sticker.emplace(_parent, document, skipPremiumEffect, _parent);
|
_sticker.emplace(_parent, document, skipPremiumEffect, _parent);
|
||||||
|
|
|
@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
class MediaGiftBox;
|
class MediaGiftBox;
|
||||||
|
struct GiftCode;
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
||||||
namespace HistoryView {
|
namespace HistoryView {
|
||||||
|
@ -35,10 +36,7 @@ public:
|
||||||
const QRect &geometry) override;
|
const QRect &geometry) override;
|
||||||
ClickHandlerPtr createViewLink() override;
|
ClickHandlerPtr createViewLink() override;
|
||||||
|
|
||||||
bool hideServiceText() override {
|
bool hideServiceText() override;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void stickerClearLoopPlayed() override;
|
void stickerClearLoopPlayed() override;
|
||||||
std::unique_ptr<StickerPlayer> stickerTakePlayer(
|
std::unique_ptr<StickerPlayer> stickerTakePlayer(
|
||||||
not_null<DocumentData*> data,
|
not_null<DocumentData*> data,
|
||||||
|
@ -52,6 +50,7 @@ private:
|
||||||
|
|
||||||
const not_null<Element*> _parent;
|
const not_null<Element*> _parent;
|
||||||
const not_null<Data::MediaGiftBox*> _gift;
|
const not_null<Data::MediaGiftBox*> _gift;
|
||||||
|
const Data::GiftCode &_data;
|
||||||
mutable std::optional<Sticker> _sticker;
|
mutable std::optional<Sticker> _sticker;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -851,7 +851,7 @@ searchInChatPeerList: PeerList(defaultPeerList) {
|
||||||
item: searchInChatPeerListItem;
|
item: searchInChatPeerListItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
msgServiceGiftBoxSize: size(206px, 231px); // Plus msgServiceGiftBoxTopSkip.
|
msgServiceGiftBoxSize: size(236px, 231px); // Plus msgServiceGiftBoxTopSkip.
|
||||||
msgServiceGiftBoxRadius: 20px;
|
msgServiceGiftBoxRadius: 20px;
|
||||||
msgServiceGiftBoxTopSkip: 4px;
|
msgServiceGiftBoxTopSkip: 4px;
|
||||||
msgServiceGiftBoxButtonHeight: 32px;
|
msgServiceGiftBoxButtonHeight: 32px;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user