2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Parse current stars rating values.

This commit is contained in:
John Preston
2025-07-15 10:28:13 +04:00
parent 65e3111e35
commit 25d4a9c7a6
5 changed files with 68 additions and 16 deletions

View File

@@ -99,28 +99,29 @@ struct PeerUpdate {
StarRefProgram = (1ULL << 35),
PaysPerMessage = (1ULL << 36),
GiftSettings = (1ULL << 37),
StarsRating = (1ULL << 38),
// For chats and channels
InviteLinks = (1ULL << 38),
Members = (1ULL << 39),
Admins = (1ULL << 40),
BannedUsers = (1ULL << 41),
Rights = (1ULL << 42),
PendingRequests = (1ULL << 43),
Reactions = (1ULL << 44),
InviteLinks = (1ULL << 39),
Members = (1ULL << 40),
Admins = (1ULL << 41),
BannedUsers = (1ULL << 42),
Rights = (1ULL << 43),
PendingRequests = (1ULL << 44),
Reactions = (1ULL << 45),
// For channels
ChannelAmIn = (1ULL << 45),
StickersSet = (1ULL << 46),
EmojiSet = (1ULL << 47),
DiscussionLink = (1ULL << 48),
MonoforumLink = (1ULL << 49),
ChannelLocation = (1ULL << 50),
Slowmode = (1ULL << 51),
GroupCall = (1ULL << 52),
ChannelAmIn = (1ULL << 46),
StickersSet = (1ULL << 47),
EmojiSet = (1ULL << 48),
DiscussionLink = (1ULL << 49),
MonoforumLink = (1ULL << 50),
ChannelLocation = (1ULL << 51),
Slowmode = (1ULL << 52),
GroupCall = (1ULL << 53),
// For iteration
LastUsedBit = (1ULL << 52),
LastUsedBit = (1ULL << 53),
};
using Flags = base::flags<Flag>;
friend inline constexpr auto is_flag_type(Flag) { return true; }

View File

@@ -1690,6 +1690,13 @@ int PeerData::starsPerMessageChecked() const {
return starsPerMessage();
}
Data::StarsRating PeerData::starsRating() const {
if (const auto user = asUser()) {
return user->starsRating();
}
return {};
}
Data::GroupCall *PeerData::groupCall() const {
if (const auto chat = asChat()) {
return chat->groupCall();

View File

@@ -109,6 +109,19 @@ struct UnavailableReason {
const MTPvector<MTPRestrictionReason> *list);
};
struct StarsRating {
int level = 0;
int levelStars = 0;
int currentStars = 0;
int nextLevelStars = 0;
explicit operator bool() const {
return level != 0 || levelStars != 0;
}
friend inline bool operator==(StarsRating, StarsRating) = default;
};
bool ApplyBotMenuButton(
not_null<BotInfo*> info,
const MTPBotMenuButton *button);
@@ -290,6 +303,7 @@ public:
[[nodiscard]] int starsPerMessage() const;
[[nodiscard]] int starsPerMessageChecked() const;
[[nodiscard]] Data::StarsRating starsRating() const;
[[nodiscard]] UserData *asBot();
[[nodiscard]] const UserData *asBot() const;

View File

@@ -64,6 +64,20 @@ bool ApplyBotVerifierSettings(
return false;
}
[[nodiscard]] Data::StarsRating ParseStarsRating(
const MTPStarsRating *rating) {
if (!rating) {
return {};
}
const auto &data = rating->data();
return {
.level = data.vlevel().v,
.levelStars = int(data.vcurrent_level_stars().v),
.currentStars = int(data.vstars().v),
.nextLevelStars = int(data.vnext_level_stars().value_or_empty()),
};
}
} // namespace
BotInfo::BotInfo() = default;
@@ -563,6 +577,17 @@ void UserData::setStarsPerMessage(int stars) {
checkTrustedPayForMessage();
}
void UserData::setStarsRating(Data::StarsRating value) {
if (_starsRating != value) {
_starsRating = value;
session().changes().peerUpdated(this, UpdateFlag::StarsRating);
}
}
Data::StarsRating UserData::starsRating() const {
return _starsRating;
}
bool UserData::canAddContact() const {
return canShareThisContact() && !isContact();
}
@@ -848,6 +873,7 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
}
user->setBotVerifyDetails(
ParseBotVerifyDetails(update.vbot_verification()));
user->setStarsRating(ParseStarsRating(update.vstars_rating()));
if (const auto gifts = update.vdisallowed_gifts()) {
const auto &data = gifts->data();

View File

@@ -195,6 +195,9 @@ public:
void setStarsPerMessage(int stars);
[[nodiscard]] int starsPerMessage() const;
void setStarsRating(Data::StarsRating value);
[[nodiscard]] Data::StarsRating starsRating() const;
[[nodiscard]] bool canShareThisContact() const;
[[nodiscard]] bool canAddContact() const;
@@ -300,6 +303,7 @@ private:
QString _phone;
QString _privateForwardName;
std::unique_ptr<Ui::BotVerifyDetails> _botVerifyDetails;
Data::StarsRating _starsRating;
ChannelId _personalChannelId = 0;
MsgId _personalChannelMessageId = 0;