mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 05:07:10 +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/main_session.h"
|
||||
#include "api/api_invite_links.h"
|
||||
#include "settings/settings_credits_graphics.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
|
@ -64,8 +65,12 @@ struct InviteLinkAction {
|
|||
|
||||
class Row;
|
||||
|
||||
using SubscriptionRightLabel = Settings::SubscriptionRightLabel;
|
||||
|
||||
class RowDelegate {
|
||||
public:
|
||||
virtual std::optional<SubscriptionRightLabel> rightLabel(
|
||||
int credits) const = 0;
|
||||
virtual void rowUpdateRow(not_null<Row*> row) = 0;
|
||||
virtual void rowPaintIcon(
|
||||
QPainter &p,
|
||||
|
@ -95,6 +100,7 @@ public:
|
|||
bool forceRound) override;
|
||||
|
||||
QSize rightActionSize() const override;
|
||||
bool rightActionDisabled() const override;
|
||||
QMargins rightActionMargins() const override;
|
||||
void rightActionPaint(
|
||||
Painter &p,
|
||||
|
@ -106,6 +112,7 @@ public:
|
|||
|
||||
private:
|
||||
const not_null<RowDelegate*> _delegate;
|
||||
std::optional<SubscriptionRightLabel> _rightLabel;
|
||||
InviteLinkData _data;
|
||||
QString _status;
|
||||
float64 _progressTillExpire = 0.;
|
||||
|
@ -141,7 +148,9 @@ private:
|
|||
[[nodiscard]] Color ComputeColor(
|
||||
const InviteLinkData &link,
|
||||
float64 progress) {
|
||||
return link.revoked
|
||||
return link.subscription
|
||||
? Color::Subscription
|
||||
: link.revoked
|
||||
? Color::Revoked
|
||||
: (progress >= 1.)
|
||||
? Color::Expired
|
||||
|
@ -149,8 +158,6 @@ private:
|
|||
? Color::ExpireSoon
|
||||
: (progress >= 0.)
|
||||
? Color::Expiring
|
||||
: link.subscription
|
||||
? Color::Subscription
|
||||
: Color::Permanent;
|
||||
}
|
||||
|
||||
|
@ -236,11 +243,13 @@ Row::Row(
|
|||
, _data(data)
|
||||
, _progressTillExpire(ComputeProgress(data, now))
|
||||
, _color(ComputeColor(data, _progressTillExpire)) {
|
||||
_rightLabel = _delegate->rightLabel(_data.subscription.credits);
|
||||
setCustomStatus(ComputeStatus(data, now));
|
||||
}
|
||||
|
||||
void Row::update(const InviteLinkData &data, TimeId now) {
|
||||
_data = data;
|
||||
_rightLabel = _delegate->rightLabel(_data.subscription.credits);
|
||||
_progressTillExpire = ComputeProgress(data, now);
|
||||
_color = ComputeColor(data, _progressTillExpire);
|
||||
setCustomStatus(ComputeStatus(data, now));
|
||||
|
@ -311,12 +320,22 @@ PaintRoundImageCallback Row::generatePaintUserpicCallback(bool forceRound) {
|
|||
}
|
||||
|
||||
QSize Row::rightActionSize() const {
|
||||
if (_rightLabel) {
|
||||
return _rightLabel->size;
|
||||
}
|
||||
return QSize(
|
||||
st::inviteLinkThreeDotsIcon.width(),
|
||||
st::inviteLinkThreeDotsIcon.height());
|
||||
}
|
||||
|
||||
bool Row::rightActionDisabled() const {
|
||||
return _rightLabel.has_value();
|
||||
}
|
||||
|
||||
QMargins Row::rightActionMargins() const {
|
||||
if (_rightLabel) {
|
||||
return QMargins(0, 0, st::boxRowPadding.right(), 0);
|
||||
}
|
||||
return QMargins(
|
||||
0,
|
||||
(st::inviteLinkList.item.height - rightActionSize().height()) / 2,
|
||||
|
@ -331,6 +350,9 @@ void Row::rightActionPaint(
|
|||
int outerWidth,
|
||||
bool selected,
|
||||
bool actionSelected) {
|
||||
if (_rightLabel) {
|
||||
return _rightLabel->draw(p, x, y, st::inviteLinkList.item.height);
|
||||
}
|
||||
(actionSelected
|
||||
? st::inviteLinkThreeDotsIconOver
|
||||
: st::inviteLinkThreeDotsIcon).paint(p, x, y, outerWidth);
|
||||
|
@ -360,6 +382,7 @@ public:
|
|||
not_null<PeerListRow*> row) override;
|
||||
Main::Session &session() const override;
|
||||
|
||||
std::optional<SubscriptionRightLabel> rightLabel(int) const override;
|
||||
void rowUpdateRow(not_null<Row*> row) override;
|
||||
void rowPaintIcon(
|
||||
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) {
|
||||
delegate()->peerListUpdateRow(row);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue