Improved API support of boosts list.

This commit is contained in:
23rd 2023-10-24 13:07:06 +03:00 committed by John Preston
parent 1852161fbf
commit 9df551a145
5 changed files with 45 additions and 11 deletions

View File

@ -567,9 +567,30 @@ void Boosts::requestBoosts(
auto list = std::vector<Data::Boost>();
list.reserve(data.vboosts().v.size());
for (const auto &boost : data.vboosts().v) {
const auto &data = boost.data();
const auto path = data.vused_gift_slug()
? (u"giftcode/"_q + qs(data.vused_gift_slug()->v))
: QString();
auto giftCodeLink = !path.isEmpty()
? Data::GiftCodeLink{
_peer->session().createInternalLink(path),
_peer->session().createInternalLinkFull(path),
qs(data.vused_gift_slug()->v),
}
: Data::GiftCodeLink();
list.push_back({
boost.data().vuser_id().value_or_empty(),
QDateTime::fromSecsSinceEpoch(boost.data().vexpires().v),
data.is_gift(),
data.is_giveaway(),
data.is_unclaimed(),
qs(data.vid()),
data.vuser_id().value_or_empty(),
data.vgiveaway_msg_id()
? FullMsgId{ _peer->id, data.vgiveaway_msg_id()->v }
: FullMsgId(),
QDateTime::fromSecsSinceEpoch(data.vdate().v),
data.vexpires().v,
std::move(giftCodeLink),
data.vmultiplier().value_or_empty(),
});
}
done(Data::BoostsListSlice{

View File

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/unixtime.h"
#include "base/weak_ptr.h"
#include "boxes/peers/prepare_short_info_box.h"
#include "data/data_boosts.h"
#include "data/data_changes.h"
#include "data/data_channel.h"
#include "data/data_media_types.h" // Data::Giveaway
@ -237,11 +238,7 @@ void GiftBox(
}, box->lifetime());
}
struct GiftCodeLink {
QString text;
QString link;
};
[[nodiscard]] GiftCodeLink MakeGiftCodeLink(
[[nodiscard]] Data::GiftCodeLink MakeGiftCodeLink(
not_null<Main::Session*> session,
const QString &slug) {
const auto path = u"giftcode/"_q + slug;

View File

@ -19,9 +19,24 @@ struct BoostsOverview final {
float64 premiumMemberPercentage = 0;
};
struct GiftCodeLink final {
QString text;
QString link;
QString slug;
};
struct Boost final {
bool isGift = false;
bool isGiveaway = false;
bool isUnclaimed = false;
QString id;
UserId userId = UserId(0);
QDateTime expirationDate;
FullMsgId giveawayMessage;
QDateTime date;
crl::time expiresAt = 0;
GiftCodeLink giftCodeLink;
int multiplier = 0;
};
struct BoostsListSlice final {

View File

@ -100,8 +100,9 @@ void FillOverview(
const auto topLeftLabel = addPrimary(stats.level);
const auto topRightLabel = addPrimary(stats.premiumMemberCount);
const auto bottomLeftLabel = addPrimary(stats.boostCount);
const auto bottomRightLabel = addPrimary(
stats.nextLevelBoostCount - stats.boostCount);
const auto bottomRightLabel = addPrimary(std::max(
stats.nextLevelBoostCount - stats.boostCount,
0));
addSub(
topLeftLabel,

View File

@ -397,7 +397,7 @@ void BoostsController::applySlice(const Data::BoostsListSlice &slice) {
row->setCustomStatus(tr::lng_boosts_list_status(
tr::now,
lt_date,
QLocale().toString(item.expirationDate, formatter)));
QLocale().toString(item.date, formatter)));
delegate()->peerListAppendRow(std::move(row));
}
delegate()->peerListRefreshRows();