From 536def0382db24bfc112ad410a1a2b3c3b6a6101 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 31 Jan 2018 12:18:40 +0300 Subject: [PATCH] Fix has_input_media. GitOrigin-RevId: f10ffc8116028849b3a0afc4ebf7169d707dd794 --- td/telegram/DocumentsManager.cpp | 8 +++++-- td/telegram/DocumentsManager.h | 2 +- td/telegram/MessagesManager.cpp | 39 ++++++++++++++++++++------------ td/telegram/Photo.cpp | 12 +++++++++- td/telegram/SecretChatActor.cpp | 1 + td/telegram/StickersManager.cpp | 2 +- td/telegram/Td.cpp | 4 ++++ td/telegram/Td.h | 2 ++ 8 files changed, 50 insertions(+), 20 deletions(-) diff --git a/td/telegram/DocumentsManager.cpp b/td/telegram/DocumentsManager.cpp index 16c8d399..8ccb29fc 100644 --- a/td/telegram/DocumentsManager.cpp +++ b/td/telegram/DocumentsManager.cpp @@ -330,10 +330,14 @@ const DocumentsManager::Document *DocumentsManager::get_document(FileId file_id) return document->second.get(); } -bool DocumentsManager::has_input_media(FileId file_id, bool is_secret) const { +bool DocumentsManager::has_input_media(FileId file_id, FileId thumbnail_file_id, bool is_secret) const { auto file_view = td_->file_manager_->get_file_view(file_id); if (is_secret) { - return file_view.is_encrypted() && file_view.has_remote_location(); + if (file_view.encryption_key().empty() || !file_view.has_remote_location()) { + return false; + } + + return !thumbnail_file_id.is_valid(); } else { if (file_view.is_encrypted()) { return false; diff --git a/td/telegram/DocumentsManager.h b/td/telegram/DocumentsManager.h index f93831c1..057e31d9 100644 --- a/td/telegram/DocumentsManager.h +++ b/td/telegram/DocumentsManager.h @@ -67,7 +67,7 @@ class DocumentsManager { void create_document(FileId file_id, PhotoSize thumbnail, string file_name, string mime_type, bool replace); - bool has_input_media(FileId file_id, bool is_secret) const; + bool has_input_media(FileId file_id, FileId thumbnail_file_id, bool is_secret) const; SecretInputMedia get_secret_input_media(FileId document_file_id, tl_object_ptr input_file, diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 27be3fd6..736ffa97 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6310,16 +6310,18 @@ void MessagesManager::after_get_difference() { } } - // TODO move to AnimationsManager - td_->animations_manager_->get_saved_animations(Auto()); + if (td_->is_online()) { + // TODO move to AnimationsManager + td_->animations_manager_->get_saved_animations(Auto()); - // TODO move to StickersManager - td_->stickers_manager_->get_installed_sticker_sets(false, Auto()); - td_->stickers_manager_->get_installed_sticker_sets(true, Auto()); - td_->stickers_manager_->get_featured_sticker_sets(Auto()); - td_->stickers_manager_->get_recent_stickers(false, Auto()); - td_->stickers_manager_->get_recent_stickers(true, Auto()); - td_->stickers_manager_->get_favorite_stickers(Auto()); + // TODO move to StickersManager + td_->stickers_manager_->get_installed_sticker_sets(false, Auto()); + td_->stickers_manager_->get_installed_sticker_sets(true, Auto()); + td_->stickers_manager_->get_featured_sticker_sets(Auto()); + td_->stickers_manager_->get_recent_stickers(false, Auto()); + td_->stickers_manager_->get_recent_stickers(true, Auto()); + td_->stickers_manager_->get_favorite_stickers(Auto()); + } load_notification_settings(); @@ -20342,10 +20344,14 @@ unique_ptr MessagesManager::dup_message_content(DialogId dialog_ return file_manager->dup_file_id(file_id); }; + FileId thumbnail_file_id; + if (to_secret) { + thumbnail_file_id = get_message_content_thumbnail_file_id(content); + } switch (content->get_id()) { case MessageAnimation::ID: { auto result = make_unique(*static_cast(content)); - if (td_->documents_manager_->has_input_media(result->file_id, to_secret)) { + if (td_->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) { return std::move(result); } result->file_id = td_->animations_manager_->dup_animation(fix_file_id(result->file_id), result->file_id); @@ -20354,7 +20360,7 @@ unique_ptr MessagesManager::dup_message_content(DialogId dialog_ } case MessageAudio::ID: { auto result = make_unique(*static_cast(content)); - if (td_->documents_manager_->has_input_media(result->file_id, to_secret)) { + if (td_->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) { return std::move(result); } result->file_id = td_->audios_manager_->dup_audio(fix_file_id(result->file_id), result->file_id); @@ -20365,7 +20371,7 @@ unique_ptr MessagesManager::dup_message_content(DialogId dialog_ return make_unique(*static_cast(content)); case MessageDocument::ID: { auto result = make_unique(*static_cast(content)); - if (td_->documents_manager_->has_input_media(result->file_id, to_secret)) { + if (td_->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) { return std::move(result); } result->file_id = td_->documents_manager_->dup_document(fix_file_id(result->file_id), result->file_id); @@ -20436,6 +20442,9 @@ unique_ptr MessagesManager::dup_message_content(DialogId dialog_ } result->photo.photos.back().file_id = fix_file_id(result->photo.photos.back().file_id); + if (thumbnail.type != 0) { + result->photo.photos[0].file_id = td_->file_manager_->dup_file_id(result->photo.photos[0].file_id); + } return std::move(result); } case MessageSticker::ID: { @@ -20453,7 +20462,7 @@ unique_ptr MessagesManager::dup_message_content(DialogId dialog_ return make_unique(*static_cast(content)); case MessageVideo::ID: { auto result = make_unique(*static_cast(content)); - if (td_->documents_manager_->has_input_media(result->file_id, to_secret)) { + if (td_->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) { return std::move(result); } result->file_id = td_->videos_manager_->dup_video(fix_file_id(result->file_id), result->file_id); @@ -20463,7 +20472,7 @@ unique_ptr MessagesManager::dup_message_content(DialogId dialog_ case MessageVideoNote::ID: { auto result = make_unique(*static_cast(content)); result->is_viewed = false; - if (td_->documents_manager_->has_input_media(result->file_id, to_secret)) { + if (td_->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) { return std::move(result); } result->file_id = td_->video_notes_manager_->dup_video_note(fix_file_id(result->file_id), result->file_id); @@ -20473,7 +20482,7 @@ unique_ptr MessagesManager::dup_message_content(DialogId dialog_ case MessageVoiceNote::ID: { auto result = make_unique(*static_cast(content)); result->is_listened = false; - if (td_->documents_manager_->has_input_media(result->file_id, to_secret)) { + if (td_->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) { return std::move(result); } result->file_id = td_->voice_notes_manager_->dup_voice_note(fix_file_id(result->file_id), result->file_id); diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index f56e72e9..a3de5734 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -386,7 +386,17 @@ bool photo_has_input_media(FileManager *file_manager, const Photo &photo, bool i auto file_id = photo.photos.back().file_id; auto file_view = file_manager->get_file_view(file_id); if (is_secret) { - return file_view.is_encrypted() && file_view.has_remote_location(); + if (file_view.encryption_key().empty() || !file_view.has_remote_location()) { + return false; + } + + for (const auto &size : photo.photos) { + if (size.type == 't' && size.file_id.is_valid()) { + return false; + } + } + + return true; } else { if (file_view.is_encrypted()) { return false; diff --git a/td/telegram/SecretChatActor.cpp b/td/telegram/SecretChatActor.cpp index 50e19228..ab9d904d 100644 --- a/td/telegram/SecretChatActor.cpp +++ b/td/telegram/SecretChatActor.cpp @@ -1687,6 +1687,7 @@ void SecretChatActor::on_outbound_outer_send_message_promise(uint64 state_id, Pr LOG(INFO) << "Outbound secret message [TODO] " << tag("logevent_id", state->message->logevent_id()); promise.set_value(Unit()); // Seems like this message is at least stored to binlog already } + void SecretChatActor::outbound_loop(OutboundMessageState *state, uint64 state_id) { if (close_flag_) { return; diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 82be450e..fabc1310 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1229,7 +1229,7 @@ bool StickersManager::has_input_media(FileId sticker_file_id, bool is_secret) co auto file_view = td_->file_manager_->get_file_view(sticker_file_id); if (is_secret) { if (file_view.is_encrypted()) { - if (file_view.has_remote_location()) { + if (file_view.has_remote_location() && !sticker->message_thumbnail.file_id.is_valid()) { return true; } } else { diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 940afb52..2016dbf3 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3562,6 +3562,10 @@ void Td::on_channel_unban_timeout(int64 channel_id_long) { contacts_manager_->on_channel_unban_timeout(ChannelId(narrow_cast(channel_id_long))); } +bool Td::is_online() const { + return is_online_; +} + void Td::request(uint64 id, tl_object_ptr function) { request_set_.insert(id); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 08ea3b4d..edfab6bf 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -97,6 +97,8 @@ class Td final : public NetQueryCallback { void on_channel_unban_timeout(int64 channel_id_long); + bool is_online() const; + template ActorId create_net_actor(ArgsT &&... args) { auto slot_id = request_actors_.create(ActorOwn<>(), RequestActorIdType);