From c1b88e2cc19f6e238203b0216e2360669ac73299 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 7 Jul 2020 20:56:54 +0300 Subject: [PATCH] Allow to specify main_frame_timestamp when setting up animated profile photo. GitOrigin-RevId: 8e5229642cdf5a454f932c0b201497f019344eab --- td/generate/scheme/td_api.tl | 6 ++++-- td/generate/scheme/td_api.tlo | Bin 176912 -> 176960 bytes td/telegram/ContactsManager.cpp | 34 +++++++++++++++++++++++--------- td/telegram/ContactsManager.h | 11 ++++++++--- td/telegram/cli.cpp | 8 ++++++-- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 41afd801e..cab2b6b7f 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -371,8 +371,10 @@ inputChatPhotoPrevious chat_photo_id:int64 = InputChatPhoto; //@description A static photo in JPEG format @photo Photo to be set as profile photo. Only inputFileLocal and inputFileGenerated are allowed inputChatPhotoStatic photo:InputFile = InputChatPhoto; -//@description An animation in MPEG4 format; must be square, shorter than 10 seconds, have width between 160 and 800 and be at most 2MB in size @animation Animation to be set as profile photo. Only inputFileLocal and inputFileGenerated are allowed -inputChatPhotoAnimation animation:InputFile = InputChatPhoto; +//@description An animation in MPEG4 format; must be square, shorter than 10 seconds, have width between 160 and 800 and be at most 2MB in size +//@animation Animation to be set as profile photo. Only inputFileLocal and inputFileGenerated are allowed +//@main_frame_timestamp Timestamp of the frame, which will be used as static chat photo +inputChatPhotoAnimation animation:InputFile main_frame_timestamp:double = InputChatPhoto; //@description Represents a user @id User identifier @first_name First name of the user @last_name Last name of the user @username Username of the user diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index e5f54471cdebd92ec431ba4bded04f9bbff6aa53..b160031aa756a0a4d0f9f984ff99df5917e9fb46 100644 GIT binary patch delta 122 zcmbR6jO)NNt_?4QSRCyC7H)ncbY&TsHTlR+3ov8SE)6g}eZxE^ndu3Wm_$TCDjA^Q zsvK90l1Ucp &&promise) : promise_(std::move(promise)) { } - void send(FileId file_id, tl_object_ptr &&input_file, bool is_animation) { + void send(FileId file_id, tl_object_ptr &&input_file, bool is_animation, + double main_frame_timestamp) { CHECK(input_file != nullptr); CHECK(file_id.is_valid()); @@ -821,12 +822,16 @@ class UploadProfilePhotoQuery : public Td::ResultHandler { if (is_animation) { flags |= telegram_api::photos_uploadProfilePhoto::VIDEO_MASK; video_input_file = std::move(input_file); + + if (main_frame_timestamp != 0.0) { + flags |= telegram_api::photos_uploadProfilePhoto::VIDEO_START_TS_MASK; + } } else { flags |= telegram_api::photos_uploadProfilePhoto::FILE_MASK; photo_input_file = std::move(input_file); } - send_query(G()->net_query_creator().create( - telegram_api::photos_uploadProfilePhoto(flags, std::move(photo_input_file), std::move(video_input_file), 0))); + send_query(G()->net_query_creator().create(telegram_api::photos_uploadProfilePhoto( + flags, std::move(photo_input_file), std::move(video_input_file), main_frame_timestamp))); } void on_result(uint64 id, BufferSlice packet) override { @@ -5491,6 +5496,7 @@ void ContactsManager::set_profile_photo(const td_api::object_ptr *input_file = nullptr; + double main_frame_timestamp = 0.0; bool is_animation = false; switch (input_photo->get_id()) { case td_api::inputChatPhotoPrevious::ID: { @@ -5517,6 +5523,7 @@ void ContactsManager::set_profile_photo(const td_api::object_ptr(input_photo.get()); input_file = &photo->animation_; + main_frame_timestamp = photo->main_frame_timestamp_; is_animation = true; break; } @@ -5525,6 +5532,11 @@ void ContactsManager::set_profile_photo(const td_api::object_ptr MAX_ANIMATION_DURATION) { + return promise.set_error(Status::Error(400, "Wrong main frame timestamp specified")); + } + auto file_type = is_animation ? FileType::Animation : FileType::Photo; auto r_file_id = td_->file_manager_->get_input_file_id(file_type, *input_file, DialogId(get_my_id()), false, false); if (r_file_id.is_error()) { @@ -5534,7 +5546,8 @@ void ContactsManager::set_profile_photo(const td_api::object_ptrfile_manager_->dup_file_id(file_id), is_animation, std::move(promise)); + upload_profile_photo(td_->file_manager_->dup_file_id(file_id), is_animation, main_frame_timestamp, + std::move(promise)); } void ContactsManager::send_update_profile_photo_query(FileId file_id, Promise &&promise) { @@ -5543,11 +5556,12 @@ void ContactsManager::send_update_profile_photo_query(FileId file_id, Promisesend(file_id, file_view.main_remote_location().as_input_photo()); } -void ContactsManager::upload_profile_photo(FileId file_id, bool is_animation, Promise &&promise, - vector bad_parts) { +void ContactsManager::upload_profile_photo(FileId file_id, bool is_animation, double main_frame_timestamp, + Promise &&promise, vector bad_parts) { CHECK(file_id.is_valid()); CHECK(uploaded_profile_photos_.find(file_id) == uploaded_profile_photos_.end()); - uploaded_profile_photos_.emplace(file_id, UploadedProfilePhoto{is_animation, !bad_parts.empty(), std::move(promise)}); + uploaded_profile_photos_.emplace( + file_id, UploadedProfilePhoto{main_frame_timestamp, is_animation, !bad_parts.empty(), std::move(promise)}); LOG(INFO) << "Ask to upload profile photo " << file_id; // TODO use force_reupload td_->file_manager_->resume_upload(file_id, std::move(bad_parts), upload_profile_photo_callback_, 32, 0); @@ -13695,6 +13709,7 @@ void ContactsManager::on_upload_profile_photo(FileId file_id, tl_object_ptrsecond.main_frame_timestamp; bool is_animation = it->second.is_animation; bool is_reupload = it->second.is_reupload; auto promise = std::move(it->second.promise); @@ -13713,12 +13728,13 @@ void ContactsManager::on_upload_profile_photo(FileId file_id, tl_object_ptrfile_manager_->delete_file_reference(file_id, file_reference); - upload_profile_photo(file_id, is_animation, std::move(promise), {-1}); + upload_profile_photo(file_id, is_animation, main_frame_timestamp, std::move(promise), {-1}); return; } CHECK(input_file != nullptr); - td_->create_handler(std::move(promise))->send(file_id, std::move(input_file), is_animation); + td_->create_handler(std::move(promise)) + ->send(file_id, std::move(input_file), is_animation, main_frame_timestamp); } void ContactsManager::on_upload_profile_photo_error(FileId file_id, Status status) { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 18d2d53fe..957dd09e2 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1119,7 +1119,8 @@ class ContactsManager : public Actor { void do_update_user_photo(User *u, UserId user_id, tl_object_ptr &&photo, const char *source); - void upload_profile_photo(FileId file_id, bool is_animation, Promise &&promise, vector bad_parts = {}); + void upload_profile_photo(FileId file_id, bool is_animation, double main_frame_timestamp, Promise &&promise, + vector bad_parts = {}); void on_upload_profile_photo(FileId file_id, tl_object_ptr input_file); void on_upload_profile_photo_error(FileId file_id, Status status); @@ -1507,12 +1508,16 @@ class ContactsManager : public Actor { std::shared_ptr upload_profile_photo_callback_; struct UploadedProfilePhoto { + double main_frame_timestamp; bool is_animation; bool is_reupload; Promise promise; - UploadedProfilePhoto(bool is_animation, bool is_reupload, Promise promise) - : is_animation(is_animation), is_reupload(is_reupload), promise(std::move(promise)) { + UploadedProfilePhoto(double main_frame_timestamp, bool is_animation, bool is_reupload, Promise promise) + : main_frame_timestamp(main_frame_timestamp) + , is_animation(is_animation) + , is_reupload(is_reupload) + , promise(std::move(promise)) { } }; std::unordered_map uploaded_profile_photos_; // file_id -> promise diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 23610c9ec..bd8531488 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3847,8 +3847,12 @@ class CliClient final : public Actor { send_request(td_api::make_object( td_api::make_object(as_input_file(args)))); } else if (op == "sppa" || op == "sppv") { - send_request(td_api::make_object( - td_api::make_object(as_input_file(args)))); + string animation; + string main_frame_timestamp; + std::tie(animation, main_frame_timestamp) = split(args); + + send_request(td_api::make_object(td_api::make_object( + as_input_file(animation), to_double(main_frame_timestamp)))); } else if (op == "sh") { auto prefix = std::move(args); send_request(td_api::make_object(prefix, 10));