Add "message_reaction" updates.

This commit is contained in:
levlam 2023-12-20 17:35:18 +03:00
parent 1320b03bc5
commit 82e48a0908
2 changed files with 61 additions and 3 deletions

View File

@ -3432,6 +3432,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) {
@ -6131,6 +6166,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) {
@ -11675,6 +11713,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();
@ -11999,6 +12039,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_) {

View File

@ -160,6 +160,7 @@ class Client final : public WebhookActor::Callback {
class JsonForumTopicEdited;
class JsonForumTopicInfo;
class JsonGameHighScore;
class JsonMessageReactionUpdated;
class JsonAddress;
class JsonOrderInfo;
class JsonSuccessfulPaymentBot;
@ -997,6 +998,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,
@ -1017,6 +1020,7 @@ class Client final : public WebhookActor::Callback {
ChatJoinRequest,
ChatBoostUpdated,
ChatBoostRemoved,
MessageReaction,
Size
};
@ -1046,9 +1050,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;