Add "message_reaction_count" update.

This commit is contained in:
levlam 2023-12-20 17:45:26 +03:00 committed by David Guillen Fandos
parent 668ea399eb
commit 50bb07bc46
2 changed files with 61 additions and 4 deletions

View File

@ -680,6 +680,20 @@ class Client::JsonReactionType final : public td::Jsonable {
const td_api::ReactionType *reaction_type_;
};
class Client::JsonReactionCount final : public td::Jsonable {
public:
explicit JsonReactionCount(const td_api::messageReaction *message_reaction) : message_reaction_(message_reaction) {
}
void store(td::JsonValueScope *scope) const {
auto object = scope->enter_object();
object("type", JsonReactionType(message_reaction_->type_.get()));
object("total_count", message_reaction_->total_count_);
}
private:
const td_api::messageReaction *message_reaction_;
};
class Client::JsonChatPermissions final : public td::Jsonable {
public:
explicit JsonChatPermissions(const td_api::chatPermissions *chat_permissions) : chat_permissions_(chat_permissions) {
@ -3606,6 +3620,25 @@ class Client::JsonMessageReactionUpdated final : public td::Jsonable {
const Client *client_;
};
class Client::JsonMessageReactionCountUpdated final : public td::Jsonable {
public:
JsonMessageReactionCountUpdated(const td_api::updateMessageReactions *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_));
object("date", update_->date_);
object("reactions",
td::json_array(update_->reactions_, [](const auto &reaction) { return JsonReactionCount(reaction.get()); }));
}
private:
const td_api::updateMessageReactions *update_;
const Client *client_;
};
class Client::JsonUpdateTypes final : public td::Jsonable {
public:
explicit JsonUpdateTypes(td::uint32 update_types) : update_types_(update_types) {
@ -6875,6 +6908,9 @@ void Client::on_update(object_ptr<td_api::Object> result) {
case td_api::updateMessageReaction::ID:
add_update_message_reaction(move_object_as<td_api::updateMessageReaction>(result));
break;
case td_api::updateMessageReactions::ID:
add_update_message_reaction_count(move_object_as<td_api::updateMessageReactions>(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) {
@ -13114,6 +13150,8 @@ td::Slice Client::get_update_type_name(UpdateType update_type) {
return td::Slice("removed_chat_boost");
case UpdateType::MessageReaction:
return td::Slice("message_reaction");
case UpdateType::MessageReactionCount:
return td::Slice("message_reaction_count");
default:
UNREACHABLE();
return td::Slice();
@ -13451,6 +13489,19 @@ void Client::add_update_message_reaction(object_ptr<td_api::updateMessageReactio
}
}
void Client::add_update_message_reaction_count(object_ptr<td_api::updateMessageReactions> &&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>(9) << 33);
add_update(UpdateType::MessageReactionCount, JsonMessageReactionCountUpdated(update.get(), this), left_time,
webhook_queue_id);
} else {
LOG(DEBUG) << "Skip updateMessageReactions 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

@ -105,6 +105,7 @@ class Client final : public WebhookActor::Callback {
class JsonUser;
class JsonUsers;
class JsonReactionType;
class JsonReactionCount;
class JsonChatPermissions;
class JsonChatPhotoInfo;
class JsonChatLocation;
@ -174,6 +175,7 @@ class Client final : public WebhookActor::Callback {
class JsonForumTopicInfo;
class JsonGameHighScore;
class JsonMessageReactionUpdated;
class JsonMessageReactionCountUpdated;
class JsonAddress;
class JsonOrderInfo;
class JsonSuccessfulPaymentBot;
@ -1129,6 +1131,8 @@ class Client final : public WebhookActor::Callback {
void add_update_message_reaction(object_ptr<td_api::updateMessageReaction> &&update);
void add_update_message_reaction_count(object_ptr<td_api::updateMessageReactions> &&update);
// append only before Size
enum class UpdateType : int32 {
Message,
@ -1150,6 +1154,7 @@ class Client final : public WebhookActor::Callback {
ChatBoostUpdated,
ChatBoostRemoved,
MessageReaction,
MessageReactionCount,
Size
};
@ -1179,10 +1184,11 @@ class Client final : public WebhookActor::Callback {
bool have_message_access(int64 chat_id) const;
// 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));
// by default ChatMember, MessageReaction, and MessageReactionCount 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)) -
(1 << static_cast<int32>(UpdateType::MessageReactionCount));
object_ptr<td_api::AuthorizationState> authorization_state_;
bool was_authorized_ = false;