mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-01 12:00:48 +00:00
Reformated serializing and parsing of ref data for Premium Settings.
This commit is contained in:
parent
668a3308be
commit
90ef0e4969
@ -12,8 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "base/timer.h"
|
||||
#include "base/weak_ptr.h"
|
||||
|
||||
struct StickerSetIdentifier;
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
@ -140,7 +140,7 @@ void BadgeView::setBadge(Badge badge, DocumentId emojiStatusId) {
|
||||
: SizeTag::Normal;
|
||||
_emojiStatus = _peer->owner().customEmojiManager().create(
|
||||
_emojiStatusId,
|
||||
[raw = _view.data()]{ raw->update(); },
|
||||
[raw = _view.data()] { raw->update(); },
|
||||
tag);
|
||||
const auto emoji = Data::FrameSizeFromTag(tag)
|
||||
/ style::DevicePixelRatio();
|
||||
@ -347,9 +347,7 @@ Cover::Cover(
|
||||
if (_peer->isSelf()) {
|
||||
_emojiStatusPanel.show(_controller, _badge.widget());
|
||||
} else {
|
||||
::Settings::ShowPremium(
|
||||
_controller,
|
||||
u"profile__%1"_q.arg(peerToUser(_peer->id).bare));
|
||||
::Settings::ShowEmojiStatusPremium(_controller, _peer);
|
||||
}
|
||||
});
|
||||
_badge.updated() | rpl::start_with_next([=] {
|
||||
|
@ -54,13 +54,20 @@ using SectionCustomTopBarData = Info::Settings::SectionCustomTopBarData;
|
||||
constexpr auto kBodyAnimationPart = 0.90;
|
||||
constexpr auto kTitleAdditionalScale = 0.15;
|
||||
|
||||
struct GiftRef {
|
||||
namespace Ref {
|
||||
namespace Gift {
|
||||
|
||||
struct Data {
|
||||
PeerId peerId;
|
||||
int months;
|
||||
bool me;
|
||||
|
||||
explicit operator bool() const {
|
||||
return peerId != 0;
|
||||
}
|
||||
};
|
||||
|
||||
[[nodiscard]] QString SerializeRef(const GiftRef &gift) {
|
||||
[[nodiscard]] QString Serialize(const Data &gift) {
|
||||
return QString::number(gift.peerId.value)
|
||||
+ ':'
|
||||
+ QString::number(gift.months)
|
||||
@ -68,7 +75,7 @@ struct GiftRef {
|
||||
+ QString::number(gift.me ? 1 : 0);
|
||||
}
|
||||
|
||||
[[nodiscard]] GiftRef ParseGiftRef(QStringView data) {
|
||||
[[nodiscard]] Data Parse(QStringView data) {
|
||||
const auto components = data.split(':');
|
||||
if (components.size() != 3) {
|
||||
return {};
|
||||
@ -80,6 +87,38 @@ struct GiftRef {
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace Gift
|
||||
|
||||
namespace EmojiStatus {
|
||||
|
||||
struct Data {
|
||||
PeerId peerId;
|
||||
|
||||
explicit operator bool() const {
|
||||
return peerId != 0;
|
||||
}
|
||||
};
|
||||
|
||||
[[nodiscard]] QString Serialize(const Data &gift) {
|
||||
return QString("profile_:%1").arg(QString::number(gift.peerId.value));
|
||||
}
|
||||
|
||||
[[nodiscard]] Data Parse(QStringView data) {
|
||||
if (data.startsWith(u"profile_:"_q)) {
|
||||
const auto components = data.split(':');
|
||||
if (components.size() != 2) {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
.peerId = PeerId(components[1].toULongLong()),
|
||||
};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace EmojiStatus
|
||||
} // namespace Ref
|
||||
|
||||
struct Entry {
|
||||
const style::icon *icon;
|
||||
rpl::producer<QString> title;
|
||||
@ -760,8 +799,8 @@ QPointer<Ui::RpWidget> Premium::createPinnedToTop(
|
||||
tr::lng_premium_summary_title_subscribed(),
|
||||
tr::lng_premium_summary_title());
|
||||
auto about = [&]() -> rpl::producer<TextWithEntities> {
|
||||
const auto gift = ParseGiftRef(_ref);
|
||||
if (gift.peerId) {
|
||||
const auto gift = Ref::Gift::Parse(_ref);
|
||||
if (gift) {
|
||||
auto &data = _controller->session().data();
|
||||
if (const auto peer = data.peer(gift.peerId)) {
|
||||
return (gift.me
|
||||
@ -856,7 +895,7 @@ QPointer<Ui::RpWidget> Premium::createPinnedToBottom(
|
||||
not_null<Ui::RpWidget*> parent) {
|
||||
const auto content = Ui::CreateChild<Ui::RpWidget>(parent.get());
|
||||
|
||||
if (ParseGiftRef(_ref).peerId) {
|
||||
if (Ref::Gift::Parse(_ref)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -938,7 +977,13 @@ void ShowGiftPremium(
|
||||
not_null<PeerData*> peer,
|
||||
int months,
|
||||
bool me) {
|
||||
ShowPremium(controller, SerializeRef({ peer->id, months, me }));
|
||||
ShowPremium(controller, Ref::Gift::Serialize({ peer->id, months, me }));
|
||||
}
|
||||
|
||||
void ShowEmojiStatusPremium(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<PeerData*> peer) {
|
||||
ShowPremium(controller, Ref::EmojiStatus::Serialize({ peer->id }));
|
||||
}
|
||||
|
||||
void StartPremiumPayment(
|
||||
|
@ -37,6 +37,9 @@ void ShowGiftPremium(
|
||||
not_null<PeerData*> peer,
|
||||
int months,
|
||||
bool me);
|
||||
void ShowEmojiStatusPremium(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<PeerData*> peer);
|
||||
|
||||
void StartPremiumPayment(
|
||||
not_null<Window::SessionController*> controller,
|
||||
|
Loading…
Reference in New Issue
Block a user