Use messages.sendMedia to send text messages with custom URLs.

This commit is contained in:
levlam 2023-10-16 20:41:39 +03:00
parent d16fc8294c
commit b9e7c8d7da
5 changed files with 54 additions and 7 deletions

View File

@ -3001,6 +3001,31 @@ tl_object_ptr<telegram_api::InputMedia> get_fake_input_media(Td *td, tl_object_p
}
}
tl_object_ptr<telegram_api::InputMedia> get_message_content_input_media_web_page(const Td *td,
const MessageContent *content) {
CHECK(content != nullptr);
if (content->get_type() != MessageContentType::Text) {
return nullptr;
}
auto *text = static_cast<const MessageText *>(content);
if (!text->is_manual && !text->force_small_media && !text->force_large_media) {
return nullptr;
}
int32 flags = 0;
if (text->force_small_media) {
flags |= telegram_api::inputMediaWebPage::FORCE_SMALL_MEDIA_MASK;
}
if (text->force_large_media) {
flags |= telegram_api::inputMediaWebPage::FORCE_LARGE_MEDIA_MASK;
}
if (!text->text.text.empty()) {
flags |= telegram_api::inputMediaWebPage::OPTIONAL_MASK;
}
return telegram_api::make_object<telegram_api::inputMediaWebPage>(
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/,
td->web_pages_manager_->get_web_page_url(text->web_page_id));
}
void delete_message_content_thumbnail(MessageContent *content, Td *td) {
switch (content->get_type()) {
case MessageContentType::Animation: {

View File

@ -125,6 +125,9 @@ tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *co
tl_object_ptr<telegram_api::InputMedia> get_fake_input_media(Td *td, tl_object_ptr<telegram_api::InputFile> input_file,
FileId file_id);
tl_object_ptr<telegram_api::InputMedia> get_message_content_input_media_web_page(const Td *td,
const MessageContent *content);
void delete_message_content_thumbnail(MessageContent *content, Td *td);
Status can_send_message_content(DialogId dialog_id, const MessageContent *content, bool is_forward, const Td *td);

View File

@ -25743,14 +25743,23 @@ void MessagesManager::on_text_message_ready_to_send(DialogId dialog_id, MessageI
} else {
const FormattedText *message_text = get_message_content_text(content);
CHECK(message_text != nullptr);
int64 random_id = begin_send_message(dialog_id, m);
td_->create_handler<SendMessageQuery>()->send(
get_message_flags(m), dialog_id, get_send_message_as_input_peer(m), get_message_input_reply_to(m),
m->top_thread_message_id, get_message_schedule_date(m),
get_input_reply_markup(td_->contacts_manager_.get(), m->reply_markup),
get_input_message_entities(td_->contacts_manager_.get(), message_text->entities, "do_send_message"),
message_text->text, m->is_copy, random_id, &m->send_query_ref);
auto input_media = get_message_content_input_media_web_page(td_, m->content.get());
if (input_media == nullptr) {
td_->create_handler<SendMessageQuery>()->send(
get_message_flags(m), dialog_id, get_send_message_as_input_peer(m), get_message_input_reply_to(m),
m->top_thread_message_id, get_message_schedule_date(m),
get_input_reply_markup(td_->contacts_manager_.get(), m->reply_markup),
get_input_message_entities(td_->contacts_manager_.get(), message_text, "do_send_message"), message_text->text,
m->is_copy, random_id, &m->send_query_ref);
} else {
td_->create_handler<SendMediaQuery>()->send(
FileId(), FileId(), get_message_flags(m), dialog_id, get_send_message_as_input_peer(m),
get_message_input_reply_to(m), m->top_thread_message_id, get_message_schedule_date(m),
get_input_reply_markup(td_->contacts_manager_.get(), m->reply_markup),
get_input_message_entities(td_->contacts_manager_.get(), message_text, "do_send_message"), message_text->text,
std::move(input_media), MessageContentType::Text, m->is_copy, random_id, &m->send_query_ref);
}
}
}

View File

@ -1097,6 +1097,14 @@ void WebPagesManager::update_web_page_instant_view_load_requests(WebPageId web_p
}
}
string WebPagesManager::get_web_page_url(WebPageId web_page_id) const {
const WebPage *web_page = get_web_page(web_page_id);
if (web_page != nullptr) {
return web_page->url_;
}
return string();
}
WebPageId WebPagesManager::get_web_page_by_url(const string &url) const {
if (url.empty()) {
return WebPageId();

View File

@ -72,6 +72,8 @@ class WebPagesManager final : public Actor {
void get_web_page_instant_view(const string &url, bool force_full, Promise<WebPageId> &&promise);
string get_web_page_url(WebPageId web_page_id) const;
WebPageId get_web_page_by_url(const string &url) const;
void get_web_page_by_url(const string &url, Promise<WebPageId> &&promise);