mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Reformated serializing and parsing of ref data for Premium Settings.
This commit is contained in:
parent
668a3308be
commit
90ef0e4969
4 changed files with 57 additions and 13 deletions
|
@ -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
|
||||||
|
|
|
@ -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([=] {
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Add table
Reference in a new issue