Reformated serializing and parsing of ref data for Premium Settings.

This commit is contained in:
23rd 2022-08-20 13:18:31 +03:00 committed by John Preston
parent 668a3308be
commit 90ef0e4969
4 changed files with 57 additions and 13 deletions

View file

@ -12,8 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/timer.h" #include "base/timer.h"
#include "base/weak_ptr.h" #include "base/weak_ptr.h"
struct StickerSetIdentifier;
namespace Main { namespace Main {
class Session; class Session;
} // namespace Main } // namespace Main

View file

@ -140,7 +140,7 @@ void BadgeView::setBadge(Badge badge, DocumentId emojiStatusId) {
: SizeTag::Normal; : SizeTag::Normal;
_emojiStatus = _peer->owner().customEmojiManager().create( _emojiStatus = _peer->owner().customEmojiManager().create(
_emojiStatusId, _emojiStatusId,
[raw = _view.data()]{ raw->update(); }, [raw = _view.data()] { raw->update(); },
tag); tag);
const auto emoji = Data::FrameSizeFromTag(tag) const auto emoji = Data::FrameSizeFromTag(tag)
/ style::DevicePixelRatio(); / style::DevicePixelRatio();
@ -347,9 +347,7 @@ Cover::Cover(
if (_peer->isSelf()) { if (_peer->isSelf()) {
_emojiStatusPanel.show(_controller, _badge.widget()); _emojiStatusPanel.show(_controller, _badge.widget());
} else { } else {
::Settings::ShowPremium( ::Settings::ShowEmojiStatusPremium(_controller, _peer);
_controller,
u"profile__%1"_q.arg(peerToUser(_peer->id).bare));
} }
}); });
_badge.updated() | rpl::start_with_next([=] { _badge.updated() | rpl::start_with_next([=] {

View file

@ -54,13 +54,20 @@ using SectionCustomTopBarData = Info::Settings::SectionCustomTopBarData;
constexpr auto kBodyAnimationPart = 0.90; constexpr auto kBodyAnimationPart = 0.90;
constexpr auto kTitleAdditionalScale = 0.15; constexpr auto kTitleAdditionalScale = 0.15;
struct GiftRef { namespace Ref {
namespace Gift {
struct Data {
PeerId peerId; PeerId peerId;
int months; int months;
bool me; 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) return QString::number(gift.peerId.value)
+ ':' + ':'
+ QString::number(gift.months) + QString::number(gift.months)
@ -68,7 +75,7 @@ struct GiftRef {
+ QString::number(gift.me ? 1 : 0); + QString::number(gift.me ? 1 : 0);
} }
[[nodiscard]] GiftRef ParseGiftRef(QStringView data) { [[nodiscard]] Data Parse(QStringView data) {
const auto components = data.split(':'); const auto components = data.split(':');
if (components.size() != 3) { if (components.size() != 3) {
return {}; 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 { struct Entry {
const style::icon *icon; const style::icon *icon;
rpl::producer<QString> title; rpl::producer<QString> title;
@ -760,8 +799,8 @@ QPointer<Ui::RpWidget> Premium::createPinnedToTop(
tr::lng_premium_summary_title_subscribed(), tr::lng_premium_summary_title_subscribed(),
tr::lng_premium_summary_title()); tr::lng_premium_summary_title());
auto about = [&]() -> rpl::producer<TextWithEntities> { auto about = [&]() -> rpl::producer<TextWithEntities> {
const auto gift = ParseGiftRef(_ref); const auto gift = Ref::Gift::Parse(_ref);
if (gift.peerId) { if (gift) {
auto &data = _controller->session().data(); auto &data = _controller->session().data();
if (const auto peer = data.peer(gift.peerId)) { if (const auto peer = data.peer(gift.peerId)) {
return (gift.me return (gift.me
@ -856,7 +895,7 @@ QPointer<Ui::RpWidget> Premium::createPinnedToBottom(
not_null<Ui::RpWidget*> parent) { not_null<Ui::RpWidget*> parent) {
const auto content = Ui::CreateChild<Ui::RpWidget>(parent.get()); const auto content = Ui::CreateChild<Ui::RpWidget>(parent.get());
if (ParseGiftRef(_ref).peerId) { if (Ref::Gift::Parse(_ref)) {
return nullptr; return nullptr;
} }
@ -938,7 +977,13 @@ void ShowGiftPremium(
not_null<PeerData*> peer, not_null<PeerData*> peer,
int months, int months,
bool me) { 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( void StartPremiumPayment(

View file

@ -37,6 +37,9 @@ void ShowGiftPremium(
not_null<PeerData*> peer, not_null<PeerData*> peer,
int months, int months,
bool me); bool me);
void ShowEmojiStatusPremium(
not_null<Window::SessionController*> controller,
not_null<PeerData*> peer);
void StartPremiumPayment( void StartPremiumPayment(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,