From c729e35ddbd9216dc79d21adf1ec2df21be565f0 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 13 Nov 2023 23:17:15 +0300 Subject: [PATCH] Add Message.forward_origin. --- telegram-bot-api/Client.cpp | 61 +++++++++++++++++++++++++++++++++++-- telegram-bot-api/Client.h | 1 + 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index bfbf7b2..73fc578 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -924,6 +924,59 @@ class Client::JsonMessageSender final : public td::Jsonable { const Client *client_; }; +class Client::JsonMessageOrigin final : public td::Jsonable { + public: + JsonMessageOrigin(const td_api::MessageOrigin *message_origin, int32 initial_send_date, const Client *client) + : message_origin_(message_origin), initial_send_date_(initial_send_date), client_(client) { + } + void store(td::JsonValueScope *scope) const { + auto object = scope->enter_object(); + switch (message_origin_->get_id()) { + case td_api::messageOriginUser::ID: { + auto origin = static_cast(message_origin_); + object("type", "user"); + object("sender_user", JsonUser(origin->sender_user_id_, client_)); + break; + } + case td_api::messageOriginChat::ID: { + auto origin = static_cast(message_origin_); + object("type", "chat"); + object("sender_chat", JsonChat(origin->sender_chat_id_, false, client_)); + if (!origin->author_signature_.empty()) { + object("author_signature", origin->author_signature_); + } + break; + } + case td_api::messageOriginHiddenUser::ID: { + auto origin = static_cast(message_origin_); + object("type", "hidden_user"); + if (!origin->sender_name_.empty()) { + object("sender_user_name", origin->sender_name_); + } + break; + } + case td_api::messageOriginChannel::ID: { + auto origin = static_cast(message_origin_); + object("type", "channel"); + object("chat", JsonChat(origin->chat_id_, false, client_)); + object("message_id", as_client_message_id(origin->message_id_)); + if (!origin->author_signature_.empty()) { + object("author_signature", origin->author_signature_); + } + break; + } + default: + UNREACHABLE(); + } + object("date", initial_send_date_); + } + + private: + const td_api::MessageOrigin *message_origin_; + int32 initial_send_date_; + const Client *client_; +}; + class Client::JsonMessages final : public td::Jsonable { public: explicit JsonMessages(const td::vector &messages) : messages_(messages) { @@ -2033,6 +2086,11 @@ void Client::JsonMessage::store(td::JsonValueScope *scope) const { } if (message_->initial_send_date > 0) { CHECK(message_->forward_origin != nullptr); + object("forward_origin", JsonMessageOrigin(message_->forward_origin.get(), message_->initial_send_date, client_)); + if (message_->is_automatic_forward) { + object("is_automatic_forward", td::JsonTrue()); + } + switch (message_->forward_origin->get_id()) { case td_api::messageOriginUser::ID: { auto forward_info = static_cast(message_->forward_origin.get()); @@ -2066,9 +2124,6 @@ void Client::JsonMessage::store(td::JsonValueScope *scope) const { default: UNREACHABLE(); } - if (message_->is_automatic_forward) { - object("is_automatic_forward", td::JsonTrue()); - } object("forward_date", message_->initial_send_date); } if (need_reply_) { diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 6abddec..7850e36 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -97,6 +97,7 @@ class Client final : public WebhookActor::Callback { class JsonChatInviteLink; class JsonChat; class JsonMessageSender; + class JsonMessageOrigin; class JsonLinkPreviewOptions; class JsonAnimation; class JsonAudio;