From 00d351c85c55addaa5c4ea289ddb9c2fcbde009a Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 13 Nov 2023 22:08:07 +0300 Subject: [PATCH] Add message.link_preview_options. --- telegram-bot-api/Client.cpp | 32 ++++++++++++++++++++++++++++++++ telegram-bot-api/Client.h | 1 + 2 files changed, 33 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index c8cc11a..462d2f7 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -939,6 +939,35 @@ class Client::JsonMessages final : public td::Jsonable { const td::vector &messages_; }; +class Client::JsonLinkPreviewOptions final : public td::Jsonable { + public: + JsonLinkPreviewOptions(const td_api::linkPreviewOptions *link_preview_options, const Client *client) + : link_preview_options_(link_preview_options), client_(client) { + } + void store(td::JsonValueScope *scope) const { + auto object = scope->enter_object(); + if (link_preview_options_->is_disabled_) { + object("is_disabled", td::JsonTrue()); + } + if (!link_preview_options_->url_.empty()) { + object("url", link_preview_options_->url_); + } + if (link_preview_options_->force_small_media_) { + object("prefer_small_media", td::JsonTrue()); + } + if (link_preview_options_->force_large_media_) { + object("prefer_large_media", td::JsonTrue()); + } + if (link_preview_options_->show_above_text_) { + object("show_above_text", td::JsonTrue()); + } + } + + private: + const td_api::linkPreviewOptions *link_preview_options_; + const Client *client_; +}; + class Client::JsonAnimation final : public td::Jsonable { public: JsonAnimation(const td_api::animation *animation, bool as_document, const Client *client) @@ -2052,6 +2081,9 @@ void Client::JsonMessage::store(td::JsonValueScope *scope) const { if (!content->text_->entities_.empty()) { object("entities", JsonVectorEntities(content->text_->entities_, client_)); } + if (content->link_preview_options_ != nullptr) { + object("link_preview_options", JsonLinkPreviewOptions(content->link_preview_options_.get(), client_)); + } break; } case td_api::messageAnimation::ID: { diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 073c8d4..28152ef 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 JsonLinkPreviewOptions; class JsonAnimation; class JsonAudio; class JsonDocument;