Add "chat_join_request" updates.

This commit is contained in:
levlam 2021-11-04 13:35:43 +03:00
parent 2fa32d7db7
commit c9a2a62248
2 changed files with 50 additions and 4 deletions

View File

@ -2354,6 +2354,29 @@ class Client::JsonChatMemberUpdated : public Jsonable {
const Client *client_; const Client *client_;
}; };
class Client::JsonChatJoinRequest : public Jsonable {
public:
JsonChatJoinRequest(const td_api::updateNewChatJoinRequest *update, const Client *client)
: update_(update), client_(client) {
}
void store(JsonValueScope *scope) const {
auto object = scope->enter_object();
object("chat", JsonChat(update_->chat_id_, false, client_));
object("from", JsonUser(update_->request_->user_id_, client_));
object("date", update_->request_->date_);
if (!update_->request_->bio_.empty()) {
object("bio", update_->request_->bio_);
}
if (update_->invite_link_ != nullptr) {
object("invite_link", JsonChatInviteLink(update_->invite_link_.get(), client_));
}
}
private:
const td_api::updateNewChatJoinRequest *update_;
const Client *client_;
};
class Client::JsonGameHighScore : public Jsonable { class Client::JsonGameHighScore : public Jsonable {
public: public:
JsonGameHighScore(const td_api::gameHighScore *score, const Client *client) : score_(score), client_(client) { JsonGameHighScore(const td_api::gameHighScore *score, const Client *client) : score_(score), client_(client) {
@ -4427,6 +4450,9 @@ void Client::on_update(object_ptr<td_api::Object> result) {
case td_api::updateChatMember::ID: case td_api::updateChatMember::ID:
add_update_chat_member(move_object_as<td_api::updateChatMember>(result)); add_update_chat_member(move_object_as<td_api::updateChatMember>(result));
break; break;
case td_api::updateNewChatJoinRequest::ID:
add_update_chat_join_request(move_object_as<td_api::updateNewChatJoinRequest>(result));
break;
default: default:
// we are not interested in this update // we are not interested in this update
break; break;
@ -7134,8 +7160,10 @@ td::Status Client::process_create_chat_invite_link_query(PromisedQueryPtr &query
auto creates_join_request = to_bool(query->arg("creates_join_request")); auto creates_join_request = to_bool(query->arg("creates_join_request"));
check_chat(chat_id, AccessRights::Write, std::move(query), check_chat(chat_id, AccessRights::Write, std::move(query),
[this, name = name.str(), expire_date, member_limit, creates_join_request](int64 chat_id, PromisedQueryPtr query) { [this, name = name.str(), expire_date, member_limit, creates_join_request](int64 chat_id,
send_request(make_object<td_api::createChatInviteLink>(chat_id, name, expire_date, member_limit, creates_join_request), PromisedQueryPtr query) {
send_request(make_object<td_api::createChatInviteLink>(chat_id, name, expire_date, member_limit,
creates_join_request),
std::make_unique<TdOnGetChatInviteLinkCallback>(this, std::move(query))); std::make_unique<TdOnGetChatInviteLinkCallback>(this, std::move(query)));
}); });
return Status::OK(); return Status::OK();
@ -7150,8 +7178,10 @@ td::Status Client::process_edit_chat_invite_link_query(PromisedQueryPtr &query)
auto creates_join_request = to_bool(query->arg("creates_join_request")); auto creates_join_request = to_bool(query->arg("creates_join_request"));
check_chat(chat_id, AccessRights::Write, std::move(query), check_chat(chat_id, AccessRights::Write, std::move(query),
[this, invite_link = invite_link.str(), name = name.str(), expire_date, member_limit, creates_join_request](int64 chat_id, PromisedQueryPtr query) { [this, invite_link = invite_link.str(), name = name.str(), expire_date, member_limit,
send_request(make_object<td_api::editChatInviteLink>(chat_id, invite_link, name, expire_date, member_limit, creates_join_request), creates_join_request](int64 chat_id, PromisedQueryPtr query) {
send_request(make_object<td_api::editChatInviteLink>(chat_id, invite_link, name, expire_date,
member_limit, creates_join_request),
std::make_unique<TdOnGetChatInviteLinkCallback>(this, std::move(query))); std::make_unique<TdOnGetChatInviteLinkCallback>(this, std::move(query)));
}); });
return Status::OK(); return Status::OK();
@ -8548,6 +8578,8 @@ Client::Slice Client::get_update_type_name(UpdateType update_type) {
return Slice("my_chat_member"); return Slice("my_chat_member");
case UpdateType::ChatMember: case UpdateType::ChatMember:
return Slice("chat_member"); return Slice("chat_member");
case UpdateType::ChatJoinRequest:
return Slice("chat_join_request");
default: default:
UNREACHABLE(); UNREACHABLE();
return Slice(); return Slice();
@ -8836,6 +8868,16 @@ void Client::add_update_chat_member(object_ptr<td_api::updateChatMember> &&updat
} }
} }
void Client::add_update_chat_join_request(object_ptr<td_api::updateNewChatJoinRequest> &&update) {
CHECK(update != nullptr);
CHECK(update->request_ != nullptr);
auto left_time = update->request_->date_ + 86400 - get_unix_time();
if (left_time > 0) {
auto webhook_queue_id = update->chat_id_ + (static_cast<int64>(6) << 33);
add_update(UpdateType::ChatJoinRequest, JsonChatJoinRequest(update.get(), this), left_time, webhook_queue_id);
}
}
td::int64 Client::choose_added_member_id(const td_api::messageChatAddMembers *message_add_members) const { td::int64 Client::choose_added_member_id(const td_api::messageChatAddMembers *message_add_members) const {
CHECK(message_add_members != nullptr); CHECK(message_add_members != nullptr);
for (auto &member_user_id : message_add_members->member_user_ids_) { for (auto &member_user_id : message_add_members->member_user_ids_) {

View File

@ -139,6 +139,7 @@ class Client : public WebhookActor::Callback {
class JsonChatMember; class JsonChatMember;
class JsonChatMembers; class JsonChatMembers;
class JsonChatMemberUpdated; class JsonChatMemberUpdated;
class JsonChatJoinRequest;
class JsonGameHighScore; class JsonGameHighScore;
class JsonAddress; class JsonAddress;
class JsonOrderInfo; class JsonOrderInfo;
@ -780,6 +781,8 @@ class Client : public WebhookActor::Callback {
void add_update_chat_member(object_ptr<td_api::updateChatMember> &&update); void add_update_chat_member(object_ptr<td_api::updateChatMember> &&update);
void add_update_chat_join_request(object_ptr<td_api::updateNewChatJoinRequest> &&update);
// append only before Size // append only before Size
enum class UpdateType : int32 { enum class UpdateType : int32 {
Message, Message,
@ -797,6 +800,7 @@ class Client : public WebhookActor::Callback {
PollAnswer, PollAnswer,
MyChatMember, MyChatMember,
ChatMember, ChatMember,
ChatJoinRequest,
Size Size
}; };