Make get_document_object methods const.

This commit is contained in:
levlam 2021-08-28 14:16:29 +03:00
parent 97fccf7f27
commit aaff89a6c3
19 changed files with 43 additions and 36 deletions

View File

@ -150,14 +150,15 @@ int32 AnimationsManager::get_animation_duration(FileId file_id) const {
return it->second->duration;
}
tl_object_ptr<td_api::animation> AnimationsManager::get_animation_object(FileId file_id, const char *source) {
tl_object_ptr<td_api::animation> 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<int32>(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)

View File

@ -33,7 +33,7 @@ class AnimationsManager final : public Actor {
int32 get_animation_duration(FileId file_id) const;
tl_object_ptr<td_api::animation> get_animation_object(FileId file_id, const char *source);
tl_object_ptr<td_api::animation> get_animation_object(FileId file_id) const;
void create_animation(FileId file_id, string minithumbnail, PhotoSize thumbnail, AnimationSize animated_thumbnail,
bool has_stickers, vector<FileId> &&sticker_file_ids, string file_name, string mime_type,

View File

@ -29,12 +29,14 @@ int32 AudiosManager::get_audio_duration(FileId file_id) const {
return it->second->duration;
}
tl_object_ptr<td_api::audio> AudiosManager::get_audio_object(FileId file_id) {
tl_object_ptr<td_api::audio> 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<td_api::audio>(
audio->duration, audio->title, audio->performer, audio->file_name, audio->mime_type,

View File

@ -28,7 +28,7 @@ class AudiosManager {
int32 get_audio_duration(FileId file_id) const;
tl_object_ptr<td_api::audio> get_audio_object(FileId file_id);
tl_object_ptr<td_api::audio> 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);

View File

@ -47,14 +47,16 @@ namespace td {
DocumentsManager::DocumentsManager(Td *td) : td_(td) {
}
tl_object_ptr<td_api::document> DocumentsManager::get_document_object(FileId file_id, PhotoFormat thumbnail_format) {
tl_object_ptr<td_api::document> 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<td_api::document>(
document->file_name, document->mime_type, get_minithumbnail_object(document->minithumbnail),
get_thumbnail_object(td_->file_manager_.get(), document->thumbnail, thumbnail_format),

View File

@ -75,7 +75,7 @@ class DocumentsManager {
}
};
tl_object_ptr<td_api::document> get_document_object(FileId file_id, PhotoFormat thumbnail_format);
tl_object_ptr<td_api::document> 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,

View File

@ -92,10 +92,9 @@ const FormattedText &Game::get_text() const {
}
tl_object_ptr<td_api::game> Game::get_game_object(Td *td, bool skip_bot_commands) const {
return make_tl_object<td_api::game>(
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<td_api::game>(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 {

View File

@ -1302,8 +1302,7 @@ void InlineQueriesManager::on_get_inline_query_results(DialogId dialog_id, UserI
auto animation = make_tl_object<td_api::inlineQueryResultAnimation>();
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<td_api::inlineQueryResultAnimation>();
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,

View File

@ -4668,7 +4668,7 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
case MessageContentType::Animation: {
const MessageAnimation *m = static_cast<const MessageAnimation *>(content);
return make_tl_object<td_api::messageAnimation>(
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: {

View File

@ -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<td_api::pushMessageContentAnimation>(
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();

View File

@ -2735,7 +2735,7 @@ class GetSavedAnimationsRequest final : public RequestActor<> {
void do_send_result() final {
send_result(make_tl_object<td_api::animations>(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);
})));
}

View File

@ -28,13 +28,14 @@ int32 VideoNotesManager::get_video_note_duration(FileId file_id) const {
return it->second->duration;
}
tl_object_ptr<td_api::videoNote> VideoNotesManager::get_video_note_object(FileId file_id) {
tl_object_ptr<td_api::videoNote> 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<td_api::videoNote>(
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),

View File

@ -28,7 +28,7 @@ class VideoNotesManager {
int32 get_video_note_duration(FileId file_id) const;
tl_object_ptr<td_api::videoNote> get_video_note_object(FileId file_id);
tl_object_ptr<td_api::videoNote> 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);

View File

@ -28,12 +28,14 @@ int32 VideosManager::get_video_duration(FileId file_id) const {
return it->second->duration;
}
tl_object_ptr<td_api::video> VideosManager::get_video_object(FileId file_id) {
tl_object_ptr<td_api::video> 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)

View File

@ -28,7 +28,7 @@ class VideosManager {
int32 get_video_duration(FileId file_id) const;
tl_object_ptr<td_api::video> get_video_object(FileId file_id);
tl_object_ptr<td_api::video> get_video_object(FileId file_id) const;
void create_video(FileId file_id, string minithumbnail, PhotoSize thumbnail, AnimationSize animated_thumbnail,
bool has_stickers, vector<FileId> &&sticker_file_ids, string file_name, string mime_type,

View File

@ -28,12 +28,14 @@ int32 VoiceNotesManager::get_voice_note_duration(FileId file_id) const {
return it->second->duration;
}
tl_object_ptr<td_api::voiceNote> VoiceNotesManager::get_voice_note_object(FileId file_id) {
tl_object_ptr<td_api::voiceNote> 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<td_api::voiceNote>(voice_note->duration, voice_note->waveform, voice_note->mime_type,
td_->file_manager_->get_file_object(file_id));

View File

@ -26,7 +26,7 @@ class VoiceNotesManager {
int32 get_voice_note_duration(FileId file_id) const;
tl_object_ptr<td_api::voiceNote> get_voice_note_object(FileId file_id);
tl_object_ptr<td_api::voiceNote> get_voice_note_object(FileId file_id) const;
void create_voice_note(FileId file_id, string mime_type, int32 duration, string waveform, bool replace);

View File

@ -981,7 +981,7 @@ class WebPageBlockAnimation final : public WebPageBlock {
td_api::object_ptr<td_api::PageBlock> get_page_block_object(Context *context) const final {
return make_tl_object<td_api::pageBlockAnimation>(
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);
}

View File

@ -1261,7 +1261,7 @@ tl_object_ptr<td_api::webPage> 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)