From aaff89a6c30cf0457b42479022ca58f009527635 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 28 Aug 2021 14:16:29 +0300 Subject: [PATCH] Make get_document_object methods const. --- td/telegram/AnimationsManager.cpp | 9 +++++---- td/telegram/AnimationsManager.h | 2 +- td/telegram/AudiosManager.cpp | 6 ++++-- td/telegram/AudiosManager.h | 2 +- td/telegram/DocumentsManager.cpp | 10 ++++++---- td/telegram/DocumentsManager.h | 2 +- td/telegram/Game.cpp | 7 +++---- td/telegram/InlineQueriesManager.cpp | 6 ++---- td/telegram/MessageContent.cpp | 2 +- td/telegram/NotificationType.cpp | 2 +- td/telegram/Td.cpp | 2 +- td/telegram/VideoNotesManager.cpp | 7 ++++--- td/telegram/VideoNotesManager.h | 2 +- td/telegram/VideosManager.cpp | 6 ++++-- td/telegram/VideosManager.h | 2 +- td/telegram/VoiceNotesManager.cpp | 6 ++++-- td/telegram/VoiceNotesManager.h | 2 +- td/telegram/WebPageBlock.cpp | 2 +- td/telegram/WebPagesManager.cpp | 2 +- 19 files changed, 43 insertions(+), 36 deletions(-) diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index f5ba25b51..5afdc1d31 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -150,14 +150,15 @@ int32 AnimationsManager::get_animation_duration(FileId file_id) const { return it->second->duration; } -tl_object_ptr AnimationsManager::get_animation_object(FileId file_id, const char *source) { +tl_object_ptr AnimationsManager::get_animation_object(FileId file_id) const { if (!file_id.is_valid()) { return nullptr; } - auto &animation = animations_[file_id]; - LOG_CHECK(animation != nullptr) << source << " " << file_id << " " - << static_cast(td_->file_manager_->get_file_view(file_id).get_type()); + auto it = animations_.find(file_id); + CHECK(it != animations_.end()); + auto animation = it->second.get(); + CHECK(animation != nullptr); auto thumbnail = animation->animated_thumbnail.file_id.is_valid() ? get_thumbnail_object(td_->file_manager_.get(), animation->animated_thumbnail, PhotoFormat::Mpeg4) diff --git a/td/telegram/AnimationsManager.h b/td/telegram/AnimationsManager.h index 56e444040..db6775b10 100644 --- a/td/telegram/AnimationsManager.h +++ b/td/telegram/AnimationsManager.h @@ -33,7 +33,7 @@ class AnimationsManager final : public Actor { int32 get_animation_duration(FileId file_id) const; - tl_object_ptr get_animation_object(FileId file_id, const char *source); + tl_object_ptr get_animation_object(FileId file_id) const; void create_animation(FileId file_id, string minithumbnail, PhotoSize thumbnail, AnimationSize animated_thumbnail, bool has_stickers, vector &&sticker_file_ids, string file_name, string mime_type, diff --git a/td/telegram/AudiosManager.cpp b/td/telegram/AudiosManager.cpp index 8912eeea2..b9f13cee0 100644 --- a/td/telegram/AudiosManager.cpp +++ b/td/telegram/AudiosManager.cpp @@ -29,12 +29,14 @@ int32 AudiosManager::get_audio_duration(FileId file_id) const { return it->second->duration; } -tl_object_ptr AudiosManager::get_audio_object(FileId file_id) { +tl_object_ptr AudiosManager::get_audio_object(FileId file_id) const { if (!file_id.is_valid()) { return nullptr; } - auto &audio = audios_[file_id]; + auto it = audios_.find(file_id); + CHECK(it != audios_.end()); + auto audio = it->second.get(); CHECK(audio != nullptr); return make_tl_object( audio->duration, audio->title, audio->performer, audio->file_name, audio->mime_type, diff --git a/td/telegram/AudiosManager.h b/td/telegram/AudiosManager.h index 6df7c23ba..84c34fa06 100644 --- a/td/telegram/AudiosManager.h +++ b/td/telegram/AudiosManager.h @@ -28,7 +28,7 @@ class AudiosManager { int32 get_audio_duration(FileId file_id) const; - tl_object_ptr get_audio_object(FileId file_id); + tl_object_ptr get_audio_object(FileId file_id) const; void create_audio(FileId file_id, string minithumbnail, PhotoSize thumbnail, string file_name, string mime_type, int32 duration, string title, string performer, bool replace); diff --git a/td/telegram/DocumentsManager.cpp b/td/telegram/DocumentsManager.cpp index fecc3dd9f..d2809e191 100644 --- a/td/telegram/DocumentsManager.cpp +++ b/td/telegram/DocumentsManager.cpp @@ -47,14 +47,16 @@ namespace td { DocumentsManager::DocumentsManager(Td *td) : td_(td) { } -tl_object_ptr DocumentsManager::get_document_object(FileId file_id, PhotoFormat thumbnail_format) { +tl_object_ptr DocumentsManager::get_document_object(FileId file_id, + PhotoFormat thumbnail_format) const { if (!file_id.is_valid()) { return nullptr; } - LOG(INFO) << "Return document " << file_id << " object"; - auto &document = documents_[file_id]; - LOG_CHECK(document != nullptr) << tag("file_id", file_id); + auto it = documents_.find(file_id); + CHECK(it != documents_.end()); + auto document = it->second.get(); + CHECK(document != nullptr); return make_tl_object( document->file_name, document->mime_type, get_minithumbnail_object(document->minithumbnail), get_thumbnail_object(td_->file_manager_.get(), document->thumbnail, thumbnail_format), diff --git a/td/telegram/DocumentsManager.h b/td/telegram/DocumentsManager.h index fbf9e5870..0b4ac96e1 100644 --- a/td/telegram/DocumentsManager.h +++ b/td/telegram/DocumentsManager.h @@ -75,7 +75,7 @@ class DocumentsManager { } }; - tl_object_ptr get_document_object(FileId file_id, PhotoFormat thumbnail_format); + tl_object_ptr get_document_object(FileId file_id, PhotoFormat thumbnail_format) const; Document on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id, MultiPromiseActor *load_data_multipromise_ptr = nullptr, diff --git a/td/telegram/Game.cpp b/td/telegram/Game.cpp index 5a954f5fa..7775f7c0e 100644 --- a/td/telegram/Game.cpp +++ b/td/telegram/Game.cpp @@ -92,10 +92,9 @@ const FormattedText &Game::get_text() const { } tl_object_ptr Game::get_game_object(Td *td, bool skip_bot_commands) const { - return make_tl_object( - id_, short_name_, title_, get_formatted_text_object(text_, skip_bot_commands, -1), description_, - get_photo_object(td->file_manager_.get(), photo_), - td->animations_manager_->get_animation_object(animation_file_id_, "get_game_object")); + return make_tl_object(id_, short_name_, title_, get_formatted_text_object(text_, skip_bot_commands, -1), + description_, get_photo_object(td->file_manager_.get(), photo_), + td->animations_manager_->get_animation_object(animation_file_id_)); } bool Game::has_input_media() const { diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 70ae34bf9..f33a4d0dd 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -1302,8 +1302,7 @@ void InlineQueriesManager::on_get_inline_query_results(DialogId dialog_id, UserI auto animation = make_tl_object(); animation->id_ = std::move(result->id_); - animation->animation_ = - td_->animations_manager_->get_animation_object(parsed_document.file_id, "inlineQueryResultAnimation"); + animation->animation_ = td_->animations_manager_->get_animation_object(parsed_document.file_id); animation->title_ = std::move(result->title_); if (!register_inline_message_content(results->query_id_, animation->id_, parsed_document.file_id, @@ -1618,8 +1617,7 @@ void InlineQueriesManager::on_get_inline_query_results(DialogId dialog_id, UserI } else if (is_animation && parsed_document.type == Document::Type::Animation) { auto animation = make_tl_object(); animation->id_ = std::move(result->id_); - animation->animation_ = - td_->animations_manager_->get_animation_object(file_id, "inlineQueryResultAnimationCached"); + animation->animation_ = td_->animations_manager_->get_animation_object(file_id); animation->title_ = std::move(result->title_); if (!register_inline_message_content(results->query_id_, animation->id_, file_id, std::move(result->send_message_), td_api::inputMessageAnimation::ID, diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 595ac31c5..2fb502e96 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4668,7 +4668,7 @@ tl_object_ptr get_message_content_object(const MessageCo case MessageContentType::Animation: { const MessageAnimation *m = static_cast(content); return make_tl_object( - td->animations_manager_->get_animation_object(m->file_id, "get_message_content_object"), + td->animations_manager_->get_animation_object(m->file_id), get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp), is_content_secret); } case MessageContentType::Audio: { diff --git a/td/telegram/NotificationType.cpp b/td/telegram/NotificationType.cpp index 5919a929e..72f00d773 100644 --- a/td/telegram/NotificationType.cpp +++ b/td/telegram/NotificationType.cpp @@ -164,7 +164,7 @@ class NotificationTypePushMessage final : public NotificationType { if (key == "MESSAGE_ANIMATION") { auto animations_manager = G()->td().get_actor_unsafe()->animations_manager_.get(); return td_api::make_object( - animations_manager->get_animation_object(document.file_id, "MESSAGE_ANIMATION"), arg, is_pinned); + animations_manager->get_animation_object(document.file_id), arg, is_pinned); } if (key == "MESSAGE_AUDIO") { auto audios_manager = G()->td().get_actor_unsafe()->audios_manager_.get(); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 99a738b19..0d7208428 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -2735,7 +2735,7 @@ class GetSavedAnimationsRequest final : public RequestActor<> { void do_send_result() final { send_result(make_tl_object(transform(std::move(animation_ids_), [td = td](FileId animation_id) { - return td->animations_manager_->get_animation_object(animation_id, "GetSavedAnimationsRequest"); + return td->animations_manager_->get_animation_object(animation_id); }))); } diff --git a/td/telegram/VideoNotesManager.cpp b/td/telegram/VideoNotesManager.cpp index aae674775..28b9d0a03 100644 --- a/td/telegram/VideoNotesManager.cpp +++ b/td/telegram/VideoNotesManager.cpp @@ -28,13 +28,14 @@ int32 VideoNotesManager::get_video_note_duration(FileId file_id) const { return it->second->duration; } -tl_object_ptr VideoNotesManager::get_video_note_object(FileId file_id) { +tl_object_ptr VideoNotesManager::get_video_note_object(FileId file_id) const { if (!file_id.is_valid()) { return nullptr; } - auto &video_note = video_notes_[file_id]; - CHECK(video_note != nullptr); + auto it = video_notes_.find(file_id); + CHECK(it != video_notes_.end()); + auto video_note = it->second.get(); return make_tl_object( video_note->duration, video_note->dimensions.width, get_minithumbnail_object(video_note->minithumbnail), get_thumbnail_object(td_->file_manager_.get(), video_note->thumbnail, PhotoFormat::Jpeg), diff --git a/td/telegram/VideoNotesManager.h b/td/telegram/VideoNotesManager.h index 0293edd8f..5e1356e29 100644 --- a/td/telegram/VideoNotesManager.h +++ b/td/telegram/VideoNotesManager.h @@ -28,7 +28,7 @@ class VideoNotesManager { int32 get_video_note_duration(FileId file_id) const; - tl_object_ptr get_video_note_object(FileId file_id); + tl_object_ptr get_video_note_object(FileId file_id) const; void create_video_note(FileId file_id, string minithumbnail, PhotoSize thumbnail, int32 duration, Dimensions dimensions, bool replace); diff --git a/td/telegram/VideosManager.cpp b/td/telegram/VideosManager.cpp index 950b1d80d..dd8ad3126 100644 --- a/td/telegram/VideosManager.cpp +++ b/td/telegram/VideosManager.cpp @@ -28,12 +28,14 @@ int32 VideosManager::get_video_duration(FileId file_id) const { return it->second->duration; } -tl_object_ptr VideosManager::get_video_object(FileId file_id) { +tl_object_ptr VideosManager::get_video_object(FileId file_id) const { if (!file_id.is_valid()) { return nullptr; } - auto &video = videos_[file_id]; + auto it = videos_.find(file_id); + CHECK(it != videos_.end()); + auto video = it->second.get(); CHECK(video != nullptr); auto thumbnail = video->animated_thumbnail.file_id.is_valid() ? get_thumbnail_object(td_->file_manager_.get(), video->animated_thumbnail, PhotoFormat::Mpeg4) diff --git a/td/telegram/VideosManager.h b/td/telegram/VideosManager.h index f7a6084f1..b47c20d6f 100644 --- a/td/telegram/VideosManager.h +++ b/td/telegram/VideosManager.h @@ -28,7 +28,7 @@ class VideosManager { int32 get_video_duration(FileId file_id) const; - tl_object_ptr get_video_object(FileId file_id); + tl_object_ptr get_video_object(FileId file_id) const; void create_video(FileId file_id, string minithumbnail, PhotoSize thumbnail, AnimationSize animated_thumbnail, bool has_stickers, vector &&sticker_file_ids, string file_name, string mime_type, diff --git a/td/telegram/VoiceNotesManager.cpp b/td/telegram/VoiceNotesManager.cpp index 32d362ddf..c9cd1c500 100644 --- a/td/telegram/VoiceNotesManager.cpp +++ b/td/telegram/VoiceNotesManager.cpp @@ -28,12 +28,14 @@ int32 VoiceNotesManager::get_voice_note_duration(FileId file_id) const { return it->second->duration; } -tl_object_ptr VoiceNotesManager::get_voice_note_object(FileId file_id) { +tl_object_ptr VoiceNotesManager::get_voice_note_object(FileId file_id) const { if (!file_id.is_valid()) { return nullptr; } - auto &voice_note = voice_notes_[file_id]; + auto it = voice_notes_.find(file_id); + CHECK(it != voice_notes_.end()); + auto voice_note = it->second.get(); CHECK(voice_note != nullptr); return make_tl_object(voice_note->duration, voice_note->waveform, voice_note->mime_type, td_->file_manager_->get_file_object(file_id)); diff --git a/td/telegram/VoiceNotesManager.h b/td/telegram/VoiceNotesManager.h index cb432f3db..21a920d33 100644 --- a/td/telegram/VoiceNotesManager.h +++ b/td/telegram/VoiceNotesManager.h @@ -26,7 +26,7 @@ class VoiceNotesManager { int32 get_voice_note_duration(FileId file_id) const; - tl_object_ptr get_voice_note_object(FileId file_id); + tl_object_ptr get_voice_note_object(FileId file_id) const; void create_voice_note(FileId file_id, string mime_type, int32 duration, string waveform, bool replace); diff --git a/td/telegram/WebPageBlock.cpp b/td/telegram/WebPageBlock.cpp index 4e7a9068f..943294574 100644 --- a/td/telegram/WebPageBlock.cpp +++ b/td/telegram/WebPageBlock.cpp @@ -981,7 +981,7 @@ class WebPageBlockAnimation final : public WebPageBlock { td_api::object_ptr get_page_block_object(Context *context) const final { return make_tl_object( - context->td_->animations_manager_->get_animation_object(animation_file_id, "get_page_block_object"), + context->td_->animations_manager_->get_animation_object(animation_file_id), caption.get_page_block_caption_object(context), need_autoplay); } diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 004b10275..65fccb1c3 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -1261,7 +1261,7 @@ tl_object_ptr WebPagesManager::get_web_page_object(WebPageId we get_photo_object(td_->file_manager_.get(), web_page->photo), web_page->embed_url, web_page->embed_type, web_page->embed_dimensions.width, web_page->embed_dimensions.height, web_page->duration, web_page->author, web_page->document.type == Document::Type::Animation - ? td_->animations_manager_->get_animation_object(web_page->document.file_id, "get_web_page_object") + ? td_->animations_manager_->get_animation_object(web_page->document.file_id) : nullptr, web_page->document.type == Document::Type::Audio ? td_->audios_manager_->get_audio_object(web_page->document.file_id)