From c24222546e52868605cd90693d004f3fb243cddd Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 26 Jun 2024 12:19:40 +0300 Subject: [PATCH] Improve names of get_input_media functions from MessageContent. --- td/telegram/BusinessConnectionManager.cpp | 18 ++++--- td/telegram/InlineMessageManager.cpp | 3 +- td/telegram/MessageContent.cpp | 59 ++++++++++++----------- td/telegram/MessageContent.h | 30 ++++++------ td/telegram/MessageImportManager.cpp | 2 +- td/telegram/MessagesManager.cpp | 22 +++++---- td/telegram/QuickReplyManager.cpp | 10 ++-- 7 files changed, 77 insertions(+), 67 deletions(-) diff --git a/td/telegram/BusinessConnectionManager.cpp b/td/telegram/BusinessConnectionManager.cpp index 64434a6bb..9b970c243 100644 --- a/td/telegram/BusinessConnectionManager.cpp +++ b/td/telegram/BusinessConnectionManager.cpp @@ -848,7 +848,8 @@ void BusinessConnectionManager::do_send_message(unique_ptr &&mes return; } - auto input_media = get_input_media(content, td_, message->ttl_, message->send_emoji_, td_->auth_manager_->is_bot()); + auto input_media = + get_message_content_input_media(content, td_, message->ttl_, message->send_emoji_, td_->auth_manager_->is_bot()); if (input_media != nullptr) { td_->create_handler(std::move(promise))->send(std::move(message), std::move(input_media)); return; @@ -1005,8 +1006,9 @@ void BusinessConnectionManager::do_upload_media(BeingUploadedMedia &&being_uploa << ", have_input_file = " << have_input_file << ", have_input_thumbnail = " << have_input_thumbnail; const auto *message = being_uploaded_media.message_.get(); - auto input_media = get_input_media(message->content_.get(), td_, std::move(input_file), std::move(input_thumbnail), - file_id, thumbnail_file_id, message->ttl_, message->send_emoji_, true); + auto input_media = + get_message_content_input_media(message->content_.get(), td_, std::move(input_file), std::move(input_thumbnail), + file_id, thumbnail_file_id, message->ttl_, message->send_emoji_, true); CHECK(input_media != nullptr); auto input_media_id = input_media->get_id(); if (input_media_id == telegram_api::inputMediaDocument::ID || input_media_id == telegram_api::inputMediaPhoto::ID) { @@ -1073,7 +1075,8 @@ void BusinessConnectionManager::complete_upload_media(unique_ptr update_message_content_file_id_remote(old_content.get(), get_message_content_any_file_id(new_content.get())); } - auto input_media = get_input_media(message->content_.get(), td_, message->ttl_, message->send_emoji_, true); + auto input_media = + get_message_content_input_media(message->content_.get(), td_, message->ttl_, message->send_emoji_, true); if (input_media == nullptr) { return promise.set_error(Status::Error(400, "Failed to upload file")); } @@ -1109,8 +1112,8 @@ void BusinessConnectionManager::send_message_album( auto message = create_business_message_to_send(business_connection_id, dialog_id, input_reply_to.clone(), disable_notification, protect_content, effect_id, nullptr, std::move(message_content)); - auto input_media = get_input_media(message->content_.get(), td_, message->ttl_, message->send_emoji_, - td_->auth_manager_->is_bot()); + auto input_media = get_message_content_input_media(message->content_.get(), td_, message->ttl_, + message->send_emoji_, td_->auth_manager_->is_bot()); if (input_media != nullptr) { auto file_id = get_message_file_id(message); CHECK(file_id.is_valid()); @@ -1303,7 +1306,8 @@ void BusinessConnectionManager::edit_business_message_media( TRY_RESULT_PROMISE(promise, new_reply_markup, get_reply_markup(std::move(reply_markup), td_->auth_manager_->is_bot(), true, false, true)); - auto input_media = get_input_media(content.content.get(), td_, MessageSelfDestructType(), string(), true); + auto input_media = + get_message_content_input_media(content.content.get(), td_, MessageSelfDestructType(), string(), true); if (input_media != nullptr) { auto file_id = get_message_content_any_file_id(content.content.get()); CHECK(file_id.is_valid()); diff --git a/td/telegram/InlineMessageManager.cpp b/td/telegram/InlineMessageManager.cpp index 8eb5851cf..cd87d2fc2 100644 --- a/td/telegram/InlineMessageManager.cpp +++ b/td/telegram/InlineMessageManager.cpp @@ -314,7 +314,8 @@ void InlineMessageManager::edit_inline_message_media( get_reply_markup(std::move(reply_markup), td_->auth_manager_->is_bot(), true, false, true)); TRY_RESULT_PROMISE(promise, input_bot_inline_message_id, get_input_bot_inline_message_id(inline_message_id)); - auto input_media = get_input_media(content.content.get(), td_, MessageSelfDestructType(), string(), true); + auto input_media = + get_message_content_input_media(content.content.get(), td_, MessageSelfDestructType(), string(), true); if (input_media == nullptr) { return promise.set_error(Status::Error(400, "Invalid message content specified")); } diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index f3f7318e3..051e5e934 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -3167,7 +3167,7 @@ Status check_message_group_message_contents(const vector &m return Status::OK(); } -bool can_have_input_media(const Td *td, const MessageContent *content, bool is_server) { +bool can_message_content_have_input_media(const Td *td, const MessageContent *content, bool is_server) { switch (content->get_type()) { case MessageContentType::Game: return is_server || static_cast(content)->game.has_input_media(); @@ -3260,9 +3260,9 @@ bool can_have_input_media(const Td *td, const MessageContent *content, bool is_s } } -SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td, - tl_object_ptr input_file, - BufferSlice thumbnail, int32 layer) { +SecretInputMedia get_message_content_secret_input_media( + const MessageContent *content, Td *td, telegram_api::object_ptr input_file, + BufferSlice thumbnail, int32 layer) { switch (content->get_type()) { case MessageContentType::Animation: { const auto *m = static_cast(content); @@ -3388,10 +3388,11 @@ SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td, return SecretInputMedia{}; } -static tl_object_ptr get_input_media_impl( - const MessageContent *content, Td *td, tl_object_ptr input_file, - tl_object_ptr input_thumbnail, MessageSelfDestructType ttl, const string &emoji) { - if (!can_have_input_media(td, content, false)) { +static telegram_api::object_ptr get_message_content_input_media_impl( + const MessageContent *content, Td *td, telegram_api::object_ptr input_file, + telegram_api::object_ptr input_thumbnail, MessageSelfDestructType ttl, + const string &emoji) { + if (!can_message_content_have_input_media(td, content, false)) { return nullptr; } switch (content->get_type()) { @@ -3544,14 +3545,14 @@ static tl_object_ptr get_input_media_impl( return nullptr; } -tl_object_ptr get_input_media(const MessageContent *content, Td *td, - tl_object_ptr input_file, - tl_object_ptr input_thumbnail, - FileId file_id, FileId thumbnail_file_id, - MessageSelfDestructType ttl, const string &emoji, bool force) { +telegram_api::object_ptr get_message_content_input_media( + const MessageContent *content, Td *td, telegram_api::object_ptr input_file, + telegram_api::object_ptr input_thumbnail, FileId file_id, FileId thumbnail_file_id, + MessageSelfDestructType ttl, const string &emoji, bool force) { bool had_input_file = input_file != nullptr; bool had_input_thumbnail = input_thumbnail != nullptr; - auto input_media = get_input_media_impl(content, td, std::move(input_file), std::move(input_thumbnail), ttl, emoji); + auto input_media = + get_message_content_input_media_impl(content, td, std::move(input_file), std::move(input_thumbnail), ttl, emoji); auto was_uploaded = FileManager::extract_was_uploaded(input_media); if (had_input_file) { if (!was_uploaded) { @@ -3582,9 +3583,10 @@ tl_object_ptr get_input_media(const MessageContent *co return input_media; } -tl_object_ptr get_input_media(const MessageContent *content, Td *td, - MessageSelfDestructType ttl, const string &emoji, bool force) { - auto input_media = get_input_media_impl(content, td, nullptr, nullptr, ttl, emoji); +telegram_api::object_ptr get_message_content_input_media(const MessageContent *content, + Td *td, MessageSelfDestructType ttl, + const string &emoji, bool force) { + auto input_media = get_message_content_input_media_impl(content, td, nullptr, nullptr, ttl, emoji); auto file_references = FileManager::extract_file_references(input_media); for (size_t i = 0; i < file_references.size(); i++) { if (file_references[i] == FileReferenceView::invalid_file_reference()) { @@ -3601,17 +3603,17 @@ tl_object_ptr get_input_media(const MessageContent *co return input_media; } -tl_object_ptr get_fake_input_media(Td *td, tl_object_ptr input_file, - FileId file_id) { +telegram_api::object_ptr get_message_content_fake_input_media( + Td *td, telegram_api::object_ptr input_file, FileId file_id) { FileView file_view = td->file_manager_->get_file_view(file_id); auto file_type = file_view.get_type(); if (is_document_file_type(file_type)) { - vector> attributes; + vector> attributes; auto file_path = file_view.suggested_path(); const PathView path_view(file_path); Slice file_name = path_view.file_name(); if (!file_name.empty()) { - attributes.push_back(make_tl_object(file_name.str())); + attributes.push_back(telegram_api::make_object(file_name.str())); } string mime_type = MimeType::from_extension(path_view.extension()); int32 flags = 0; @@ -3621,19 +3623,20 @@ tl_object_ptr get_fake_input_media(Td *td, tl_object_p if (file_type == FileType::DocumentAsFile) { flags |= telegram_api::inputMediaUploadedDocument::FORCE_FILE_MASK; } - return make_tl_object( + return telegram_api::make_object( flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, std::move(input_file), nullptr, mime_type, - std::move(attributes), vector>(), 0); + std::move(attributes), vector>(), 0); } else { CHECK(file_type == FileType::Photo || file_type == FileType::PhotoStory); int32 flags = 0; - return make_tl_object( - flags, false /*ignored*/, std::move(input_file), vector>(), 0); + return telegram_api::make_object( + flags, false /*ignored*/, std::move(input_file), + vector>(), 0); } } -tl_object_ptr get_message_content_input_media_web_page(const Td *td, - const MessageContent *content) { +telegram_api::object_ptr get_message_content_input_media_web_page( + const Td *td, const MessageContent *content) { CHECK(content != nullptr); if (content->get_type() != MessageContentType::Text) { return nullptr; @@ -6507,7 +6510,7 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const CHECK(type == MessageContentDupType::Copy || type == MessageContentDupType::ServerCopy); } if (type != MessageContentDupType::Forward && type != MessageContentDupType::SendViaBot && - !can_have_input_media(td, content, type == MessageContentDupType::ServerCopy)) { + !can_message_content_have_input_media(td, content, type == MessageContentDupType::ServerCopy)) { return nullptr; } diff --git a/td/telegram/MessageContent.h b/td/telegram/MessageContent.h index cf0f5c894..07e595889 100644 --- a/td/telegram/MessageContent.h +++ b/td/telegram/MessageContent.h @@ -121,26 +121,26 @@ Result get_input_message_content( Status check_message_group_message_contents(const vector &message_contents); -bool can_have_input_media(const Td *td, const MessageContent *content, bool is_server); +bool can_message_content_have_input_media(const Td *td, const MessageContent *content, bool is_server); -SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td, - tl_object_ptr input_file, - BufferSlice thumbnail, int32 layer); +SecretInputMedia get_message_content_secret_input_media( + const MessageContent *content, Td *td, telegram_api::object_ptr input_file, + BufferSlice thumbnail, int32 layer); -tl_object_ptr get_input_media(const MessageContent *content, Td *td, - tl_object_ptr input_file, - tl_object_ptr input_thumbnail, - FileId file_id, FileId thumbnail_file_id, - MessageSelfDestructType ttl, const string &emoji, bool force); +telegram_api::object_ptr get_message_content_input_media( + const MessageContent *content, Td *td, telegram_api::object_ptr input_file, + telegram_api::object_ptr input_thumbnail, FileId file_id, FileId thumbnail_file_id, + MessageSelfDestructType ttl, const string &emoji, bool force); -tl_object_ptr get_input_media(const MessageContent *content, Td *td, - MessageSelfDestructType ttl, const string &emoji, bool force); +telegram_api::object_ptr get_message_content_input_media(const MessageContent *content, + Td *td, MessageSelfDestructType ttl, + const string &emoji, bool force); -tl_object_ptr get_fake_input_media(Td *td, tl_object_ptr input_file, - FileId file_id); +telegram_api::object_ptr get_message_content_fake_input_media( + Td *td, telegram_api::object_ptr input_file, FileId file_id); -tl_object_ptr get_message_content_input_media_web_page(const Td *td, - const MessageContent *content); +telegram_api::object_ptr get_message_content_input_media_web_page( + const Td *td, const MessageContent *content); void delete_message_content_thumbnail(MessageContent *content, Td *td); diff --git a/td/telegram/MessageImportManager.cpp b/td/telegram/MessageImportManager.cpp index 9da56b60f..56f417793 100644 --- a/td/telegram/MessageImportManager.cpp +++ b/td/telegram/MessageImportManager.cpp @@ -519,7 +519,7 @@ void MessageImportManager::on_upload_imported_message_attachment(FileId file_id, const PathView path_view(suggested_path); td_->create_handler(std::move(promise)) ->send(dialog_id, import_id, path_view.file_name().str(), file_id, - get_fake_input_media(td_, std::move(input_file), file_id)); + get_message_content_fake_input_media(td_, std::move(input_file), file_id)); } void MessageImportManager::on_upload_imported_message_attachment_error(FileId file_id, Status status) { diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index a589b0405..591b1b6b2 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -8350,8 +8350,8 @@ void MessagesManager::do_send_media(DialogId dialog_id, const Message *m, FileId content = m->content.get(); } - auto input_media = get_input_media(content, td_, std::move(input_file), std::move(input_thumbnail), file_id, - thumbnail_file_id, m->ttl, m->send_emoji, true); + auto input_media = get_message_content_input_media(content, td_, std::move(input_file), std::move(input_thumbnail), + file_id, thumbnail_file_id, m->ttl, m->send_emoji, true); LOG_CHECK(input_media != nullptr) << to_string(get_message_object(dialog_id, m, "do_send_media")) << ' ' << have_input_file << ' ' << have_input_thumbnail << ' ' << file_id << ' ' << thumbnail_file_id << ' ' << m->ttl; @@ -8375,7 +8375,8 @@ void MessagesManager::do_send_secret_media(DialogId dialog_id, const Message *m, auto layer = td_->user_manager_->get_secret_chat_layer(dialog_id.get_secret_chat_id()); on_secret_message_media_uploaded( dialog_id, m, - get_secret_input_media(m->content.get(), td_, std::move(input_encrypted_file), std::move(thumbnail), layer), + get_message_content_secret_input_media(m->content.get(), td_, std::move(input_encrypted_file), + std::move(thumbnail), layer), file_id, thumbnail_file_id); } @@ -23981,7 +23982,7 @@ void MessagesManager::do_send_message(DialogId dialog_id, const Message *m, vect CHECK(!is_edit); auto layer = td_->user_manager_->get_secret_chat_layer(dialog_id.get_secret_chat_id()); - auto secret_input_media = get_secret_input_media(content, td_, nullptr, BufferSlice(), layer); + auto secret_input_media = get_message_content_secret_input_media(content, td_, nullptr, BufferSlice(), layer); if (secret_input_media.empty()) { LOG(INFO) << "Ask to upload encrypted file " << file_id; CHECK(file_id.is_valid()); @@ -23998,8 +23999,8 @@ void MessagesManager::do_send_message(DialogId dialog_id, const Message *m, vect on_secret_message_media_uploaded(dialog_id, m, std::move(secret_input_media), file_id, thumbnail_file_id); } } else { - auto input_media = - get_input_media(content, td_, m->ttl, m->send_emoji, td_->auth_manager_->is_bot() && bad_parts.empty()); + auto input_media = get_message_content_input_media(content, td_, m->ttl, m->send_emoji, + td_->auth_manager_->is_bot() && bad_parts.empty()); if (file_ids.size() > 1u) { // TODO PaidMedia return; @@ -24250,7 +24251,7 @@ void MessagesManager::on_upload_message_media_success(DialogId dialog_id, Messag on_message_changed(d, m, need_update, "on_upload_message_media_success"); } - auto input_media = get_input_media(m->content.get(), td_, m->ttl, m->send_emoji, true); + auto input_media = get_message_content_input_media(m->content.get(), td_, m->ttl, m->send_emoji, true); Status result; if (input_media == nullptr) { result = Status::Error(400, "Failed to upload file"); @@ -24426,7 +24427,7 @@ void MessagesManager::do_send_message_group(int64 media_album_id) { } const FormattedText *caption = get_message_content_caption(m->content.get()); - auto input_media = get_input_media(m->content.get(), td_, m->ttl, m->send_emoji, true); + auto input_media = get_message_content_input_media(m->content.get(), td_, m->ttl, m->send_emoji, true); if (input_media == nullptr) { // TODO return CHECK auto file_id = get_message_content_any_file_id(m->content.get()); @@ -24498,7 +24499,8 @@ void MessagesManager::on_text_message_ready_to_send(DialogId dialog_id, MessageI if (dialog_id.get_type() == DialogType::SecretChat) { CHECK(!message_id.is_scheduled()); auto layer = td_->user_manager_->get_secret_chat_layer(dialog_id.get_secret_chat_id()); - send_secret_message(dialog_id, m, get_secret_input_media(content, td_, nullptr, BufferSlice(), layer)); + send_secret_message(dialog_id, m, + get_message_content_secret_input_media(content, td_, nullptr, BufferSlice(), layer)); } else { const FormattedText *message_text = get_message_content_text(content); CHECK(message_text != nullptr); @@ -25047,7 +25049,7 @@ bool MessagesManager::can_resend_message(const Message *m) const { auto content_type = m->content->get_type(); if (m->via_bot_user_id.is_valid() || m->hide_via_bot) { // via bot message - if (!can_have_input_media(td_, m->content.get(), false)) { + if (!can_message_content_have_input_media(td_, m->content.get(), false)) { return false; } diff --git a/td/telegram/QuickReplyManager.cpp b/td/telegram/QuickReplyManager.cpp index 7d3c35000..13dd19f30 100644 --- a/td/telegram/QuickReplyManager.cpp +++ b/td/telegram/QuickReplyManager.cpp @@ -2194,7 +2194,7 @@ void QuickReplyManager::do_send_message(const QuickReplyMessage *m, vector FileId file_id = get_message_content_any_file_id(content); // any_file_id, because it could be a photo sent by ID FileId thumbnail_file_id = get_message_content_thumbnail_file_id(content, td_); LOG(DEBUG) << "Need to send file " << file_id << " with thumbnail " << thumbnail_file_id; - auto input_media = get_input_media(content, td_, {}, m->send_emoji, false); + auto input_media = get_message_content_input_media(content, td_, {}, m->send_emoji, false); if (input_media == nullptr) { if (content_type == MessageContentType::Game || content_type == MessageContentType::Story) { return; @@ -2285,8 +2285,8 @@ void QuickReplyManager::do_send_media(const QuickReplyMessage *m, FileId file_id auto content = m->message_id.is_server() ? m->edited_content.get() : m->content.get(); CHECK(content != nullptr); - auto input_media = get_input_media(content, td_, std::move(input_file), std::move(input_thumbnail), file_id, - thumbnail_file_id, {}, m->send_emoji, true); + auto input_media = get_message_content_input_media(content, td_, std::move(input_file), std::move(input_thumbnail), + file_id, thumbnail_file_id, {}, m->send_emoji, true); CHECK(input_media != nullptr); on_message_media_uploaded(m, std::move(input_media), file_id, thumbnail_file_id); @@ -2417,7 +2417,7 @@ void QuickReplyManager::on_upload_message_media_success(QuickReplyShortcutId sho save_quick_reply_shortcuts(); - auto input_media = get_input_media(content.get(), td_, {}, m->send_emoji, true); + auto input_media = get_message_content_input_media(content.get(), td_, {}, m->send_emoji, true); Status result; if (input_media == nullptr) { result = Status::Error(400, "Failed to upload file"); @@ -2515,7 +2515,7 @@ void QuickReplyManager::do_send_message_group(QuickReplyShortcutId shortcut_id, << " and is_finished = " << static_cast(request.is_finished[i]); const FormattedText *caption = get_message_content_caption(m->content.get()); - auto input_media = get_input_media(m->content.get(), td_, {}, m->send_emoji, true); + auto input_media = get_message_content_input_media(m->content.get(), td_, {}, m->send_emoji, true); CHECK(input_media != nullptr); auto entities = get_input_message_entities(td_->user_manager_.get(), caption, "do_send_message_group"); int32 input_single_media_flags = 0;