add user status

This commit is contained in:
Giuseppe Marino 2022-05-02 22:08:22 +02:00
parent edcb8529e6
commit 411f4b15c5
No known key found for this signature in database
GPG Key ID: 2BC70C5463357449
2 changed files with 44 additions and 0 deletions

View File

@ -411,6 +411,9 @@ class Client::JsonUser final : public Jsonable {
if (user_info != nullptr && user_info->is_scam) { if (user_info != nullptr && user_info->is_scam) {
object("is_scam", td::JsonBool(user_info->is_scam)); object("is_scam", td::JsonBool(user_info->is_scam));
} }
if (user_info != nullptr) {
json_store_user_status(object, user_info->status.get());
}
//end custom properties impl //end custom properties impl
if (is_bot && full_bot_info_) { if (is_bot && full_bot_info_) {
@ -715,6 +718,8 @@ class Client::JsonChat final : public Jsonable {
if (user_info->is_scam) { if (user_info->is_scam) {
object("is_scam", td::JsonBool(user_info->is_scam)); object("is_scam", td::JsonBool(user_info->is_scam));
} }
json_store_user_status(object, user_info->status.get());
// end custom properties impl // end custom properties impl
if (is_full_) { if (is_full_) {
@ -5269,6 +5274,12 @@ void Client::on_update(object_ptr<td_api::Object> result) {
set_user_has_private_forwards(user_id, full_info->has_private_forwards_); set_user_has_private_forwards(user_id, full_info->has_private_forwards_);
break; break;
} }
case td_api::updateUserStatus::ID: {
auto update = move_object_as<td_api::updateUserStatus>(result);
auto user_id = update->user_id_;
set_user_status(user_id, std::move(update->status_));
break;
}
case td_api::updateBasicGroup::ID: { case td_api::updateBasicGroup::ID: {
auto update = move_object_as<td_api::updateBasicGroup>(result); auto update = move_object_as<td_api::updateBasicGroup>(result);
auto *group_info = add_group_info(update->basic_group_->id_); auto *group_info = add_group_info(update->basic_group_->id_);
@ -10195,6 +10206,7 @@ void Client::add_user(UserInfo *user_info, object_ptr<td_api::user> &&user) {
// start custom properties // start custom properties
user_info->is_verified = user->is_verified_; user_info->is_verified = user->is_verified_;
user_info->is_scam = user->is_scam_; user_info->is_scam = user->is_scam_;
user_info->status = std::move(user->status_);
//end custom properties //end custom properties
user_info->have_access = user->have_access_; user_info->have_access = user->have_access_;
@ -10251,6 +10263,10 @@ void Client::set_user_has_private_forwards(int64 user_id, bool has_private_forwa
add_user_info(user_id)->has_private_forwards = has_private_forwards; add_user_info(user_id)->has_private_forwards = has_private_forwards;
} }
void Client::set_user_status(int64 user_id, object_ptr<td_api::UserStatus> &&status) {
add_user_info(user_id)->status = std::move(status);
}
void Client::add_group(GroupInfo *group_info, object_ptr<td_api::basicGroup> &&group) { void Client::add_group(GroupInfo *group_info, object_ptr<td_api::basicGroup> &&group) {
group_info->member_count = group->member_count_; group_info->member_count = group->member_count_;
group_info->left = group->status_->get_id() == td_api::chatMemberStatusLeft::ID; group_info->left = group->status_->get_id() == td_api::chatMemberStatusLeft::ID;
@ -10528,6 +10544,30 @@ void Client::json_store_permissions(td::JsonObjectScope &object, const td_api::c
object("can_pin_messages", td::JsonBool(permissions->can_pin_messages_)); object("can_pin_messages", td::JsonBool(permissions->can_pin_messages_));
} }
void Client::json_store_user_status(td::JsonObjectScope &object, const td_api::UserStatus *userStatus) {
switch (userStatus->get_id()) {
case td_api::userStatusEmpty::ID:
object("user_status", nullptr);
break;
case td_api::userStatusLastMonth::ID:
object("user_status", "month");
break;
case td_api::userStatusLastWeek::ID:
object("user_status", "week");
break;
case td_api::userStatusOffline::ID:
object("user_status", "offline");
object("last_seen", static_cast<const td_api::userStatusOffline *>(userStatus)->was_online_);
break;
case td_api::userStatusOnline::ID:
object("user_status", "online");
break;
case td_api::userStatusRecently::ID:
object("user_status", "recently");
break;
}
}
Client::Slice Client::get_update_type_name(UpdateType update_type) { Client::Slice Client::get_update_type_name(UpdateType update_type) {
switch (update_type) { switch (update_type) {
case UpdateType::Message: case UpdateType::Message:

View File

@ -711,6 +711,7 @@ class Client final : public WebhookActor::Callback {
// start custom properties // start custom properties
bool is_verified = false; bool is_verified = false;
bool is_scam = false; bool is_scam = false;
object_ptr<td_api::UserStatus> status;
// end custom properties // end custom properties
bool have_access = false; bool have_access = false;
@ -723,6 +724,7 @@ class Client final : public WebhookActor::Callback {
void set_user_photo(int64 user_id, object_ptr<td_api::chatPhoto> &&photo); void set_user_photo(int64 user_id, object_ptr<td_api::chatPhoto> &&photo);
void set_user_bio(int64 user_id, td::string &&bio); void set_user_bio(int64 user_id, td::string &&bio);
void set_user_has_private_forwards(int64 user_id, bool has_private_forwards); void set_user_has_private_forwards(int64 user_id, bool has_private_forwards);
void set_user_status(int64 user_id, object_ptr<td_api::UserStatus> &&status);
UserInfo *add_user_info(int64 user_id); UserInfo *add_user_info(int64 user_id);
const UserInfo *get_user_info(int64 user_id) const; const UserInfo *get_user_info(int64 user_id) const;
@ -870,6 +872,8 @@ class Client final : public WebhookActor::Callback {
static void json_store_permissions(td::JsonObjectScope &object, const td_api::chatPermissions *permissions); static void json_store_permissions(td::JsonObjectScope &object, const td_api::chatPermissions *permissions);
static void json_store_user_status(td::JsonObjectScope &object, const td_api::UserStatus *userStatus);
void remove_replies_to_message(int64 chat_id, int64 reply_to_message_id, bool only_from_cache); void remove_replies_to_message(int64 chat_id, int64 reply_to_message_id, bool only_from_cache);
void delete_message(int64 chat_id, int64 message_id, bool only_from_cache); void delete_message(int64 chat_id, int64 message_id, bool only_from_cache);