mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2024-11-27 06:26:50 +01:00
Add "chat_join_request" updates.
This commit is contained in:
parent
2fa32d7db7
commit
c9a2a62248
@ -2354,6 +2354,29 @@ class Client::JsonChatMemberUpdated : public Jsonable {
|
||||
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 {
|
||||
public:
|
||||
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:
|
||||
add_update_chat_member(move_object_as<td_api::updateChatMember>(result));
|
||||
break;
|
||||
case td_api::updateNewChatJoinRequest::ID:
|
||||
add_update_chat_join_request(move_object_as<td_api::updateNewChatJoinRequest>(result));
|
||||
break;
|
||||
default:
|
||||
// we are not interested in this update
|
||||
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"));
|
||||
|
||||
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) {
|
||||
send_request(make_object<td_api::createChatInviteLink>(chat_id, name, expire_date, member_limit, creates_join_request),
|
||||
[this, name = name.str(), expire_date, member_limit, creates_join_request](int64 chat_id,
|
||||
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)));
|
||||
});
|
||||
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"));
|
||||
|
||||
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) {
|
||||
send_request(make_object<td_api::editChatInviteLink>(chat_id, invite_link, name, expire_date, member_limit, creates_join_request),
|
||||
[this, invite_link = invite_link.str(), name = name.str(), expire_date, member_limit,
|
||||
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)));
|
||||
});
|
||||
return Status::OK();
|
||||
@ -8548,6 +8578,8 @@ Client::Slice Client::get_update_type_name(UpdateType update_type) {
|
||||
return Slice("my_chat_member");
|
||||
case UpdateType::ChatMember:
|
||||
return Slice("chat_member");
|
||||
case UpdateType::ChatJoinRequest:
|
||||
return Slice("chat_join_request");
|
||||
default:
|
||||
UNREACHABLE();
|
||||
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 {
|
||||
CHECK(message_add_members != nullptr);
|
||||
for (auto &member_user_id : message_add_members->member_user_ids_) {
|
||||
|
@ -139,6 +139,7 @@ class Client : public WebhookActor::Callback {
|
||||
class JsonChatMember;
|
||||
class JsonChatMembers;
|
||||
class JsonChatMemberUpdated;
|
||||
class JsonChatJoinRequest;
|
||||
class JsonGameHighScore;
|
||||
class JsonAddress;
|
||||
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_join_request(object_ptr<td_api::updateNewChatJoinRequest> &&update);
|
||||
|
||||
// append only before Size
|
||||
enum class UpdateType : int32 {
|
||||
Message,
|
||||
@ -797,6 +800,7 @@ class Client : public WebhookActor::Callback {
|
||||
PollAnswer,
|
||||
MyChatMember,
|
||||
ChatMember,
|
||||
ChatJoinRequest,
|
||||
Size
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user