mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2024-12-29 05:35:48 +01:00
Add "message_reaction_count" update.
This commit is contained in:
parent
82e48a0908
commit
56d2dc6392
@ -612,6 +612,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) {
|
||||
@ -3467,6 +3481,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) {
|
||||
@ -6169,6 +6202,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) {
|
||||
@ -11715,6 +11751,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();
|
||||
@ -12052,6 +12090,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_) {
|
||||
|
@ -92,6 +92,7 @@ class Client final : public WebhookActor::Callback {
|
||||
class JsonUser;
|
||||
class JsonUsers;
|
||||
class JsonReactionType;
|
||||
class JsonReactionCount;
|
||||
class JsonChatPermissions;
|
||||
class JsonChatPhotoInfo;
|
||||
class JsonChatLocation;
|
||||
@ -161,6 +162,7 @@ class Client final : public WebhookActor::Callback {
|
||||
class JsonForumTopicInfo;
|
||||
class JsonGameHighScore;
|
||||
class JsonMessageReactionUpdated;
|
||||
class JsonMessageReactionCountUpdated;
|
||||
class JsonAddress;
|
||||
class JsonOrderInfo;
|
||||
class JsonSuccessfulPaymentBot;
|
||||
@ -1000,6 +1002,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,
|
||||
@ -1021,6 +1025,7 @@ class Client final : public WebhookActor::Callback {
|
||||
ChatBoostUpdated,
|
||||
ChatBoostRemoved,
|
||||
MessageReaction,
|
||||
MessageReactionCount,
|
||||
Size
|
||||
};
|
||||
|
||||
@ -1050,10 +1055,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;
|
||||
|
Loading…
Reference in New Issue
Block a user