Add emojiStatus.expiration_date.

This commit is contained in:
levlam 2023-07-06 20:14:42 +03:00
parent 565403e241
commit 5130ec7760
7 changed files with 31 additions and 30 deletions

View File

@ -681,8 +681,10 @@ premiumPaymentOption currency:string amount:int53 discount_percentage:int32 mont
premiumStatePaymentOption payment_option:premiumPaymentOption is_current:Bool is_upgrade:Bool last_transaction_id:string = PremiumStatePaymentOption;
//@description Describes a custom emoji to be shown instead of the Telegram Premium badge @custom_emoji_id Identifier of the custom emoji in stickerFormatTgs format
emojiStatus custom_emoji_id:int64 = EmojiStatus;
//@description Describes a custom emoji to be shown instead of the Telegram Premium badge
//@custom_emoji_id Identifier of the custom emoji in stickerFormatTgs format
//@expiration_date Point in time (Unix timestamp) when the status will expire; 0 if never
emojiStatus custom_emoji_id:int64 expiration_date:int32 = EmojiStatus;
//@description Contains a list of custom emoji identifiers, which can be set as emoji statuses @custom_emoji_ids The list of custom emoji identifiers
emojiStatuses custom_emoji_ids:vector<int64> = EmojiStatuses;
@ -7939,10 +7941,8 @@ toggleUsernameIsActive username:string is_active:Bool = Ok;
//@description Changes order of active usernames of the current user @usernames The new order of active usernames. All currently active usernames must be specified
reorderActiveUsernames usernames:vector<string> = Ok;
//@description Changes the emoji status of the current user; for Telegram Premium users only
//@emoji_status New emoji status; pass null to switch to the default badge
//@duration Duration of the status, in seconds; pass 0 to keep the status active until it will be changed manually
setEmojiStatus emoji_status:emojiStatus duration:int32 = Ok;
//@description Changes the emoji status of the current user; for Telegram Premium users only @emoji_status New emoji status; pass null to switch to the default badge
setEmojiStatus emoji_status:emojiStatus = Ok;
//@description Changes the location of the current user. Needs to be called if getOption("is_location_visible") is true and location changes for more than 1 kilometer @location The new location of the user
setLocation location:location = Ok;

View File

@ -11960,15 +11960,15 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
}
auto unix_time = G()->unix_time();
auto effective_custom_emoji_id = u->emoji_status.get_effective_custom_emoji_id(u->is_premium, unix_time);
if (effective_custom_emoji_id != u->last_sent_emoji_status) {
u->last_sent_emoji_status = effective_custom_emoji_id;
auto effective_emoji_status = u->emoji_status.get_effective_emoji_status(u->is_premium, unix_time);
if (effective_emoji_status != u->last_sent_emoji_status) {
u->last_sent_emoji_status = effective_emoji_status;
u->is_changed = true;
} else {
u->need_save_to_database = true;
}
if (u->last_sent_emoji_status.is_valid()) {
auto until_date = u->emoji_status.get_until_date();
if (!u->last_sent_emoji_status.is_empty()) {
auto until_date = u->last_sent_emoji_status.get_until_date();
auto left_time = until_date - unix_time;
if (left_time >= 0 && left_time < 30 * 86400) {
LOG(DEBUG) << "Set emoji status timeout for " << user_id << " in " << left_time << " seconds";
@ -18859,7 +18859,8 @@ tl_object_ptr<td_api::user> ContactsManager::get_user_object(UserId user_id, con
type = make_tl_object<td_api::userTypeRegular>();
}
auto emoji_status = u->last_sent_emoji_status.is_valid() ? u->emoji_status.get_emoji_status_object() : nullptr;
auto emoji_status =
!u->last_sent_emoji_status.is_empty() ? u->last_sent_emoji_status.get_emoji_status_object() : nullptr;
auto have_access = user_id == get_my_id() || have_input_peer_user(u, user_id, AccessRights::Know);
return td_api::make_object<td_api::user>(
user_id.get(), u->first_name, u->last_name, u->usernames.get_usernames_object(), u->phone_number,

View File

@ -746,7 +746,7 @@ class ContactsManager final : public Actor {
string phone_number;
int64 access_hash = -1;
EmojiStatus emoji_status;
CustomEmojiId last_sent_emoji_status;
EmojiStatus last_sent_emoji_status;
ProfilePhoto photo;

View File

@ -202,18 +202,18 @@ class ClearRecentEmojiStatusesQuery final : public Td::ResultHandler {
}
};
EmojiStatus::EmojiStatus(const td_api::object_ptr<td_api::emojiStatus> &emoji_status, int32 duration) {
EmojiStatus::EmojiStatus(const td_api::object_ptr<td_api::emojiStatus> &emoji_status) {
if (emoji_status == nullptr) {
return;
}
custom_emoji_id_ = CustomEmojiId(emoji_status->custom_emoji_id_);
if (duration != 0) {
if (emoji_status->expiration_date_ != 0) {
int32 current_time = G()->unix_time();
if (duration >= std::numeric_limits<int32>::max() - current_time) {
until_date_ = std::numeric_limits<int32>::max();
if (emoji_status->expiration_date_ > current_time) {
until_date_ = emoji_status->expiration_date_;
} else {
until_date_ = current_time + duration;
custom_emoji_id_ = {};
}
}
}
@ -255,17 +255,17 @@ td_api::object_ptr<td_api::emojiStatus> EmojiStatus::get_emoji_status_object() c
if (is_empty()) {
return nullptr;
}
return td_api::make_object<td_api::emojiStatus>(custom_emoji_id_.get());
return td_api::make_object<td_api::emojiStatus>(custom_emoji_id_.get(), until_date_);
}
CustomEmojiId EmojiStatus::get_effective_custom_emoji_id(bool is_premium, int32 unix_time) const {
EmojiStatus EmojiStatus::get_effective_emoji_status(bool is_premium, int32 unix_time) const {
if (!is_premium) {
return CustomEmojiId();
return EmojiStatus();
}
if (until_date_ != 0 && until_date_ <= unix_time) {
return CustomEmojiId();
return EmojiStatus();
}
return custom_emoji_id_;
return *this;
}
StringBuilder &operator<<(StringBuilder &string_builder, const EmojiStatus &emoji_status) {

View File

@ -30,7 +30,7 @@ class EmojiStatus {
public:
EmojiStatus() = default;
EmojiStatus(const td_api::object_ptr<td_api::emojiStatus> &emoji_status, int32 duration);
explicit EmojiStatus(const td_api::object_ptr<td_api::emojiStatus> &emoji_status);
explicit EmojiStatus(tl_object_ptr<telegram_api::EmojiStatus> &&emoji_status);
@ -38,7 +38,7 @@ class EmojiStatus {
td_api::object_ptr<td_api::emojiStatus> get_emoji_status_object() const;
CustomEmojiId get_effective_custom_emoji_id(bool is_premium, int32 unix_time) const;
EmojiStatus get_effective_emoji_status(bool is_premium, int32 unix_time) const;
bool is_empty() const {
return !custom_emoji_id_.is_valid();

View File

@ -7186,7 +7186,7 @@ void Td::on_request(uint64 id, td_api::reorderActiveUsernames &request) {
void Td::on_request(uint64 id, const td_api::setEmojiStatus &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
contacts_manager_->set_emoji_status(EmojiStatus(request.emoji_status_, request.duration_), std::move(promise));
contacts_manager_->set_emoji_status(EmojiStatus(request.emoji_status_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getThemedEmojiStatuses &request) {

View File

@ -5158,13 +5158,13 @@ class CliClient final : public Actor {
} else if (op == "raun") {
send_request(td_api::make_object<td_api::reorderActiveUsernames>(autosplit_str(args)));
} else if (op == "sese") {
send_request(td_api::make_object<td_api::setEmojiStatus>(nullptr, 0));
send_request(td_api::make_object<td_api::setEmojiStatus>(nullptr));
} else if (op == "ses") {
int64 custom_emoji_id;
int32 until_date;
get_args(args, custom_emoji_id, until_date);
int32 expiration_date;
get_args(args, custom_emoji_id, expiration_date);
send_request(td_api::make_object<td_api::setEmojiStatus>(
td_api::make_object<td_api::emojiStatus>(custom_emoji_id), until_date));
td_api::make_object<td_api::emojiStatus>(custom_emoji_id, expiration_date)));
} else if (op == "gtes") {
send_request(td_api::make_object<td_api::getThemedEmojiStatuses>());
} else if (op == "gdes") {