Simplify SecretInputMedia creation.
This commit is contained in:
parent
35a0a7c383
commit
f9f309d334
@ -412,6 +412,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/SecretChatActor.cpp
|
||||
td/telegram/SecretChatDb.cpp
|
||||
td/telegram/SecretChatsManager.cpp
|
||||
td/telegram/SecretInputMedia.cpp
|
||||
td/telegram/SecureManager.cpp
|
||||
td/telegram/SecureStorage.cpp
|
||||
td/telegram/SecureValue.cpp
|
||||
|
@ -388,8 +388,7 @@ SecretInputMedia AnimationsManager::get_secret_input_media(FileId animation_file
|
||||
auto *animation = get_animation(animation_file_id);
|
||||
CHECK(animation != nullptr);
|
||||
auto file_view = td_->file_manager_->get_file_view(animation_file_id);
|
||||
auto &encryption_key = file_view.encryption_key();
|
||||
if (!file_view.is_encrypted_secret() || encryption_key.empty()) {
|
||||
if (!file_view.is_encrypted_secret() || file_view.encryption_key().empty()) {
|
||||
return SecretInputMedia{};
|
||||
}
|
||||
if (file_view.has_remote_location()) {
|
||||
@ -415,12 +414,13 @@ SecretInputMedia AnimationsManager::get_secret_input_media(FileId animation_file
|
||||
}
|
||||
attributes.push_back(make_tl_object<secret_api::documentAttributeAnimated>());
|
||||
|
||||
return SecretInputMedia{
|
||||
std::move(input_file),
|
||||
make_tl_object<secret_api::decryptedMessageMediaDocument>(
|
||||
std::move(thumbnail), animation->thumbnail.dimensions.width, animation->thumbnail.dimensions.height,
|
||||
animation->mime_type, narrow_cast<int32>(file_view.size()), BufferSlice(encryption_key.key_slice()),
|
||||
BufferSlice(encryption_key.iv_slice()), std::move(attributes), caption)};
|
||||
return {std::move(input_file),
|
||||
std::move(thumbnail),
|
||||
animation->thumbnail.dimensions,
|
||||
animation->mime_type,
|
||||
file_view,
|
||||
std::move(attributes),
|
||||
caption};
|
||||
}
|
||||
|
||||
void AnimationsManager::on_update_animation_search_emojis(string animation_search_emojis) {
|
||||
|
@ -210,8 +210,7 @@ SecretInputMedia AudiosManager::get_secret_input_media(FileId audio_file_id,
|
||||
auto *audio = get_audio(audio_file_id);
|
||||
CHECK(audio != nullptr);
|
||||
auto file_view = td_->file_manager_->get_file_view(audio_file_id);
|
||||
auto &encryption_key = file_view.encryption_key();
|
||||
if (!file_view.is_encrypted_secret() || encryption_key.empty()) {
|
||||
if (!file_view.is_encrypted_secret() || file_view.encryption_key().empty()) {
|
||||
return SecretInputMedia{};
|
||||
}
|
||||
if (file_view.has_remote_location()) {
|
||||
@ -231,12 +230,13 @@ SecretInputMedia AudiosManager::get_secret_input_media(FileId audio_file_id,
|
||||
secret_api::documentAttributeAudio::TITLE_MASK | secret_api::documentAttributeAudio::PERFORMER_MASK,
|
||||
false /*ignored*/, audio->duration, audio->title, audio->performer, BufferSlice()));
|
||||
|
||||
return SecretInputMedia{
|
||||
std::move(input_file),
|
||||
make_tl_object<secret_api::decryptedMessageMediaDocument>(
|
||||
std::move(thumbnail), audio->thumbnail.dimensions.width, audio->thumbnail.dimensions.height, audio->mime_type,
|
||||
narrow_cast<int32>(file_view.size()), BufferSlice(encryption_key.key_slice()),
|
||||
BufferSlice(encryption_key.iv_slice()), std::move(attributes), caption)};
|
||||
return {std::move(input_file),
|
||||
std::move(thumbnail),
|
||||
audio->thumbnail.dimensions,
|
||||
audio->mime_type,
|
||||
file_view,
|
||||
std::move(attributes),
|
||||
caption};
|
||||
}
|
||||
|
||||
tl_object_ptr<telegram_api::InputMedia> AudiosManager::get_input_media(
|
||||
|
@ -593,8 +593,7 @@ SecretInputMedia DocumentsManager::get_secret_input_media(FileId document_file_i
|
||||
const GeneralDocument *document = get_document(document_file_id);
|
||||
CHECK(document != nullptr);
|
||||
auto file_view = td_->file_manager_->get_file_view(document_file_id);
|
||||
auto &encryption_key = file_view.encryption_key();
|
||||
if (!file_view.is_encrypted_secret() || encryption_key.empty()) {
|
||||
if (!file_view.is_encrypted_secret() || file_view.encryption_key().empty()) {
|
||||
return SecretInputMedia{};
|
||||
}
|
||||
if (file_view.has_remote_location()) {
|
||||
@ -610,12 +609,13 @@ SecretInputMedia DocumentsManager::get_secret_input_media(FileId document_file_i
|
||||
if (!document->file_name.empty()) {
|
||||
attributes.push_back(make_tl_object<secret_api::documentAttributeFilename>(document->file_name));
|
||||
}
|
||||
return SecretInputMedia{
|
||||
std::move(input_file),
|
||||
make_tl_object<secret_api::decryptedMessageMediaDocument>(
|
||||
std::move(thumbnail), document->thumbnail.dimensions.width, document->thumbnail.dimensions.height,
|
||||
document->mime_type, narrow_cast<int32>(file_view.size()), BufferSlice(encryption_key.key_slice()),
|
||||
BufferSlice(encryption_key.iv_slice()), std::move(attributes), caption)};
|
||||
return {std::move(input_file),
|
||||
std::move(thumbnail),
|
||||
document->thumbnail.dimensions,
|
||||
document->mime_type,
|
||||
file_view,
|
||||
std::move(attributes),
|
||||
caption};
|
||||
}
|
||||
|
||||
tl_object_ptr<telegram_api::InputMedia> DocumentsManager::get_input_media(
|
||||
|
25
td/telegram/SecretInputMedia.cpp
Normal file
25
td/telegram/SecretInputMedia.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
||||
//
|
||||
// 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/SecretInputMedia.h"
|
||||
|
||||
#include "td/telegram/files/FileManager.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
SecretInputMedia::SecretInputMedia(tl_object_ptr<telegram_api::InputEncryptedFile> input_file, BufferSlice &&thumbnail,
|
||||
Dimensions thumbnail_dimensions, const string &mime_type, const FileView &file_view,
|
||||
vector<tl_object_ptr<secret_api::DocumentAttribute>> &&attributes,
|
||||
const string &caption)
|
||||
: input_file_(std::move(input_file)) {
|
||||
auto &encryption_key = file_view.encryption_key();
|
||||
decrypted_media_ = secret_api::make_object<secret_api::decryptedMessageMediaDocument>(
|
||||
std::move(thumbnail), thumbnail_dimensions.width, thumbnail_dimensions.height, mime_type,
|
||||
narrow_cast<int32>(file_view.size()), BufferSlice(encryption_key.key_slice()),
|
||||
BufferSlice(encryption_key.iv_slice()), std::move(attributes), caption);
|
||||
}
|
||||
|
||||
} // namespace td
|
@ -6,11 +6,17 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/PhotoSize.h"
|
||||
#include "td/telegram/secret_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/common.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
class FileView;
|
||||
|
||||
struct SecretInputMedia {
|
||||
tl_object_ptr<telegram_api::InputEncryptedFile> input_file_;
|
||||
tl_object_ptr<secret_api::DecryptedMessageMedia> decrypted_media_;
|
||||
@ -22,6 +28,10 @@ struct SecretInputMedia {
|
||||
: input_file_(std::move(input_file)), decrypted_media_(std::move(decrypted_media)) {
|
||||
}
|
||||
|
||||
SecretInputMedia(tl_object_ptr<telegram_api::InputEncryptedFile> input_file, BufferSlice &&thumbnail,
|
||||
Dimensions thumbnail_dimensions, const string &mime_type, const FileView &file_view,
|
||||
vector<tl_object_ptr<secret_api::DocumentAttribute>> &&attributes, const string &caption);
|
||||
|
||||
bool empty() const {
|
||||
return decrypted_media_ == nullptr;
|
||||
}
|
||||
|
@ -2748,13 +2748,13 @@ SecretInputMedia StickersManager::get_secret_input_media(FileId sticker_file_id,
|
||||
}
|
||||
|
||||
if (file_view.is_encrypted_secret()) {
|
||||
auto &encryption_key = file_view.encryption_key();
|
||||
return SecretInputMedia{std::move(input_file),
|
||||
make_tl_object<secret_api::decryptedMessageMediaDocument>(
|
||||
std::move(thumbnail), sticker->s_thumbnail.dimensions.width,
|
||||
sticker->s_thumbnail.dimensions.height, get_sticker_format_mime_type(sticker->format),
|
||||
narrow_cast<int32>(file_view.size()), BufferSlice(encryption_key.key_slice()),
|
||||
BufferSlice(encryption_key.iv_slice()), std::move(attributes), "")};
|
||||
return {std::move(input_file),
|
||||
std::move(thumbnail),
|
||||
sticker->s_thumbnail.dimensions,
|
||||
get_sticker_format_mime_type(sticker->format),
|
||||
file_view,
|
||||
std::move(attributes),
|
||||
string()};
|
||||
} else {
|
||||
CHECK(!file_view.is_encrypted());
|
||||
auto &remote_location = file_view.remote_location();
|
||||
|
@ -159,8 +159,7 @@ SecretInputMedia VideoNotesManager::get_secret_input_media(FileId video_note_fil
|
||||
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);
|
||||
auto &encryption_key = file_view.encryption_key();
|
||||
if (!file_view.is_encrypted_secret() || encryption_key.empty()) {
|
||||
if (!file_view.is_encrypted_secret() || file_view.encryption_key().empty()) {
|
||||
return SecretInputMedia{};
|
||||
}
|
||||
if (file_view.has_remote_location()) {
|
||||
@ -176,12 +175,14 @@ SecretInputMedia VideoNotesManager::get_secret_input_media(FileId video_note_fil
|
||||
attributes.push_back(make_tl_object<secret_api::documentAttributeVideo66>(
|
||||
secret_api::documentAttributeVideo66::ROUND_MESSAGE_MASK, true, video_note->duration,
|
||||
video_note->dimensions.width, video_note->dimensions.height));
|
||||
return SecretInputMedia{
|
||||
std::move(input_file),
|
||||
make_tl_object<secret_api::decryptedMessageMediaDocument>(
|
||||
std::move(thumbnail), video_note->thumbnail.dimensions.width, video_note->thumbnail.dimensions.height,
|
||||
"video/mp4", narrow_cast<int32>(file_view.size()), BufferSlice(encryption_key.key_slice()),
|
||||
BufferSlice(encryption_key.iv_slice()), std::move(attributes), "")};
|
||||
|
||||
return {std::move(input_file),
|
||||
std::move(thumbnail),
|
||||
video_note->thumbnail.dimensions,
|
||||
"video/mp4",
|
||||
file_view,
|
||||
std::move(attributes),
|
||||
string()};
|
||||
}
|
||||
|
||||
tl_object_ptr<telegram_api::InputMedia> VideoNotesManager::get_input_media(
|
||||
|
@ -205,8 +205,7 @@ SecretInputMedia VideosManager::get_secret_input_media(FileId video_file_id,
|
||||
const Video *video = get_video(video_file_id);
|
||||
CHECK(video != nullptr);
|
||||
auto file_view = td_->file_manager_->get_file_view(video_file_id);
|
||||
auto &encryption_key = file_view.encryption_key();
|
||||
if (!file_view.is_encrypted_secret() || encryption_key.empty()) {
|
||||
if (!file_view.is_encrypted_secret() || file_view.encryption_key().empty()) {
|
||||
return SecretInputMedia{};
|
||||
}
|
||||
if (file_view.has_remote_location()) {
|
||||
@ -218,12 +217,17 @@ SecretInputMedia VideosManager::get_secret_input_media(FileId video_file_id,
|
||||
if (video->thumbnail.file_id.is_valid() && thumbnail.empty()) {
|
||||
return {};
|
||||
}
|
||||
return SecretInputMedia{
|
||||
std::move(input_file),
|
||||
make_tl_object<secret_api::decryptedMessageMediaVideo>(
|
||||
std::move(thumbnail), video->thumbnail.dimensions.width, video->thumbnail.dimensions.height, video->duration,
|
||||
video->mime_type, video->dimensions.width, video->dimensions.height, narrow_cast<int32>(file_view.size()),
|
||||
BufferSlice(encryption_key.key_slice()), BufferSlice(encryption_key.iv_slice()), caption)};
|
||||
vector<tl_object_ptr<secret_api::DocumentAttribute>> attributes;
|
||||
attributes.emplace_back(make_tl_object<secret_api::documentAttributeVideo>(video->duration, video->dimensions.width,
|
||||
video->dimensions.height));
|
||||
|
||||
return {std::move(input_file),
|
||||
std::move(thumbnail),
|
||||
video->thumbnail.dimensions,
|
||||
video->mime_type,
|
||||
file_view,
|
||||
std::move(attributes),
|
||||
caption};
|
||||
}
|
||||
|
||||
tl_object_ptr<telegram_api::InputMedia> VideosManager::get_input_media(
|
||||
|
@ -133,8 +133,7 @@ SecretInputMedia VoiceNotesManager::get_secret_input_media(FileId voice_file_id,
|
||||
auto *voice_note = get_voice_note(voice_file_id);
|
||||
CHECK(voice_note != nullptr);
|
||||
auto file_view = td_->file_manager_->get_file_view(voice_file_id);
|
||||
auto &encryption_key = file_view.encryption_key();
|
||||
if (!file_view.is_encrypted_secret() || encryption_key.empty()) {
|
||||
if (!file_view.is_encrypted_secret() || file_view.encryption_key().empty()) {
|
||||
return SecretInputMedia{};
|
||||
}
|
||||
if (file_view.has_remote_location()) {
|
||||
@ -147,11 +146,9 @@ SecretInputMedia VoiceNotesManager::get_secret_input_media(FileId voice_file_id,
|
||||
attributes.push_back(make_tl_object<secret_api::documentAttributeAudio>(
|
||||
secret_api::documentAttributeAudio::VOICE_MASK | secret_api::documentAttributeAudio::WAVEFORM_MASK,
|
||||
false /*ignored*/, voice_note->duration, "", "", BufferSlice(voice_note->waveform)));
|
||||
return SecretInputMedia{std::move(input_file),
|
||||
make_tl_object<secret_api::decryptedMessageMediaDocument>(
|
||||
BufferSlice(), 0, 0, voice_note->mime_type, narrow_cast<int32>(file_view.size()),
|
||||
BufferSlice(encryption_key.key_slice()), BufferSlice(encryption_key.iv_slice()),
|
||||
std::move(attributes), caption)};
|
||||
|
||||
return {std::move(input_file), BufferSlice(), Dimensions(), voice_note->mime_type, file_view,
|
||||
std::move(attributes), caption};
|
||||
}
|
||||
|
||||
tl_object_ptr<telegram_api::InputMedia> VoiceNotesManager::get_input_media(
|
||||
|
Loading…
Reference in New Issue
Block a user