mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Fixed display of gift service actions for gift senders.
This commit is contained in:
parent
e64190fb64
commit
3602155f68
7 changed files with 111 additions and 20 deletions
|
@ -1469,6 +1469,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_action_proximity_distance_km#other" = "{count} km";
|
||||
"lng_action_webview_data_done" = "You have just successfully transferred data from the «{text}» button to the bot.";
|
||||
"lng_action_gift_received" = "{user} sent you a gift for {cost}";
|
||||
"lng_action_gift_received_me" = "You sent to {user} a gift for {cost}";
|
||||
|
||||
"lng_premium_gift_duration_months#one" = "for {count} month";
|
||||
"lng_premium_gift_duration_months#other" = "for {count} months";
|
||||
|
@ -1700,6 +1701,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_premium_summary_title" = "Telegram Premium";
|
||||
"lng_premium_summary_top_about" = "Go **beyond the limits**, get **exclusive features** and support us by subscribing to **Telegram Premium**.";
|
||||
"lng_premium_summary_title_subscribed" = "You are all set!";
|
||||
"lng_premium_summary_subtitle_gift#one" = "{user} has gifted you a {count}-month subscription for Telegram Premium.";
|
||||
"lng_premium_summary_subtitle_gift#other" = "{user} has gifted you a {count}-months subscription for Telegram Premium.";
|
||||
"lng_premium_summary_subtitle_gift_me#one" = "You gifted {user} a {count}-month subscription for Telegram Premium.";
|
||||
"lng_premium_summary_subtitle_gift_me#other" = "You gifted {user} a {count}-months subscription for Telegram Premium.";
|
||||
"lng_premium_summary_subtitle_double_limits" = "Doubled Limits";
|
||||
"lng_premium_summary_about_double_limits" = "Up to 1000 channels, 20 folders, 10 pins, 20 public links, 4 accounts and more.";
|
||||
"lng_premium_summary_subtitle_more_upload" = "4Gb Upload Size";
|
||||
|
|
|
@ -1734,13 +1734,21 @@ ClickHandlerPtr MediaDice::MakeHandler(
|
|||
});
|
||||
}
|
||||
|
||||
MediaGiftBox::MediaGiftBox(not_null<HistoryItem*> parent, int months)
|
||||
MediaGiftBox::MediaGiftBox(
|
||||
not_null<HistoryItem*> parent,
|
||||
not_null<PeerData*> from,
|
||||
int months)
|
||||
: Media(parent)
|
||||
, _from(from)
|
||||
, _months(months) {
|
||||
}
|
||||
|
||||
std::unique_ptr<Media> MediaGiftBox::clone(not_null<HistoryItem*> parent) {
|
||||
return std::make_unique<MediaGiftBox>(parent, _months);
|
||||
return std::make_unique<MediaGiftBox>(parent, _from, _months);
|
||||
}
|
||||
|
||||
not_null<PeerData*> MediaGiftBox::from() const {
|
||||
return _from;
|
||||
}
|
||||
|
||||
int MediaGiftBox::months() const {
|
||||
|
|
|
@ -477,10 +477,14 @@ private:
|
|||
|
||||
class MediaGiftBox final : public Media {
|
||||
public:
|
||||
MediaGiftBox(not_null<HistoryItem*> parent, int months);
|
||||
MediaGiftBox(
|
||||
not_null<HistoryItem*> parent,
|
||||
not_null<PeerData*> from,
|
||||
int months);
|
||||
|
||||
std::unique_ptr<Media> clone(not_null<HistoryItem*> parent) override;
|
||||
|
||||
[[nodiscard]] not_null<PeerData*> from() const;
|
||||
[[nodiscard]] int months() const;
|
||||
|
||||
[[nodiscard]] bool activated() const;
|
||||
|
@ -500,6 +504,7 @@ public:
|
|||
HistoryView::Element *replacing = nullptr) override;
|
||||
|
||||
private:
|
||||
not_null<PeerData*> _from;
|
||||
int _months = 0;
|
||||
bool _activated = false;
|
||||
|
||||
|
|
|
@ -617,18 +617,22 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
|
|||
|
||||
auto prepareGiftPremium = [&](
|
||||
const MTPDmessageActionGiftPremium &action) {
|
||||
auto result = PreparedText{};
|
||||
const auto isSelf = (_from->id == _from->session().userPeerId());
|
||||
const auto peer = isSelf ? history()->peer : _from;
|
||||
history()->session().giftBoxStickersPacks().load();
|
||||
const auto amount = action.vamount().v;
|
||||
const auto currency = qs(action.vcurrency());
|
||||
auto result = PreparedText{};
|
||||
result.links.push_back(fromLink());
|
||||
result.text = tr::lng_action_gift_received(
|
||||
tr::now,
|
||||
lt_user,
|
||||
fromLinkText(), // Link 1.
|
||||
lt_cost,
|
||||
{ Ui::FillAmountAndCurrency(amount, currency) },
|
||||
Ui::Text::WithEntities);
|
||||
result.links.push_back(peer->createOpenLink());
|
||||
result.text = (isSelf
|
||||
? tr::lng_action_gift_received_me
|
||||
: tr::lng_action_gift_received)(
|
||||
tr::now,
|
||||
lt_user,
|
||||
Ui::Text::Link(peer->name, 1), // Link 1.
|
||||
lt_cost,
|
||||
{ Ui::FillAmountAndCurrency(amount, currency) },
|
||||
Ui::Text::WithEntities);
|
||||
return result;
|
||||
};
|
||||
|
||||
|
@ -760,7 +764,10 @@ void HistoryService::applyAction(const MTPMessageAction &action) {
|
|||
}
|
||||
}
|
||||
}, [&](const MTPDmessageActionGiftPremium &data) {
|
||||
_media = std::make_unique<Data::MediaGiftBox>(this, data.vmonths().v);
|
||||
_media = std::make_unique<Data::MediaGiftBox>(
|
||||
this,
|
||||
_from,
|
||||
data.vmonths().v);
|
||||
}, [](const auto &) {
|
||||
});
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "lottie/lottie_common.h"
|
||||
#include "lottie/lottie_single_player.h"
|
||||
#include "main/main_session.h"
|
||||
#include "settings/settings_premium.h" // Settings::ShowPremium
|
||||
#include "settings/settings_premium.h" // Settings::ShowGiftPremium
|
||||
#include "ui/chat/chat_style.h"
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
#include "window/window_session_controller.h"
|
||||
|
@ -66,11 +66,15 @@ MediaGift::MediaGift(
|
|||
+ margins.right(),
|
||||
height);
|
||||
|
||||
const auto from = _gift->from();
|
||||
const auto to = _parent->data()->history()->peer;
|
||||
const auto months = _gift->months();
|
||||
result.link = std::make_shared<LambdaClickHandler>([=](
|
||||
ClickContext context) {
|
||||
const auto my = context.other.value<ClickHandlerContext>();
|
||||
if (const auto controller = my.sessionWindow.get()) {
|
||||
Settings::ShowPremium(controller, QString());
|
||||
const auto me = (from->id == controller->session().userPeerId());
|
||||
Settings::ShowGiftPremium(controller, me ? to : from, months, me);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "data/data_session.h"
|
||||
#include "main/main_session.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_app_config.h"
|
||||
|
@ -55,6 +56,32 @@ constexpr auto kTitleAnimationPart = 0.15;
|
|||
|
||||
constexpr auto kTitleAdditionalScale = 0.15;
|
||||
|
||||
struct GiftRef {
|
||||
PeerId peerId;
|
||||
int months;
|
||||
bool me;
|
||||
};
|
||||
|
||||
[[nodiscard]] QString SerializeRef(const GiftRef &gift) {
|
||||
return QString::number(gift.peerId.value)
|
||||
+ ':'
|
||||
+ QString::number(gift.months)
|
||||
+ ':'
|
||||
+ QString::number(gift.me ? 1 : 0);
|
||||
}
|
||||
|
||||
[[nodiscard]] GiftRef ParseGiftRef(QStringView data) {
|
||||
const auto components = data.split(':');
|
||||
if (components.size() != 3) {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
.peerId = PeerId(components[0].toULongLong()),
|
||||
.months = components[1].toInt(),
|
||||
.me = (components[2].toInt() == 1),
|
||||
};
|
||||
}
|
||||
|
||||
struct Entry {
|
||||
const style::icon *icon;
|
||||
rpl::producer<QString> title;
|
||||
|
@ -734,10 +761,26 @@ QPointer<Ui::RpWidget> Premium::createPinnedToTop(
|
|||
Data::AmPremiumValue(&_controller->session()),
|
||||
tr::lng_premium_summary_title_subscribed(),
|
||||
tr::lng_premium_summary_title());
|
||||
auto about = rpl::conditional(
|
||||
Data::AmPremiumValue(&_controller->session()),
|
||||
_controller->session().api().premium().statusTextValue(),
|
||||
tr::lng_premium_summary_top_about(Ui::Text::RichLangValue));
|
||||
auto about = [&] {
|
||||
const auto gift = ParseGiftRef(_ref);
|
||||
if (gift.peerId) {
|
||||
auto &data = _controller->session().data();
|
||||
if (const auto peer = data.peer(gift.peerId)) {
|
||||
return (gift.me
|
||||
? tr::lng_premium_summary_subtitle_gift_me
|
||||
: tr::lng_premium_summary_subtitle_gift)(
|
||||
lt_count,
|
||||
rpl::single(float64(gift.months)),
|
||||
lt_user,
|
||||
rpl::single(Ui::Text::Bold(peer->name)),
|
||||
Ui::Text::RichLangValue);
|
||||
}
|
||||
}
|
||||
return rpl::conditional(
|
||||
Data::AmPremiumValue(&_controller->session()),
|
||||
_controller->session().api().premium().statusTextValue(),
|
||||
tr::lng_premium_summary_top_about(Ui::Text::RichLangValue));
|
||||
}();
|
||||
|
||||
const auto content = Ui::CreateChild<TopBar>(
|
||||
parent.get(),
|
||||
|
@ -746,7 +789,9 @@ QPointer<Ui::RpWidget> Premium::createPinnedToTop(
|
|||
std::move(about));
|
||||
_setPaused = [=](bool paused) {
|
||||
content->setPaused(paused);
|
||||
_subscribe->setGlarePaused(paused);
|
||||
if (_subscribe) {
|
||||
_subscribe->setGlarePaused(paused);
|
||||
}
|
||||
};
|
||||
|
||||
_wrap.value(
|
||||
|
@ -811,6 +856,10 @@ QPointer<Ui::RpWidget> Premium::createPinnedToBottom(
|
|||
not_null<Ui::RpWidget*> parent) {
|
||||
const auto content = Ui::CreateChild<Ui::RpWidget>(parent.get());
|
||||
|
||||
if (ParseGiftRef(_ref).peerId) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
_subscribe = CreateSubscribeButton({
|
||||
_controller,
|
||||
content,
|
||||
|
@ -884,6 +933,14 @@ void ShowPremium(
|
|||
controller->showSettings(Settings::PremiumId());
|
||||
}
|
||||
|
||||
void ShowGiftPremium(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<PeerData*> peer,
|
||||
int months,
|
||||
bool me) {
|
||||
ShowPremium(controller, SerializeRef({ peer->id, months, me }));
|
||||
}
|
||||
|
||||
void StartPremiumPayment(
|
||||
not_null<Window::SessionController*> controller,
|
||||
const QString &ref) {
|
||||
|
|
|
@ -32,6 +32,11 @@ void ShowPremium(not_null<::Main::Session*> session, const QString &ref);
|
|||
void ShowPremium(
|
||||
not_null<Window::SessionController*> controller,
|
||||
const QString &ref);
|
||||
void ShowGiftPremium(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<PeerData*> peer,
|
||||
int months,
|
||||
bool me);
|
||||
|
||||
void StartPremiumPayment(
|
||||
not_null<Window::SessionController*> controller,
|
||||
|
|
Loading…
Add table
Reference in a new issue