mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2024-11-30 07:32:53 +01:00
Add "message_reaction" updates.
This commit is contained in:
parent
fa489a4979
commit
668ea399eb
@ -3571,6 +3571,41 @@ class Client::JsonGameHighScore final : public td::Jsonable {
|
||||
const Client *client_;
|
||||
};
|
||||
|
||||
class Client::JsonMessageReactionUpdated final : public td::Jsonable {
|
||||
public:
|
||||
JsonMessageReactionUpdated(const td_api::updateMessageReaction *update, const Client *client)
|
||||
: update_(update), client_(client) {
|
||||
}
|
||||
void store(td::JsonValueScope *scope) const {
|
||||
auto object = scope->enter_object();
|
||||
object("chat", JsonChat(update_->chat_id_, client_));
|
||||
object("message_id", as_client_message_id(update_->message_id_));
|
||||
switch (update_->actor_id_->get_id()) {
|
||||
case td_api::messageSenderUser::ID: {
|
||||
auto user_id = static_cast<const td_api::messageSenderUser *>(update_->actor_id_.get())->user_id_;
|
||||
object("user", JsonUser(user_id, client_));
|
||||
break;
|
||||
}
|
||||
case td_api::messageSenderChat::ID: {
|
||||
auto actor_chat_id = static_cast<const td_api::messageSenderChat *>(update_->actor_id_.get())->chat_id_;
|
||||
object("actor_chat", JsonChat(actor_chat_id, client_));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
object("date", update_->date_);
|
||||
object("old_reaction", td::json_array(update_->old_reaction_types_,
|
||||
[](const auto &reaction) { return JsonReactionType(reaction.get()); }));
|
||||
object("new_reaction", td::json_array(update_->new_reaction_types_,
|
||||
[](const auto &reaction) { return JsonReactionType(reaction.get()); }));
|
||||
}
|
||||
|
||||
private:
|
||||
const td_api::updateMessageReaction *update_;
|
||||
const Client *client_;
|
||||
};
|
||||
|
||||
class Client::JsonUpdateTypes final : public td::Jsonable {
|
||||
public:
|
||||
explicit JsonUpdateTypes(td::uint32 update_types) : update_types_(update_types) {
|
||||
@ -6837,6 +6872,9 @@ void Client::on_update(object_ptr<td_api::Object> result) {
|
||||
case td_api::updateChatBoost::ID:
|
||||
add_update_chat_boost(move_object_as<td_api::updateChatBoost>(result));
|
||||
break;
|
||||
case td_api::updateMessageReaction::ID:
|
||||
add_update_message_reaction(move_object_as<td_api::updateMessageReaction>(result));
|
||||
break;
|
||||
case td_api::updateConnectionState::ID: {
|
||||
auto update = move_object_as<td_api::updateConnectionState>(result);
|
||||
if (update->state_->get_id() == td_api::connectionStateReady::ID) {
|
||||
@ -13074,6 +13112,8 @@ td::Slice Client::get_update_type_name(UpdateType update_type) {
|
||||
return td::Slice("chat_boost");
|
||||
case UpdateType::ChatBoostRemoved:
|
||||
return td::Slice("removed_chat_boost");
|
||||
case UpdateType::MessageReaction:
|
||||
return td::Slice("message_reaction");
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return td::Slice();
|
||||
@ -13398,6 +13438,19 @@ void Client::add_update_chat_boost(object_ptr<td_api::updateChatBoost> &&update)
|
||||
}
|
||||
}
|
||||
|
||||
void Client::add_update_message_reaction(object_ptr<td_api::updateMessageReaction> &&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>(8) << 33);
|
||||
add_update(UpdateType::MessageReaction, JsonMessageReactionUpdated(update.get(), this), left_time,
|
||||
webhook_queue_id);
|
||||
} else {
|
||||
LOG(DEBUG) << "Skip updateMessageReaction with date " << update->date_ << ", because current date is "
|
||||
<< get_unix_time();
|
||||
}
|
||||
}
|
||||
|
||||
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_) {
|
||||
|
@ -173,6 +173,7 @@ class Client final : public WebhookActor::Callback {
|
||||
class JsonForumTopicEdited;
|
||||
class JsonForumTopicInfo;
|
||||
class JsonGameHighScore;
|
||||
class JsonMessageReactionUpdated;
|
||||
class JsonAddress;
|
||||
class JsonOrderInfo;
|
||||
class JsonSuccessfulPaymentBot;
|
||||
@ -1126,6 +1127,8 @@ class Client final : public WebhookActor::Callback {
|
||||
|
||||
void add_update_chat_boost(object_ptr<td_api::updateChatBoost> &&update);
|
||||
|
||||
void add_update_message_reaction(object_ptr<td_api::updateMessageReaction> &&update);
|
||||
|
||||
// append only before Size
|
||||
enum class UpdateType : int32 {
|
||||
Message,
|
||||
@ -1146,6 +1149,7 @@ class Client final : public WebhookActor::Callback {
|
||||
ChatJoinRequest,
|
||||
ChatBoostUpdated,
|
||||
ChatBoostRemoved,
|
||||
MessageReaction,
|
||||
Size
|
||||
};
|
||||
|
||||
@ -1175,9 +1179,10 @@ class Client final : public WebhookActor::Callback {
|
||||
|
||||
bool have_message_access(int64 chat_id) const;
|
||||
|
||||
// by default ChatMember updates are disabled
|
||||
static constexpr td::uint32 DEFAULT_ALLOWED_UPDATE_TYPES =
|
||||
(1 << static_cast<int32>(UpdateType::Size)) - 1 - (1 << static_cast<int32>(UpdateType::ChatMember));
|
||||
// by default ChatMember and MessageReaction updates are disabled
|
||||
static constexpr td::uint32 DEFAULT_ALLOWED_UPDATE_TYPES = (1 << static_cast<int32>(UpdateType::Size)) - 1 -
|
||||
(1 << static_cast<int32>(UpdateType::ChatMember)) -
|
||||
(1 << static_cast<int32>(UpdateType::MessageReaction));
|
||||
|
||||
object_ptr<td_api::AuthorizationState> authorization_state_;
|
||||
bool was_authorized_ = false;
|
||||
|
Loading…
Reference in New Issue
Block a user