mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2024-11-23 20:26:50 +01:00
Add update 'chat_member'.
This commit is contained in:
parent
8323701b27
commit
418946b0e1
@ -2266,6 +2266,29 @@ class Client::JsonChatMembers : public Jsonable {
|
||||
const Client *client_;
|
||||
};
|
||||
|
||||
class Client::JsonChatMemberUpdated : public Jsonable {
|
||||
public:
|
||||
JsonChatMemberUpdated(const td_api::updateChatMember *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("actor", JsonUser(update_->actor_user_id_, client_));
|
||||
object("date", update_->date_);
|
||||
auto chat_type = client_->get_chat_type(update_->chat_id_);
|
||||
object("old_chat_member", JsonChatMember(update_->old_chat_member_.get(), chat_type, client_));
|
||||
object("new_chat_member", JsonChatMember(update_->new_chat_member_.get(), chat_type, client_));
|
||||
if (update_->invite_link_ != nullptr) {
|
||||
object("invite_link", JsonChatInviteLink(update_->invite_link_.get(), client_));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const td_api::updateChatMember *update_;
|
||||
const Client *client_;
|
||||
};
|
||||
|
||||
class Client::JsonGameHighScore : public Jsonable {
|
||||
public:
|
||||
JsonGameHighScore(const td_api::gameHighScore *score, const Client *client) : score_(score), client_(client) {
|
||||
@ -4313,6 +4336,9 @@ void Client::on_update(object_ptr<td_api::Object> result) {
|
||||
case td_api::updateNewCustomQuery::ID:
|
||||
add_new_custom_query(move_object_as<td_api::updateNewCustomQuery>(result));
|
||||
break;
|
||||
case td_api::updateChatMember::ID:
|
||||
add_update_chat_member(move_object_as<td_api::updateChatMember>(result));
|
||||
break;
|
||||
default:
|
||||
// we are not interested in this updates
|
||||
break;
|
||||
@ -8227,6 +8253,8 @@ Client::Slice Client::get_update_type_name(UpdateType update_type) {
|
||||
return Slice("poll");
|
||||
case UpdateType::PollAnswer:
|
||||
return Slice("poll_answer");
|
||||
case UpdateType::ChatMember:
|
||||
return Slice("chat_member");
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return Slice();
|
||||
@ -8498,6 +8526,15 @@ void Client::add_new_custom_query(object_ptr<td_api::updateNewCustomQuery> &&que
|
||||
add_update(UpdateType::CustomQuery, JsonCustomJson(query->data_), timeout, 0);
|
||||
}
|
||||
|
||||
void Client::add_update_chat_member(object_ptr<td_api::updateChatMember> &&update) {
|
||||
CHECK(update != nullptr);
|
||||
auto left_time = update->date_ + 86400 - get_unix_time();
|
||||
if (left_time > 0) {
|
||||
auto webhook_queue_id = update->chat_id_ + (static_cast<int64>(5) << 33);
|
||||
add_update(UpdateType::ChatMember, JsonChatMemberUpdated(update.get(), this), left_time, webhook_queue_id);
|
||||
}
|
||||
}
|
||||
|
||||
td::int32 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_) {
|
||||
|
@ -136,6 +136,7 @@ class Client : public WebhookActor::Callback {
|
||||
class JsonChatPhotos;
|
||||
class JsonChatMember;
|
||||
class JsonChatMembers;
|
||||
class JsonChatMemberUpdated;
|
||||
class JsonGameHighScore;
|
||||
class JsonAddress;
|
||||
class JsonOrderInfo;
|
||||
@ -750,6 +751,8 @@ class Client : public WebhookActor::Callback {
|
||||
|
||||
void add_new_custom_query(object_ptr<td_api::updateNewCustomQuery> &&query);
|
||||
|
||||
void add_update_chat_member(object_ptr<td_api::updateChatMember> &&update);
|
||||
|
||||
// append only before Size
|
||||
enum class UpdateType : int32 {
|
||||
Message,
|
||||
@ -765,6 +768,7 @@ class Client : public WebhookActor::Callback {
|
||||
PreCheckoutQuery,
|
||||
Poll,
|
||||
PollAnswer,
|
||||
ChatMember,
|
||||
Size
|
||||
};
|
||||
|
||||
@ -792,8 +796,8 @@ class Client : public WebhookActor::Callback {
|
||||
|
||||
bool have_message_access(int64 chat_id) const;
|
||||
|
||||
// by default all 13 update types up to PollAnswer are allowed
|
||||
static constexpr td::uint32 DEFAULT_ALLOWED_UPDATE_TYPES = ((1 << 13) - 1);
|
||||
// by default all 14 update types up to ChatMember are allowed
|
||||
static constexpr td::uint32 DEFAULT_ALLOWED_UPDATE_TYPES = ((1 << 14) - 1);
|
||||
|
||||
object_ptr<td_api::AuthorizationState> authorization_state_;
|
||||
bool was_authorized_ = false;
|
||||
|
Loading…
Reference in New Issue
Block a user