2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#include "td/telegram/VideoNotesManager.h"
|
|
|
|
|
2021-05-27 20:15:30 +02:00
|
|
|
#include "td/telegram/AuthManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/files/FileManager.h"
|
2022-08-14 14:04:08 +02:00
|
|
|
#include "td/telegram/Global.h"
|
2022-10-20 20:31:00 +02:00
|
|
|
#include "td/telegram/MessagesManager.h"
|
2022-10-20 23:10:43 +02:00
|
|
|
#include "td/telegram/OptionManager.h"
|
2022-04-09 22:21:07 +02:00
|
|
|
#include "td/telegram/PhotoFormat.h"
|
2021-05-27 20:15:30 +02:00
|
|
|
#include "td/telegram/secret_api.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/Td.h"
|
2021-05-27 20:15:30 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
2023-11-21 18:32:23 +01:00
|
|
|
#include "td/telegram/TranscriptionManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-08-14 14:04:08 +02:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
2022-11-02 17:51:41 +01:00
|
|
|
#include "td/utils/buffer.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/logging.h"
|
2022-11-02 17:51:41 +01:00
|
|
|
#include "td/utils/misc.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2022-10-20 17:53:12 +02:00
|
|
|
VideoNotesManager::VideoNotesManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2022-07-20 12:40:14 +02:00
|
|
|
VideoNotesManager::~VideoNotesManager() {
|
|
|
|
Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), video_notes_);
|
|
|
|
}
|
2022-10-20 17:53:12 +02:00
|
|
|
|
|
|
|
void VideoNotesManager::tear_down() {
|
|
|
|
parent_.reset();
|
|
|
|
}
|
2022-07-20 12:40:14 +02:00
|
|
|
|
2018-09-27 20:14:32 +02:00
|
|
|
int32 VideoNotesManager::get_video_note_duration(FileId file_id) const {
|
2022-08-03 22:23:32 +02:00
|
|
|
auto video_note = get_video_note(file_id);
|
|
|
|
CHECK(video_note != nullptr);
|
|
|
|
return video_note->duration;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-08-28 13:16:29 +02:00
|
|
|
tl_object_ptr<td_api::videoNote> VideoNotesManager::get_video_note_object(FileId file_id) const {
|
2018-12-31 20:04:05 +01:00
|
|
|
if (!file_id.is_valid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-08-03 22:23:32 +02:00
|
|
|
auto video_note = get_video_note(file_id);
|
2022-10-20 20:31:00 +02:00
|
|
|
auto speech_recognition_result = video_note->transcription_info == nullptr
|
|
|
|
? nullptr
|
|
|
|
: video_note->transcription_info->get_speech_recognition_result_object();
|
2020-05-31 21:22:15 +02:00
|
|
|
return make_tl_object<td_api::videoNote>(
|
2022-10-20 22:23:40 +02:00
|
|
|
video_note->duration, video_note->waveform, video_note->dimensions.width,
|
|
|
|
get_minithumbnail_object(video_note->minithumbnail),
|
2020-05-31 21:22:15 +02:00
|
|
|
get_thumbnail_object(td_->file_manager_.get(), video_note->thumbnail, PhotoFormat::Jpeg),
|
2022-10-20 20:31:00 +02:00
|
|
|
std::move(speech_recognition_result), td_->file_manager_->get_file_object(file_id));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2018-09-27 03:19:03 +02:00
|
|
|
FileId VideoNotesManager::on_get_video_note(unique_ptr<VideoNote> new_video_note, bool replace) {
|
2018-12-31 20:04:05 +01:00
|
|
|
auto file_id = new_video_note->file_id;
|
2019-08-01 02:58:49 +02:00
|
|
|
CHECK(file_id.is_valid());
|
2018-01-05 16:50:35 +01:00
|
|
|
LOG(INFO) << "Receive video note " << file_id;
|
2018-12-31 20:04:05 +01:00
|
|
|
auto &v = video_notes_[file_id];
|
|
|
|
if (v == nullptr) {
|
|
|
|
v = std::move(new_video_note);
|
|
|
|
} else if (replace) {
|
|
|
|
CHECK(v->file_id == new_video_note->file_id);
|
2022-10-20 22:23:40 +02:00
|
|
|
if (v->duration != new_video_note->duration || v->dimensions != new_video_note->dimensions ||
|
|
|
|
v->waveform != new_video_note->waveform) {
|
2018-12-31 20:04:05 +01:00
|
|
|
LOG(DEBUG) << "Video note " << file_id << " info has changed";
|
|
|
|
v->duration = new_video_note->duration;
|
|
|
|
v->dimensions = new_video_note->dimensions;
|
2022-10-20 22:23:40 +02:00
|
|
|
v->waveform = std::move(new_video_note->waveform);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2019-03-01 20:51:33 +01:00
|
|
|
if (v->minithumbnail != new_video_note->minithumbnail) {
|
|
|
|
v->minithumbnail = std::move(new_video_note->minithumbnail);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
if (v->thumbnail != new_video_note->thumbnail) {
|
|
|
|
if (!v->thumbnail.file_id.is_valid()) {
|
|
|
|
LOG(DEBUG) << "Video note " << file_id << " thumbnail has changed";
|
|
|
|
} else {
|
|
|
|
LOG(INFO) << "Video note " << file_id << " thumbnail has changed from " << v->thumbnail << " to "
|
|
|
|
<< new_video_note->thumbnail;
|
|
|
|
}
|
2022-10-20 00:16:24 +02:00
|
|
|
v->thumbnail = std::move(new_video_note->thumbnail);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2022-10-20 20:31:00 +02:00
|
|
|
if (TranscriptionInfo::update_from(v->transcription_info, std::move(new_video_note->transcription_info))) {
|
|
|
|
on_video_note_transcription_completed(file_id);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
return file_id;
|
|
|
|
}
|
|
|
|
|
2022-10-20 20:31:00 +02:00
|
|
|
VideoNotesManager::VideoNote *VideoNotesManager::get_video_note(FileId file_id) {
|
|
|
|
return video_notes_.get_pointer(file_id);
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
const VideoNotesManager::VideoNote *VideoNotesManager::get_video_note(FileId file_id) const {
|
2022-08-04 09:50:34 +02:00
|
|
|
return video_notes_.get_pointer(file_id);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FileId VideoNotesManager::get_video_note_thumbnail_file_id(FileId file_id) const {
|
|
|
|
auto video_note = get_video_note(file_id);
|
|
|
|
CHECK(video_note != nullptr);
|
|
|
|
return video_note->thumbnail.file_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoNotesManager::delete_video_note_thumbnail(FileId file_id) {
|
|
|
|
auto &video_note = video_notes_[file_id];
|
|
|
|
CHECK(video_note != nullptr);
|
|
|
|
video_note->thumbnail = PhotoSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
FileId VideoNotesManager::dup_video_note(FileId new_id, FileId old_id) {
|
|
|
|
const VideoNote *old_video_note = get_video_note(old_id);
|
|
|
|
CHECK(old_video_note != nullptr);
|
|
|
|
auto &new_video_note = video_notes_[new_id];
|
2022-02-09 22:59:52 +01:00
|
|
|
CHECK(new_video_note == nullptr);
|
2022-10-20 20:31:00 +02:00
|
|
|
new_video_note = make_unique<VideoNote>();
|
2018-12-31 20:04:05 +01:00
|
|
|
new_video_note->file_id = new_id;
|
2022-10-20 20:31:00 +02:00
|
|
|
new_video_note->duration = old_video_note->duration;
|
|
|
|
new_video_note->dimensions = old_video_note->dimensions;
|
2022-10-20 22:23:40 +02:00
|
|
|
new_video_note->waveform = old_video_note->waveform;
|
2022-10-20 20:31:00 +02:00
|
|
|
new_video_note->minithumbnail = old_video_note->minithumbnail;
|
|
|
|
new_video_note->thumbnail = old_video_note->thumbnail;
|
2022-11-21 09:40:43 +01:00
|
|
|
new_video_note->thumbnail.file_id =
|
|
|
|
td_->file_manager_->dup_file_id(new_video_note->thumbnail.file_id, "dup_video_note");
|
2022-10-20 20:31:00 +02:00
|
|
|
new_video_note->transcription_info = TranscriptionInfo::copy_if_transcribed(old_video_note->transcription_info);
|
2018-12-31 20:04:05 +01:00
|
|
|
return new_id;
|
|
|
|
}
|
|
|
|
|
2022-08-03 20:38:03 +02:00
|
|
|
void VideoNotesManager::merge_video_notes(FileId new_id, FileId old_id) {
|
2021-08-26 17:50:28 +02:00
|
|
|
CHECK(old_id.is_valid() && new_id.is_valid());
|
|
|
|
CHECK(new_id != old_id);
|
2018-01-05 16:50:35 +01:00
|
|
|
|
|
|
|
LOG(INFO) << "Merge video notes " << new_id << " and " << old_id;
|
2018-12-31 20:04:05 +01:00
|
|
|
const VideoNote *old_ = get_video_note(old_id);
|
|
|
|
CHECK(old_ != nullptr);
|
|
|
|
|
2022-08-03 20:58:07 +02:00
|
|
|
const auto *new_ = get_video_note(new_id);
|
|
|
|
if (new_ == nullptr) {
|
2022-08-03 20:38:03 +02:00
|
|
|
dup_video_note(new_id, old_id);
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
|
|
|
if (old_->thumbnail != new_->thumbnail) {
|
|
|
|
// LOG_STATUS(td_->file_manager_->merge(new_->thumbnail.file_id, old_->thumbnail.file_id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOG_STATUS(td_->file_manager_->merge(new_id, old_id));
|
|
|
|
}
|
|
|
|
|
2019-03-01 20:51:33 +01:00
|
|
|
void VideoNotesManager::create_video_note(FileId file_id, string minithumbnail, PhotoSize thumbnail, int32 duration,
|
2022-10-20 22:23:40 +02:00
|
|
|
Dimensions dimensions, string waveform, bool replace) {
|
2018-12-31 20:04:05 +01:00
|
|
|
auto v = make_unique<VideoNote>();
|
|
|
|
v->file_id = file_id;
|
2018-02-12 11:37:54 +01:00
|
|
|
v->duration = max(duration, 0);
|
2018-12-31 20:04:05 +01:00
|
|
|
if (dimensions.width == dimensions.height && dimensions.width <= 640) {
|
|
|
|
v->dimensions = dimensions;
|
|
|
|
} else {
|
|
|
|
LOG(INFO) << "Receive wrong video note dimensions " << dimensions;
|
|
|
|
}
|
2022-10-20 22:23:40 +02:00
|
|
|
v->waveform = std::move(waveform);
|
2021-05-27 20:15:30 +02:00
|
|
|
if (!td_->auth_manager_->is_bot()) {
|
|
|
|
v->minithumbnail = std::move(minithumbnail);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
v->thumbnail = std::move(thumbnail);
|
|
|
|
on_get_video_note(std::move(v), replace);
|
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
void VideoNotesManager::register_video_note(FileId video_note_file_id, MessageFullId message_full_id,
|
2022-10-19 17:30:25 +02:00
|
|
|
const char *source) {
|
2023-09-21 18:11:17 +02:00
|
|
|
if (message_full_id.get_message_id().is_scheduled() || !message_full_id.get_message_id().is_server() ||
|
2022-11-12 08:51:57 +01:00
|
|
|
td_->auth_manager_->is_bot()) {
|
2022-10-19 17:30:25 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-09-21 18:11:17 +02:00
|
|
|
LOG(INFO) << "Register video note " << video_note_file_id << " from " << message_full_id << " from " << source;
|
2023-01-02 18:12:15 +01:00
|
|
|
CHECK(video_note_file_id.is_valid());
|
2023-09-21 18:11:17 +02:00
|
|
|
bool is_inserted = video_note_messages_[video_note_file_id].insert(message_full_id).second;
|
|
|
|
LOG_CHECK(is_inserted) << source << ' ' << video_note_file_id << ' ' << message_full_id;
|
|
|
|
is_inserted = message_video_notes_.emplace(message_full_id, video_note_file_id).second;
|
2022-10-19 17:30:25 +02:00
|
|
|
CHECK(is_inserted);
|
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
void VideoNotesManager::unregister_video_note(FileId video_note_file_id, MessageFullId message_full_id,
|
2022-10-19 17:30:25 +02:00
|
|
|
const char *source) {
|
2023-09-21 18:11:17 +02:00
|
|
|
if (message_full_id.get_message_id().is_scheduled() || !message_full_id.get_message_id().is_server() ||
|
2022-11-12 08:51:57 +01:00
|
|
|
td_->auth_manager_->is_bot()) {
|
2022-10-19 17:30:25 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-09-21 18:11:17 +02:00
|
|
|
LOG(INFO) << "Unregister video note " << video_note_file_id << " from " << message_full_id << " from " << source;
|
2023-01-02 18:12:15 +01:00
|
|
|
CHECK(video_note_file_id.is_valid());
|
2022-10-19 17:30:25 +02:00
|
|
|
auto &message_ids = video_note_messages_[video_note_file_id];
|
2023-09-21 18:11:17 +02:00
|
|
|
auto is_deleted = message_ids.erase(message_full_id) > 0;
|
|
|
|
LOG_CHECK(is_deleted) << source << ' ' << video_note_file_id << ' ' << message_full_id;
|
2022-10-19 17:30:25 +02:00
|
|
|
if (message_ids.empty()) {
|
|
|
|
video_note_messages_.erase(video_note_file_id);
|
|
|
|
}
|
2023-09-21 18:11:17 +02:00
|
|
|
is_deleted = message_video_notes_.erase(message_full_id) > 0;
|
2022-10-19 17:30:25 +02:00
|
|
|
CHECK(is_deleted);
|
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
void VideoNotesManager::recognize_speech(MessageFullId message_full_id, Promise<Unit> &&promise) {
|
|
|
|
auto it = message_video_notes_.find(message_full_id);
|
2022-10-20 20:31:00 +02:00
|
|
|
CHECK(it != message_video_notes_.end());
|
|
|
|
|
|
|
|
auto file_id = it->second;
|
|
|
|
auto video_note = get_video_note(file_id);
|
|
|
|
CHECK(video_note != nullptr);
|
|
|
|
if (video_note->transcription_info == nullptr) {
|
|
|
|
video_note->transcription_info = make_unique<TranscriptionInfo>();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto handler = [actor_id = actor_id(this),
|
|
|
|
file_id](Result<telegram_api::object_ptr<telegram_api::updateTranscribedAudio>> r_update) {
|
|
|
|
send_closure(actor_id, &VideoNotesManager::on_transcribed_audio_update, file_id, true, std::move(r_update));
|
|
|
|
};
|
2023-09-21 18:11:17 +02:00
|
|
|
if (video_note->transcription_info->recognize_speech(td_, message_full_id, std::move(promise), std::move(handler))) {
|
2022-10-20 20:31:00 +02:00
|
|
|
on_video_note_transcription_updated(file_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoNotesManager::on_transcribed_audio_update(
|
|
|
|
FileId file_id, bool is_initial, Result<telegram_api::object_ptr<telegram_api::updateTranscribedAudio>> r_update) {
|
|
|
|
if (G()->close_flag()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto video_note = get_video_note(file_id);
|
|
|
|
CHECK(video_note != nullptr);
|
|
|
|
CHECK(video_note->transcription_info != nullptr);
|
|
|
|
|
|
|
|
if (r_update.is_error()) {
|
2023-11-21 14:16:14 +01:00
|
|
|
auto promises = video_note->transcription_info->on_failed_transcription(r_update.move_as_error());
|
2022-10-20 20:31:00 +02:00
|
|
|
on_video_note_transcription_updated(file_id);
|
2023-11-21 14:16:14 +01:00
|
|
|
set_promises(promises);
|
2022-10-20 20:31:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto update = r_update.move_as_ok();
|
|
|
|
auto transcription_id = update->transcription_id_;
|
|
|
|
if (!update->pending_) {
|
|
|
|
auto promises = video_note->transcription_info->on_final_transcription(std::move(update->text_), transcription_id);
|
|
|
|
on_video_note_transcription_completed(file_id);
|
|
|
|
set_promises(promises);
|
|
|
|
} else {
|
|
|
|
auto is_changed =
|
|
|
|
video_note->transcription_info->on_partial_transcription(std::move(update->text_), transcription_id);
|
|
|
|
if (is_changed) {
|
|
|
|
on_video_note_transcription_updated(file_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_initial) {
|
2023-11-21 18:32:23 +01:00
|
|
|
td_->transcription_manager_->subscribe_to_transcribed_audio_updates(
|
2022-10-20 20:31:00 +02:00
|
|
|
transcription_id, [actor_id = actor_id(this),
|
|
|
|
file_id](Result<telegram_api::object_ptr<telegram_api::updateTranscribedAudio>> r_update) {
|
|
|
|
send_closure(actor_id, &VideoNotesManager::on_transcribed_audio_update, file_id, false,
|
|
|
|
std::move(r_update));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoNotesManager::on_video_note_transcription_updated(FileId file_id) {
|
|
|
|
auto it = video_note_messages_.find(file_id);
|
|
|
|
if (it != video_note_messages_.end()) {
|
2023-09-21 18:11:17 +02:00
|
|
|
for (const auto &message_full_id : it->second) {
|
|
|
|
td_->messages_manager_->on_external_update_message_content(message_full_id);
|
2022-10-20 20:31:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoNotesManager::on_video_note_transcription_completed(FileId file_id) {
|
|
|
|
auto it = video_note_messages_.find(file_id);
|
|
|
|
if (it != video_note_messages_.end()) {
|
2023-09-21 18:11:17 +02:00
|
|
|
for (const auto &message_full_id : it->second) {
|
|
|
|
td_->messages_manager_->on_update_message_content(message_full_id);
|
2022-10-20 20:31:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
void VideoNotesManager::rate_speech_recognition(MessageFullId message_full_id, bool is_good, Promise<Unit> &&promise) {
|
|
|
|
auto it = message_video_notes_.find(message_full_id);
|
2022-10-20 20:31:00 +02:00
|
|
|
CHECK(it != message_video_notes_.end());
|
|
|
|
|
|
|
|
auto file_id = it->second;
|
|
|
|
auto video_note = get_video_note(file_id);
|
|
|
|
CHECK(video_note != nullptr);
|
|
|
|
if (video_note->transcription_info == nullptr) {
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
2023-09-21 18:11:17 +02:00
|
|
|
video_note->transcription_info->rate_speech_recognition(td_, message_full_id, is_good, std::move(promise));
|
2022-10-20 20:31:00 +02:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
SecretInputMedia VideoNotesManager::get_secret_input_media(FileId video_note_file_id,
|
|
|
|
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
|
2022-05-11 06:46:06 +02:00
|
|
|
BufferSlice thumbnail, int32 layer) const {
|
2018-12-31 20:04:05 +01:00
|
|
|
const VideoNote *video_note = get_video_note(video_note_file_id);
|
|
|
|
CHECK(video_note != nullptr);
|
|
|
|
auto file_view = td_->file_manager_->get_file_view(video_note_file_id);
|
2022-05-11 00:53:18 +02:00
|
|
|
if (!file_view.is_encrypted_secret() || file_view.encryption_key().empty()) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return SecretInputMedia{};
|
|
|
|
}
|
|
|
|
if (file_view.has_remote_location()) {
|
2019-11-17 20:41:28 +01:00
|
|
|
input_file = file_view.main_remote_location().as_input_encrypted_file();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (!input_file) {
|
|
|
|
return SecretInputMedia{};
|
|
|
|
}
|
|
|
|
if (video_note->thumbnail.file_id.is_valid() && thumbnail.empty()) {
|
|
|
|
return SecretInputMedia{};
|
|
|
|
}
|
|
|
|
vector<tl_object_ptr<secret_api::DocumentAttribute>> attributes;
|
2022-09-28 11:17:04 +02:00
|
|
|
attributes.push_back(make_tl_object<secret_api::documentAttributeVideo>(
|
|
|
|
secret_api::documentAttributeVideo::ROUND_MESSAGE_MASK, true, video_note->duration, video_note->dimensions.width,
|
|
|
|
video_note->dimensions.height));
|
2022-05-11 00:53:18 +02:00
|
|
|
|
|
|
|
return {std::move(input_file),
|
|
|
|
std::move(thumbnail),
|
|
|
|
video_note->thumbnail.dimensions,
|
|
|
|
"video/mp4",
|
|
|
|
file_view,
|
|
|
|
std::move(attributes),
|
2022-05-11 06:46:06 +02:00
|
|
|
string(),
|
|
|
|
layer};
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::InputMedia> VideoNotesManager::get_input_media(
|
|
|
|
FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file,
|
|
|
|
tl_object_ptr<telegram_api::InputFile> input_thumbnail) const {
|
|
|
|
auto file_view = td_->file_manager_->get_file_view(file_id);
|
|
|
|
if (file_view.is_encrypted()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-11-17 20:41:28 +01:00
|
|
|
if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) {
|
2022-12-08 18:58:37 +01:00
|
|
|
return make_tl_object<telegram_api::inputMediaDocument>(
|
|
|
|
0, false /*ignored*/, file_view.main_remote_location().as_input_document(), 0, string());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (file_view.has_url()) {
|
2022-12-08 18:58:37 +01:00
|
|
|
return make_tl_object<telegram_api::inputMediaDocumentExternal>(0, false /*ignored*/, file_view.url(), 0);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (input_file != nullptr) {
|
|
|
|
const VideoNote *video_note = get_video_note(file_id);
|
|
|
|
CHECK(video_note != nullptr);
|
|
|
|
|
|
|
|
vector<tl_object_ptr<telegram_api::DocumentAttribute>> attributes;
|
2022-10-20 23:10:43 +02:00
|
|
|
auto suggested_video_note_length =
|
|
|
|
narrow_cast<int32>(td_->option_manager_->get_option_integer("suggested_video_note_length", 384));
|
2018-12-31 20:04:05 +01:00
|
|
|
attributes.push_back(make_tl_object<telegram_api::documentAttributeVideo>(
|
2018-02-07 00:31:38 +01:00
|
|
|
telegram_api::documentAttributeVideo::ROUND_MESSAGE_MASK, false /*ignored*/, false /*ignored*/,
|
2023-05-01 20:07:01 +02:00
|
|
|
false /*ignored*/, video_note->duration,
|
|
|
|
video_note->dimensions.width ? video_note->dimensions.width : suggested_video_note_length,
|
|
|
|
video_note->dimensions.height ? video_note->dimensions.height : suggested_video_note_length, 0));
|
2021-08-01 06:40:57 +02:00
|
|
|
int32 flags = telegram_api::inputMediaUploadedDocument::NOSOUND_VIDEO_MASK;
|
2018-12-31 20:04:05 +01:00
|
|
|
if (input_thumbnail != nullptr) {
|
|
|
|
flags |= telegram_api::inputMediaUploadedDocument::THUMB_MASK;
|
|
|
|
}
|
|
|
|
return make_tl_object<telegram_api::inputMediaUploadedDocument>(
|
2022-12-08 18:58:37 +01:00
|
|
|
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, std::move(input_file),
|
|
|
|
std::move(input_thumbnail), "video/mp4", std::move(attributes),
|
|
|
|
vector<tl_object_ptr<telegram_api::InputDocument>>(), 0);
|
2019-02-12 02:50:30 +01:00
|
|
|
} else {
|
|
|
|
CHECK(!file_view.has_remote_location());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|