mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added subscription price info to list of invite links.
This commit is contained in:
parent
d6541d777f
commit
81a79e2895
1 changed files with 37 additions and 3 deletions
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/session/session_show.h"
|
#include "main/session/session_show.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "api/api_invite_links.h"
|
#include "api/api_invite_links.h"
|
||||||
|
#include "settings/settings_credits_graphics.h"
|
||||||
#include "ui/wrap/slide_wrap.h"
|
#include "ui/wrap/slide_wrap.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/widgets/popup_menu.h"
|
#include "ui/widgets/popup_menu.h"
|
||||||
|
@ -64,8 +65,12 @@ struct InviteLinkAction {
|
||||||
|
|
||||||
class Row;
|
class Row;
|
||||||
|
|
||||||
|
using SubscriptionRightLabel = Settings::SubscriptionRightLabel;
|
||||||
|
|
||||||
class RowDelegate {
|
class RowDelegate {
|
||||||
public:
|
public:
|
||||||
|
virtual std::optional<SubscriptionRightLabel> rightLabel(
|
||||||
|
int credits) const = 0;
|
||||||
virtual void rowUpdateRow(not_null<Row*> row) = 0;
|
virtual void rowUpdateRow(not_null<Row*> row) = 0;
|
||||||
virtual void rowPaintIcon(
|
virtual void rowPaintIcon(
|
||||||
QPainter &p,
|
QPainter &p,
|
||||||
|
@ -95,6 +100,7 @@ public:
|
||||||
bool forceRound) override;
|
bool forceRound) override;
|
||||||
|
|
||||||
QSize rightActionSize() const override;
|
QSize rightActionSize() const override;
|
||||||
|
bool rightActionDisabled() const override;
|
||||||
QMargins rightActionMargins() const override;
|
QMargins rightActionMargins() const override;
|
||||||
void rightActionPaint(
|
void rightActionPaint(
|
||||||
Painter &p,
|
Painter &p,
|
||||||
|
@ -106,6 +112,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const not_null<RowDelegate*> _delegate;
|
const not_null<RowDelegate*> _delegate;
|
||||||
|
std::optional<SubscriptionRightLabel> _rightLabel;
|
||||||
InviteLinkData _data;
|
InviteLinkData _data;
|
||||||
QString _status;
|
QString _status;
|
||||||
float64 _progressTillExpire = 0.;
|
float64 _progressTillExpire = 0.;
|
||||||
|
@ -141,7 +148,9 @@ private:
|
||||||
[[nodiscard]] Color ComputeColor(
|
[[nodiscard]] Color ComputeColor(
|
||||||
const InviteLinkData &link,
|
const InviteLinkData &link,
|
||||||
float64 progress) {
|
float64 progress) {
|
||||||
return link.revoked
|
return link.subscription
|
||||||
|
? Color::Subscription
|
||||||
|
: link.revoked
|
||||||
? Color::Revoked
|
? Color::Revoked
|
||||||
: (progress >= 1.)
|
: (progress >= 1.)
|
||||||
? Color::Expired
|
? Color::Expired
|
||||||
|
@ -149,8 +158,6 @@ private:
|
||||||
? Color::ExpireSoon
|
? Color::ExpireSoon
|
||||||
: (progress >= 0.)
|
: (progress >= 0.)
|
||||||
? Color::Expiring
|
? Color::Expiring
|
||||||
: link.subscription
|
|
||||||
? Color::Subscription
|
|
||||||
: Color::Permanent;
|
: Color::Permanent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,11 +243,13 @@ Row::Row(
|
||||||
, _data(data)
|
, _data(data)
|
||||||
, _progressTillExpire(ComputeProgress(data, now))
|
, _progressTillExpire(ComputeProgress(data, now))
|
||||||
, _color(ComputeColor(data, _progressTillExpire)) {
|
, _color(ComputeColor(data, _progressTillExpire)) {
|
||||||
|
_rightLabel = _delegate->rightLabel(_data.subscription.credits);
|
||||||
setCustomStatus(ComputeStatus(data, now));
|
setCustomStatus(ComputeStatus(data, now));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Row::update(const InviteLinkData &data, TimeId now) {
|
void Row::update(const InviteLinkData &data, TimeId now) {
|
||||||
_data = data;
|
_data = data;
|
||||||
|
_rightLabel = _delegate->rightLabel(_data.subscription.credits);
|
||||||
_progressTillExpire = ComputeProgress(data, now);
|
_progressTillExpire = ComputeProgress(data, now);
|
||||||
_color = ComputeColor(data, _progressTillExpire);
|
_color = ComputeColor(data, _progressTillExpire);
|
||||||
setCustomStatus(ComputeStatus(data, now));
|
setCustomStatus(ComputeStatus(data, now));
|
||||||
|
@ -311,12 +320,22 @@ PaintRoundImageCallback Row::generatePaintUserpicCallback(bool forceRound) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize Row::rightActionSize() const {
|
QSize Row::rightActionSize() const {
|
||||||
|
if (_rightLabel) {
|
||||||
|
return _rightLabel->size;
|
||||||
|
}
|
||||||
return QSize(
|
return QSize(
|
||||||
st::inviteLinkThreeDotsIcon.width(),
|
st::inviteLinkThreeDotsIcon.width(),
|
||||||
st::inviteLinkThreeDotsIcon.height());
|
st::inviteLinkThreeDotsIcon.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Row::rightActionDisabled() const {
|
||||||
|
return _rightLabel.has_value();
|
||||||
|
}
|
||||||
|
|
||||||
QMargins Row::rightActionMargins() const {
|
QMargins Row::rightActionMargins() const {
|
||||||
|
if (_rightLabel) {
|
||||||
|
return QMargins(0, 0, st::boxRowPadding.right(), 0);
|
||||||
|
}
|
||||||
return QMargins(
|
return QMargins(
|
||||||
0,
|
0,
|
||||||
(st::inviteLinkList.item.height - rightActionSize().height()) / 2,
|
(st::inviteLinkList.item.height - rightActionSize().height()) / 2,
|
||||||
|
@ -331,6 +350,9 @@ void Row::rightActionPaint(
|
||||||
int outerWidth,
|
int outerWidth,
|
||||||
bool selected,
|
bool selected,
|
||||||
bool actionSelected) {
|
bool actionSelected) {
|
||||||
|
if (_rightLabel) {
|
||||||
|
return _rightLabel->draw(p, x, y, st::inviteLinkList.item.height);
|
||||||
|
}
|
||||||
(actionSelected
|
(actionSelected
|
||||||
? st::inviteLinkThreeDotsIconOver
|
? st::inviteLinkThreeDotsIconOver
|
||||||
: st::inviteLinkThreeDotsIcon).paint(p, x, y, outerWidth);
|
: st::inviteLinkThreeDotsIcon).paint(p, x, y, outerWidth);
|
||||||
|
@ -360,6 +382,7 @@ public:
|
||||||
not_null<PeerListRow*> row) override;
|
not_null<PeerListRow*> row) override;
|
||||||
Main::Session &session() const override;
|
Main::Session &session() const override;
|
||||||
|
|
||||||
|
std::optional<SubscriptionRightLabel> rightLabel(int) const override;
|
||||||
void rowUpdateRow(not_null<Row*> row) override;
|
void rowUpdateRow(not_null<Row*> row) override;
|
||||||
void rowPaintIcon(
|
void rowPaintIcon(
|
||||||
QPainter &p,
|
QPainter &p,
|
||||||
|
@ -645,6 +668,17 @@ void LinksController::expiringProgressTimer() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<SubscriptionRightLabel> LinksController::rightLabel(
|
||||||
|
int credits) const {
|
||||||
|
if (credits > 0) {
|
||||||
|
return Settings::PaintSubscriptionRightLabelCallback(
|
||||||
|
&session(),
|
||||||
|
st::inviteLinkList.item,
|
||||||
|
credits);
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
void LinksController::rowUpdateRow(not_null<Row*> row) {
|
void LinksController::rowUpdateRow(not_null<Row*> row) {
|
||||||
delegate()->peerListUpdateRow(row);
|
delegate()->peerListUpdateRow(row);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue