From c1f4e9d292c5faa24c978964f40771dcb228b408 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 27 Sep 2018 21:14:32 +0300 Subject: [PATCH] Make get_*_duration const. GitOrigin-RevId: 85b5eb4cb221c2144318989d4d93b45784adcdf4 --- td/telegram/AnimationsManager.cpp | 8 ++++---- td/telegram/AnimationsManager.h | 2 +- td/telegram/AudiosManager.cpp | 8 ++++---- td/telegram/AudiosManager.h | 2 +- td/telegram/InlineQueriesManager.h | 2 +- td/telegram/MessagesManager.cpp | 14 +++++++------- td/telegram/MessagesManager.h | 3 ++- td/telegram/VideoNotesManager.cpp | 8 ++++---- td/telegram/VideoNotesManager.h | 2 +- td/telegram/VideosManager.cpp | 8 ++++---- td/telegram/VideosManager.h | 2 +- td/telegram/VoiceNotesManager.cpp | 8 ++++---- td/telegram/VoiceNotesManager.h | 2 +- td/telegram/files/FileManager.cpp | 2 +- 14 files changed, 36 insertions(+), 35 deletions(-) diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index 6c7cd307..f0e81c67 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -107,10 +107,10 @@ void AnimationsManager::tear_down() { parent_.reset(); } -int32 AnimationsManager::get_animation_duration(FileId file_id) { - auto &animation = animations_[file_id]; - CHECK(animation != nullptr); - return animation->duration; +int32 AnimationsManager::get_animation_duration(FileId file_id) const { + auto it = animations_.find(file_id); + CHECK(it != animations_.end()); + return it->second->duration; } tl_object_ptr AnimationsManager::get_animation_object(FileId file_id, const char *source) { diff --git a/td/telegram/AnimationsManager.h b/td/telegram/AnimationsManager.h index 8f43f833..f1919fcb 100644 --- a/td/telegram/AnimationsManager.h +++ b/td/telegram/AnimationsManager.h @@ -34,7 +34,7 @@ class AnimationsManager : public Actor { public: AnimationsManager(Td *td, ActorShared<> parent); - int32 get_animation_duration(FileId file_id); + int32 get_animation_duration(FileId file_id) const; tl_object_ptr get_animation_object(FileId file_id, const char *source); diff --git a/td/telegram/AudiosManager.cpp b/td/telegram/AudiosManager.cpp index e8fbd09d..d84ed5d4 100644 --- a/td/telegram/AudiosManager.cpp +++ b/td/telegram/AudiosManager.cpp @@ -24,10 +24,10 @@ namespace td { AudiosManager::AudiosManager(Td *td) : td_(td) { } -int32 AudiosManager::get_audio_duration(FileId file_id) { - auto &audio = audios_[file_id]; - CHECK(audio != nullptr); - return audio->duration; +int32 AudiosManager::get_audio_duration(FileId file_id) const { + auto it = audios_.find(file_id); + CHECK(it != audios_.end()); + return it->second->duration; } tl_object_ptr AudiosManager::get_audio_object(FileId file_id) { diff --git a/td/telegram/AudiosManager.h b/td/telegram/AudiosManager.h index d3554fee..325611b5 100644 --- a/td/telegram/AudiosManager.h +++ b/td/telegram/AudiosManager.h @@ -28,7 +28,7 @@ class AudiosManager { public: explicit AudiosManager(Td *td); - int32 get_audio_duration(FileId file_id); + int32 get_audio_duration(FileId file_id) const; tl_object_ptr get_audio_object(FileId file_id); diff --git a/td/telegram/InlineQueriesManager.h b/td/telegram/InlineQueriesManager.h index cc24668a..e21ed3f1 100644 --- a/td/telegram/InlineQueriesManager.h +++ b/td/telegram/InlineQueriesManager.h @@ -99,7 +99,7 @@ class InlineQueriesManager : public Actor { Result> get_inline_message( tl_object_ptr &&input_message_content, tl_object_ptr &&reply_markup_ptr, - int32 allowed_media_content_id) const TD_WARN_UNUSED_RESULT; // TODO make static + int32 allowed_media_content_id) const TD_WARN_UNUSED_RESULT; InlineMessageContent create_inline_message_content(FileId file_id, tl_object_ptr &&inline_message, diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index c53ad484..e4c65023 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -4373,7 +4373,7 @@ void MessagesManager::Message::store(StorerT &storer) const { if (has_media_album_id) { store(media_album_id, storer); } - store(static_cast(content.get()), storer); // TODO unique_ptr with const propagation + store(content.get(), storer); if (has_reply_markup) { store(*reply_markup, storer); } @@ -5157,7 +5157,7 @@ int32 MessagesManager::get_message_index_mask(DialogId dialog_id, const Message if (m->is_content_secret || (m->ttl > 0 && !is_secret)) { return 0; } - int32 mentions_mask = get_message_content_index_mask(m->content.get(), is_secret, m->is_outgoing); + int32 mentions_mask = get_message_content_index_mask(m->content.get(), td_, is_secret, m->is_outgoing); if (m->contains_mention) { mentions_mask |= search_messages_filter_index_mask(SearchMessagesFilter::Mention); if (m->contains_unread_mention) { @@ -5167,14 +5167,14 @@ int32 MessagesManager::get_message_index_mask(DialogId dialog_id, const Message return mentions_mask; } -int32 MessagesManager::get_message_content_index_mask(const MessageContent *content, bool is_secret, - bool is_outgoing) const { +int32 MessagesManager::get_message_content_index_mask(const MessageContent *content, const Td *td, bool is_secret, + bool is_outgoing) { switch (content->get_type()) { case MessageContentType::Animation: return search_messages_filter_index_mask(SearchMessagesFilter::Animation); case MessageContentType::Audio: { auto message_audio = static_cast(content); - auto duration = td_->audios_manager_->get_audio_duration(message_audio->file_id); + auto duration = td->audios_manager_->get_audio_duration(message_audio->file_id); return is_secret || duration > 0 ? search_messages_filter_index_mask(SearchMessagesFilter::Audio) : search_messages_filter_index_mask(SearchMessagesFilter::Document); } @@ -5193,14 +5193,14 @@ int32 MessagesManager::get_message_content_index_mask(const MessageContent *cont return 0; case MessageContentType::Video: { auto message_video = static_cast(content); - auto duration = td_->videos_manager_->get_video_duration(message_video->file_id); + auto duration = td->videos_manager_->get_video_duration(message_video->file_id); return is_secret || duration > 0 ? search_messages_filter_index_mask(SearchMessagesFilter::Video) | search_messages_filter_index_mask(SearchMessagesFilter::PhotoAndVideo) : search_messages_filter_index_mask(SearchMessagesFilter::Document); } case MessageContentType::VideoNote: { auto message_video_note = static_cast(content); - auto duration = td_->video_notes_manager_->get_video_note_duration(message_video_note->file_id); + auto duration = td->video_notes_manager_->get_video_note_duration(message_video_note->file_id); return is_secret || duration > 0 ? search_messages_filter_index_mask(SearchMessagesFilter::VideoNote) | search_messages_filter_index_mask(SearchMessagesFilter::VoiceAndVideoNote) : search_messages_filter_index_mask(SearchMessagesFilter::Document); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index df2132eb..e210ae00 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2238,7 +2238,8 @@ class MessagesManager : public Actor { int32 get_message_index_mask(DialogId dialog_id, const Message *m) const; - int32 get_message_content_index_mask(const MessageContent *content, bool is_secret, bool is_outgoing) const; + static int32 get_message_content_index_mask(const MessageContent *content, const Td *td, bool is_secret, + bool is_outgoing); Message *add_message_to_dialog(DialogId dialog_id, unique_ptr message, bool from_update, bool *need_update, bool *need_update_dialog_pos, const char *source); diff --git a/td/telegram/VideoNotesManager.cpp b/td/telegram/VideoNotesManager.cpp index 5342803d..4611452d 100644 --- a/td/telegram/VideoNotesManager.cpp +++ b/td/telegram/VideoNotesManager.cpp @@ -24,10 +24,10 @@ namespace td { VideoNotesManager::VideoNotesManager(Td *td) : td_(td) { } -int32 VideoNotesManager::get_video_note_duration(FileId file_id) { - auto &video_note = video_notes_[file_id]; - CHECK(video_note != nullptr); - return video_note->duration; +int32 VideoNotesManager::get_video_note_duration(FileId file_id) const { + auto it = video_notes_.find(file_id); + CHECK(it != video_notes_.end()); + return it->second->duration; } tl_object_ptr VideoNotesManager::get_video_note_object(FileId file_id) { diff --git a/td/telegram/VideoNotesManager.h b/td/telegram/VideoNotesManager.h index 6f8c7d91..db5cc7db 100644 --- a/td/telegram/VideoNotesManager.h +++ b/td/telegram/VideoNotesManager.h @@ -28,7 +28,7 @@ class VideoNotesManager { public: explicit VideoNotesManager(Td *td); - int32 get_video_note_duration(FileId file_id); + int32 get_video_note_duration(FileId file_id) const; tl_object_ptr get_video_note_object(FileId file_id); diff --git a/td/telegram/VideosManager.cpp b/td/telegram/VideosManager.cpp index eb056b88..1331c829 100644 --- a/td/telegram/VideosManager.cpp +++ b/td/telegram/VideosManager.cpp @@ -25,10 +25,10 @@ namespace td { VideosManager::VideosManager(Td *td) : td_(td) { } -int32 VideosManager::get_video_duration(FileId file_id) { - auto &video = videos_[file_id]; - CHECK(video != nullptr); - return video->duration; +int32 VideosManager::get_video_duration(FileId file_id) const { + auto it = videos_.find(file_id); + CHECK(it != videos_.end()); + return it->second->duration; } tl_object_ptr VideosManager::get_video_object(FileId file_id) { diff --git a/td/telegram/VideosManager.h b/td/telegram/VideosManager.h index 67a0eccf..44b6f7c3 100644 --- a/td/telegram/VideosManager.h +++ b/td/telegram/VideosManager.h @@ -28,7 +28,7 @@ class VideosManager { public: explicit VideosManager(Td *td); - int32 get_video_duration(FileId file_id); + int32 get_video_duration(FileId file_id) const; tl_object_ptr get_video_object(FileId file_id); diff --git a/td/telegram/VoiceNotesManager.cpp b/td/telegram/VoiceNotesManager.cpp index c1b6d957..326cd563 100644 --- a/td/telegram/VoiceNotesManager.cpp +++ b/td/telegram/VoiceNotesManager.cpp @@ -25,10 +25,10 @@ namespace td { VoiceNotesManager::VoiceNotesManager(Td *td) : td_(td) { } -int32 VoiceNotesManager::get_voice_note_duration(FileId file_id) { - auto &voice_note = voice_notes_[file_id]; - CHECK(voice_note != nullptr); - return voice_note->duration; +int32 VoiceNotesManager::get_voice_note_duration(FileId file_id) const { + auto it = voice_notes_.find(file_id); + CHECK(it != voice_notes_.end()); + return it->second->duration; } tl_object_ptr VoiceNotesManager::get_voice_note_object(FileId file_id) { diff --git a/td/telegram/VoiceNotesManager.h b/td/telegram/VoiceNotesManager.h index 88178306..d387923f 100644 --- a/td/telegram/VoiceNotesManager.h +++ b/td/telegram/VoiceNotesManager.h @@ -26,7 +26,7 @@ class VoiceNotesManager { public: explicit VoiceNotesManager(Td *td); - int32 get_voice_note_duration(FileId file_id); + int32 get_voice_note_duration(FileId file_id) const; tl_object_ptr get_voice_note_object(FileId file_id); diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index ad93e05b..a7a1504e 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -1238,7 +1238,7 @@ void FileManager::flush_to_pmc(FileNodePtr node, bool new_remote, bool new_local data.generate_ = make_unique(*node->generate_); } - // TODO: not needed when GenerateLocation has constant convertion + // TODO: not needed when GenerateLocation has constant conversion if (data.remote_.type() != RemoteFileLocation::Type::Full && data.local_.type() != LocalFileLocation::Type::Full) { data.local_ = LocalFileLocation(); data.remote_ = RemoteFileLocation();