Added initial support of complex boosts list in boosts info.

This commit is contained in:
23rd 2023-11-01 15:24:38 +03:00 committed by John Preston
parent 69b24c494e
commit 01573af0de
3 changed files with 91 additions and 16 deletions

View file

@ -4328,6 +4328,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_boosts_link_subtext" = "Share this link with your subscribers to get more boosts."; "lng_boosts_link_subtext" = "Share this link with your subscribers to get more boosts.";
"lng_boosts_get_boosts" = "Get Boosts via Gifts"; "lng_boosts_get_boosts" = "Get Boosts via Gifts";
"lng_boosts_get_boosts_subtext" = "Get more boosts for your channel by gifting Telegram Premium to your subscribers."; "lng_boosts_get_boosts_subtext" = "Get more boosts for your channel by gifting Telegram Premium to your subscribers.";
"lng_boosts_list_unclaimed" = "Unclaimed";
"lng_boosts_list_pending" = "To be distributed";
"lng_boosts_list_pending_about" = "The recipient will be selected when the giveaway ends.";
// Wnd specific // Wnd specific

View file

@ -554,6 +554,7 @@ void Boosts::requestBoosts(
constexpr auto kTlFirstSlice = tl::make_int(kFirstSlice); constexpr auto kTlFirstSlice = tl::make_int(kFirstSlice);
constexpr auto kTlLimit = tl::make_int(kLimit); constexpr auto kTlLimit = tl::make_int(kLimit);
_requestId = _api.request(MTPpremium_GetBoostsList( _requestId = _api.request(MTPpremium_GetBoostsList(
// MTP_flags(MTPpremium_GetBoostsList::Flag::f_gifts),
MTP_flags(0), MTP_flags(0),
_peer->input, _peer->input,
MTP_string(token.next), MTP_string(token.next),

View file

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h" #include "main/main_session.h"
#include "settings/settings_common.h" #include "settings/settings_common.h"
#include "ui/effects/toggle_arrow.h" #include "ui/effects/toggle_arrow.h"
#include "ui/empty_userpic.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "ui/rect.h" #include "ui/rect.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
@ -30,6 +31,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Info::Statistics { namespace Info::Statistics {
namespace { namespace {
constexpr auto kColorIndexUnclaimed = int(3);
constexpr auto kColorIndexPending = int(4);
void AddArrow(not_null<Ui::RpWidget*> parent) { void AddArrow(not_null<Ui::RpWidget*> parent) {
const auto arrow = Ui::CreateChild<Ui::RpWidget>(parent.get()); const auto arrow = Ui::CreateChild<Ui::RpWidget>(parent.get());
arrow->paintRequest( arrow->paintRequest(
@ -323,9 +327,14 @@ void PublicForwardsController::appendRow(
class BoostRow final : public PeerListRow { class BoostRow final : public PeerListRow {
public: public:
using PeerListRow::PeerListRow; BoostRow(not_null<PeerData*> peer, const Data::Boost &boost);
BoostRow(const Data::Boost &boost);
void setMultiplier(int multiplier); [[nodiscard]] const Data::Boost &boost() const;
[[nodiscard]] QString generateName() override;
[[nodiscard]] PaintRoundImageCallback generatePaintUserpicCallback(
bool forceRound) override;
int paintNameIconGetWidth( int paintNameIconGetWidth(
Painter &p, Painter &p,
@ -339,10 +348,72 @@ public:
bool selected) override; bool selected) override;
private: private:
void init();
void setMultiplier(int multiplier);
const Data::Boost _boost;
Ui::EmptyUserpic _userpic;
QImage _badge; QImage _badge;
}; };
BoostRow::BoostRow(not_null<PeerData*> peer, const Data::Boost &boost)
: PeerListRow(peer, UniqueRowIdFromString(boost.id))
, _boost(boost)
, _userpic(Ui::EmptyUserpic::UserpicColor(0), QString()) {
init();
}
BoostRow::BoostRow(const Data::Boost &boost)
: PeerListRow(UniqueRowIdFromString(boost.id))
, _boost(boost)
, _userpic(
Ui::EmptyUserpic::UserpicColor(boost.isUnclaimed
? kColorIndexUnclaimed
: kColorIndexPending),
QString()) {
init();
}
void BoostRow::init() {
setMultiplier(_boost.multiplier);
constexpr auto kMonthsDivider = int(30 * 86400);
const auto months = (_boost.expiresAt - _boost.date.toSecsSinceEpoch())
/ kMonthsDivider;
auto status = !PeerListRow::special()
? tr::lng_boosts_list_status(
tr::now,
lt_date,
langDateTime(_boost.date))
: tr::lng_months_tiny(tr::now, lt_count, months)
+ ' '
+ QChar(0x2022)
+ ' '
+ langDateTime(_boost.date);
PeerListRow::setCustomStatus(std::move(status));
}
const Data::Boost &BoostRow::boost() const {
return _boost;
}
QString BoostRow::generateName() {
return !PeerListRow::special()
? PeerListRow::generateName()
: _boost.isUnclaimed
? tr::lng_boosts_list_unclaimed(tr::now)
: tr::lng_boosts_list_pending(tr::now);
}
PaintRoundImageCallback BoostRow::generatePaintUserpicCallback(bool force) {
if (!PeerListRow::special()) {
return PeerListRow::generatePaintUserpicCallback(force);
}
return [=](Painter &p, int x, int y, int outerWidth, int size) mutable {
_userpic.paintCircle(p, x, y, outerWidth, size);
};
}
void BoostRow::setMultiplier(int multiplier) { void BoostRow::setMultiplier(int multiplier) {
if (!multiplier) { if (!multiplier) {
_badge = QImage(); _badge = QImage();
@ -480,27 +551,27 @@ void BoostsController::applySlice(const Data::BoostsListSlice &slice) {
_allLoaded = slice.allLoaded; _allLoaded = slice.allLoaded;
_apiToken = slice.token; _apiToken = slice.token;
const auto formatter = u"MMM d, yyyy"_q;
for (const auto &item : slice.list) { for (const auto &item : slice.list) {
const auto user = session().data().user(item.userId); auto row = [&] {
if (delegate()->peerListFindRow(user->id.value)) { if (item.userId && !item.isUnclaimed) {
continue; const auto user = session().data().user(item.userId);
} return std::make_unique<BoostRow>(user, item);
auto row = std::make_unique<BoostRow>(user); } else {
row->setMultiplier(item.multiplier); return std::make_unique<BoostRow>(item);
row->setCustomStatus(tr::lng_boosts_list_status( }
tr::now, }();
lt_date,
QLocale().toString(item.date, formatter)));
delegate()->peerListAppendRow(std::move(row)); delegate()->peerListAppendRow(std::move(row));
} }
delegate()->peerListRefreshRows(); delegate()->peerListRefreshRows();
} }
void BoostsController::rowClicked(not_null<PeerListRow*> row) { void BoostsController::rowClicked(not_null<PeerListRow*> row) {
crl::on_main([=, peer = row->peer()] { if (!row->special()) {
_showPeerInfo(peer); crl::on_main([=, peer = row->peer()] {
}); _showPeerInfo(peer);
});
return;
}
} }
} // namespace } // namespace