Allow to send self-destructing video notes and voice notes.

This commit is contained in:
levlam 2024-01-02 14:51:16 +03:00
parent 139b61e4b6
commit 052f6cb20c
8 changed files with 69 additions and 36 deletions

View File

@ -3125,7 +3125,6 @@ inputMessageDocument document:InputFile thumbnail:inputThumbnail disable_content
//@has_spoiler True, if the photo preview must be covered by a spoiler animation; not supported in secret chats //@has_spoiler True, if the photo preview must be covered by a spoiler animation; not supported in secret chats
inputMessagePhoto photo:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> width:int32 height:int32 caption:formattedText self_destruct_type:MessageSelfDestructType has_spoiler:Bool = InputMessageContent; inputMessagePhoto photo:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> width:int32 height:int32 caption:formattedText self_destruct_type:MessageSelfDestructType has_spoiler:Bool = InputMessageContent;
//@description A sticker message //@description A sticker message
//@sticker Sticker to be sent //@sticker Sticker to be sent
//@thumbnail Sticker thumbnail; pass null to skip thumbnail uploading //@thumbnail Sticker thumbnail; pass null to skip thumbnail uploading
@ -3152,14 +3151,16 @@ inputMessageVideo video:InputFile thumbnail:inputThumbnail added_sticker_file_id
//@thumbnail Video thumbnail; pass null to skip thumbnail uploading //@thumbnail Video thumbnail; pass null to skip thumbnail uploading
//@duration Duration of the video, in seconds //@duration Duration of the video, in seconds
//@length Video width and height; must be positive and not greater than 640 //@length Video width and height; must be positive and not greater than 640
inputMessageVideoNote video_note:InputFile thumbnail:inputThumbnail duration:int32 length:int32 = InputMessageContent; //@self_destruct_type Video note self-destruct type; pass null if none; private chats only
inputMessageVideoNote video_note:InputFile thumbnail:inputThumbnail duration:int32 length:int32 self_destruct_type:MessageSelfDestructType = InputMessageContent;
//@description A voice note message //@description A voice note message
//@voice_note Voice note to be sent //@voice_note Voice note to be sent
//@duration Duration of the voice note, in seconds //@duration Duration of the voice note, in seconds
//@waveform Waveform representation of the voice note in 5-bit format //@waveform Waveform representation of the voice note in 5-bit format
//@caption Voice note caption; pass null to use an empty caption; 0-getOption("message_caption_length_max") characters //@caption Voice note caption; pass null to use an empty caption; 0-getOption("message_caption_length_max") characters
inputMessageVoiceNote voice_note:InputFile duration:int32 waveform:bytes caption:formattedText = InputMessageContent; //@self_destruct_type Voice note self-destruct type; pass null if none; private chats only
inputMessageVoiceNote voice_note:InputFile duration:int32 waveform:bytes caption:formattedText self_destruct_type:MessageSelfDestructType = InputMessageContent;
//@description A message with a location //@description A message with a location
//@location Location to be sent //@location Location to be sent

View File

@ -2678,6 +2678,7 @@ static Result<InputMessageContent> create_input_message_content(
} }
case td_api::inputMessageVideoNote::ID: { case td_api::inputMessageVideoNote::ID: {
auto input_video_note = static_cast<td_api::inputMessageVideoNote *>(input_message_content.get()); auto input_video_note = static_cast<td_api::inputMessageVideoNote *>(input_message_content.get());
self_destruct_type = std::move(input_video_note->self_destruct_type_);
auto length = input_video_note->length_; auto length = input_video_note->length_;
if (length < 0 || length >= 640) { if (length < 0 || length >= 640) {
@ -2692,6 +2693,7 @@ static Result<InputMessageContent> create_input_message_content(
} }
case td_api::inputMessageVoiceNote::ID: { case td_api::inputMessageVoiceNote::ID: {
auto input_voice_note = static_cast<td_api::inputMessageVoiceNote *>(input_message_content.get()); auto input_voice_note = static_cast<td_api::inputMessageVoiceNote *>(input_message_content.get());
self_destruct_type = std::move(input_voice_note->self_destruct_type_);
td->voice_notes_manager_->create_voice_note(file_id, std::move(mime_type), input_voice_note->duration_, td->voice_notes_manager_->create_voice_note(file_id, std::move(mime_type), input_voice_note->duration_,
std::move(input_voice_note->waveform_), false); std::move(input_voice_note->waveform_), false);
@ -2833,7 +2835,7 @@ static Result<InputMessageContent> create_input_message_content(
} }
if (self_destruct_type != nullptr && dialog_id.get_type() != DialogType::User) { if (self_destruct_type != nullptr && dialog_id.get_type() != DialogType::User) {
return Status::Error(400, "Messages can self-destruct only in can be specified only in private chats"); return Status::Error(400, "Messages can self-destruct only in private chats");
} }
int32 ttl = 0; int32 ttl = 0;
if (self_destruct_type != nullptr) { if (self_destruct_type != nullptr) {
@ -3249,11 +3251,12 @@ static tl_object_ptr<telegram_api::InputMedia> get_input_media_impl(
} }
case MessageContentType::VideoNote: { case MessageContentType::VideoNote: {
const auto *m = static_cast<const MessageVideoNote *>(content); const auto *m = static_cast<const MessageVideoNote *>(content);
return td->video_notes_manager_->get_input_media(m->file_id, std::move(input_file), std::move(input_thumbnail)); return td->video_notes_manager_->get_input_media(m->file_id, std::move(input_file), std::move(input_thumbnail),
ttl);
} }
case MessageContentType::VoiceNote: { case MessageContentType::VoiceNote: {
const auto *m = static_cast<const MessageVoiceNote *>(content); const auto *m = static_cast<const MessageVoiceNote *>(content);
return td->voice_notes_manager_->get_input_media(m->file_id, std::move(input_file)); return td->voice_notes_manager_->get_input_media(m->file_id, std::move(input_file), ttl);
} }
case MessageContentType::Text: case MessageContentType::Text:
case MessageContentType::Unsupported: case MessageContentType::Unsupported:

View File

@ -211,17 +211,25 @@ SecretInputMedia VideoNotesManager::get_secret_input_media(FileId video_note_fil
tl_object_ptr<telegram_api::InputMedia> VideoNotesManager::get_input_media( tl_object_ptr<telegram_api::InputMedia> VideoNotesManager::get_input_media(
FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file, FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file,
tl_object_ptr<telegram_api::InputFile> input_thumbnail) const { tl_object_ptr<telegram_api::InputFile> input_thumbnail, int32 ttl) const {
auto file_view = td_->file_manager_->get_file_view(file_id); auto file_view = td_->file_manager_->get_file_view(file_id);
if (file_view.is_encrypted()) { if (file_view.is_encrypted()) {
return nullptr; return nullptr;
} }
if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) { if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) {
int32 flags = 0;
if (ttl != 0) {
flags |= telegram_api::inputMediaDocument::TTL_SECONDS_MASK;
}
return make_tl_object<telegram_api::inputMediaDocument>( return make_tl_object<telegram_api::inputMediaDocument>(
0, false /*ignored*/, file_view.main_remote_location().as_input_document(), 0, string()); flags, false /*ignored*/, file_view.main_remote_location().as_input_document(), ttl, string());
} }
if (file_view.has_url()) { if (file_view.has_url()) {
return make_tl_object<telegram_api::inputMediaDocumentExternal>(0, false /*ignored*/, file_view.url(), 0); int32 flags = 0;
if (ttl != 0) {
flags |= telegram_api::inputMediaDocumentExternal::TTL_SECONDS_MASK;
}
return make_tl_object<telegram_api::inputMediaDocumentExternal>(flags, false /*ignored*/, file_view.url(), ttl);
} }
if (input_file != nullptr) { if (input_file != nullptr) {
@ -237,13 +245,16 @@ tl_object_ptr<telegram_api::InputMedia> VideoNotesManager::get_input_media(
video_note->dimensions.width ? video_note->dimensions.width : suggested_video_note_length, 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)); video_note->dimensions.height ? video_note->dimensions.height : suggested_video_note_length, 0));
int32 flags = telegram_api::inputMediaUploadedDocument::NOSOUND_VIDEO_MASK; int32 flags = telegram_api::inputMediaUploadedDocument::NOSOUND_VIDEO_MASK;
if (ttl != 0) {
flags |= telegram_api::inputMediaUploadedDocument::TTL_SECONDS_MASK;
}
if (input_thumbnail != nullptr) { if (input_thumbnail != nullptr) {
flags |= telegram_api::inputMediaUploadedDocument::THUMB_MASK; flags |= telegram_api::inputMediaUploadedDocument::THUMB_MASK;
} }
return make_tl_object<telegram_api::inputMediaUploadedDocument>( return make_tl_object<telegram_api::inputMediaUploadedDocument>(
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, std::move(input_file), flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, std::move(input_file),
std::move(input_thumbnail), "video/mp4", std::move(attributes), std::move(input_thumbnail), "video/mp4", std::move(attributes),
vector<tl_object_ptr<telegram_api::InputDocument>>(), 0); vector<tl_object_ptr<telegram_api::InputDocument>>(), ttl);
} else { } else {
CHECK(!file_view.has_remote_location()); CHECK(!file_view.has_remote_location());
} }

View File

@ -44,7 +44,8 @@ class VideoNotesManager final : public Actor {
tl_object_ptr<telegram_api::InputMedia> get_input_media(FileId file_id, tl_object_ptr<telegram_api::InputMedia> get_input_media(FileId file_id,
tl_object_ptr<telegram_api::InputFile> input_file, tl_object_ptr<telegram_api::InputFile> input_file,
tl_object_ptr<telegram_api::InputFile> input_thumbnail) const; tl_object_ptr<telegram_api::InputFile> input_thumbnail,
int32 ttl) const;
SecretInputMedia get_secret_input_media(FileId video_note_file_id, SecretInputMedia get_secret_input_media(FileId video_note_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file, tl_object_ptr<telegram_api::InputEncryptedFile> input_file,

View File

@ -281,6 +281,8 @@ tl_object_ptr<telegram_api::InputMedia> VideosManager::get_input_media(
const Video *video = get_video(file_id); const Video *video = get_video(file_id);
CHECK(video != nullptr); CHECK(video != nullptr);
vector<tl_object_ptr<telegram_api::DocumentAttribute>> attributes;
{
int32 attribute_flags = 0; int32 attribute_flags = 0;
if (video->supports_streaming) { if (video->supports_streaming) {
attribute_flags |= telegram_api::documentAttributeVideo::SUPPORTS_STREAMING_MASK; attribute_flags |= telegram_api::documentAttributeVideo::SUPPORTS_STREAMING_MASK;
@ -288,11 +290,10 @@ tl_object_ptr<telegram_api::InputMedia> VideosManager::get_input_media(
if (video->is_animation) { if (video->is_animation) {
attribute_flags |= telegram_api::documentAttributeVideo::NOSOUND_MASK; attribute_flags |= telegram_api::documentAttributeVideo::NOSOUND_MASK;
} }
vector<tl_object_ptr<telegram_api::DocumentAttribute>> attributes;
attributes.push_back(make_tl_object<telegram_api::documentAttributeVideo>( attributes.push_back(make_tl_object<telegram_api::documentAttributeVideo>(
attribute_flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, video->precise_duration, attribute_flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, video->precise_duration,
video->dimensions.width, video->dimensions.height, 0)); video->dimensions.width, video->dimensions.height, 0));
}
if (!video->file_name.empty()) { if (!video->file_name.empty()) {
attributes.push_back(make_tl_object<telegram_api::documentAttributeFilename>(video->file_name)); attributes.push_back(make_tl_object<telegram_api::documentAttributeFilename>(video->file_name));
} }

View File

@ -167,17 +167,25 @@ SecretInputMedia VoiceNotesManager::get_secret_input_media(FileId voice_note_fil
} }
tl_object_ptr<telegram_api::InputMedia> VoiceNotesManager::get_input_media( tl_object_ptr<telegram_api::InputMedia> VoiceNotesManager::get_input_media(
FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file) const { FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file, int32 ttl) const {
auto file_view = td_->file_manager_->get_file_view(file_id); auto file_view = td_->file_manager_->get_file_view(file_id);
if (file_view.is_encrypted()) { if (file_view.is_encrypted()) {
return nullptr; return nullptr;
} }
if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) { if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) {
int32 flags = 0;
if (ttl != 0) {
flags |= telegram_api::inputMediaDocument::TTL_SECONDS_MASK;
}
return make_tl_object<telegram_api::inputMediaDocument>( return make_tl_object<telegram_api::inputMediaDocument>(
0, false /*ignored*/, file_view.main_remote_location().as_input_document(), 0, string()); flags, false /*ignored*/, file_view.main_remote_location().as_input_document(), ttl, string());
} }
if (file_view.has_url()) { if (file_view.has_url()) {
return make_tl_object<telegram_api::inputMediaDocumentExternal>(0, false /*ignored*/, file_view.url(), 0); int32 flags = 0;
if (ttl != 0) {
flags |= telegram_api::inputMediaDocumentExternal::TTL_SECONDS_MASK;
}
return make_tl_object<telegram_api::inputMediaDocumentExternal>(flags, false /*ignored*/, file_view.url(), ttl);
} }
if (input_file != nullptr) { if (input_file != nullptr) {
@ -185,19 +193,25 @@ tl_object_ptr<telegram_api::InputMedia> VoiceNotesManager::get_input_media(
CHECK(voice_note != nullptr); CHECK(voice_note != nullptr);
vector<tl_object_ptr<telegram_api::DocumentAttribute>> attributes; vector<tl_object_ptr<telegram_api::DocumentAttribute>> attributes;
{
int32 flags = telegram_api::documentAttributeAudio::VOICE_MASK; int32 flags = telegram_api::documentAttributeAudio::VOICE_MASK;
if (!voice_note->waveform.empty()) { if (!voice_note->waveform.empty()) {
flags |= telegram_api::documentAttributeAudio::WAVEFORM_MASK; flags |= telegram_api::documentAttributeAudio::WAVEFORM_MASK;
} }
attributes.push_back(make_tl_object<telegram_api::documentAttributeAudio>( attributes.push_back(make_tl_object<telegram_api::documentAttributeAudio>(
flags, false /*ignored*/, voice_note->duration, "", "", BufferSlice(voice_note->waveform))); flags, false /*ignored*/, voice_note->duration, "", "", BufferSlice(voice_note->waveform)));
}
string mime_type = voice_note->mime_type; string mime_type = voice_note->mime_type;
if (mime_type != "audio/ogg" && mime_type != "audio/mpeg" && mime_type != "audio/mp4") { if (mime_type != "audio/ogg" && mime_type != "audio/mpeg" && mime_type != "audio/mp4") {
mime_type = "audio/ogg"; mime_type = "audio/ogg";
} }
int32 flags = 0;
if (ttl != 0) {
flags |= telegram_api::inputMediaUploadedDocument::TTL_SECONDS_MASK;
}
return make_tl_object<telegram_api::inputMediaUploadedDocument>( return make_tl_object<telegram_api::inputMediaUploadedDocument>(
0, false /*ignored*/, false /*ignored*/, false /*ignored*/, std::move(input_file), nullptr, mime_type, flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, std::move(input_file), nullptr, mime_type,
std::move(attributes), vector<tl_object_ptr<telegram_api::InputDocument>>(), 0); std::move(attributes), vector<tl_object_ptr<telegram_api::InputDocument>>(), ttl);
} else { } else {
CHECK(!file_view.has_remote_location()); CHECK(!file_view.has_remote_location());
} }

View File

@ -39,7 +39,8 @@ class VoiceNotesManager final : public Actor {
void create_voice_note(FileId file_id, string mime_type, int32 duration, string waveform, bool replace); void create_voice_note(FileId file_id, string mime_type, int32 duration, string waveform, bool replace);
tl_object_ptr<telegram_api::InputMedia> get_input_media(FileId file_id, tl_object_ptr<telegram_api::InputMedia> get_input_media(FileId file_id,
tl_object_ptr<telegram_api::InputFile> input_file) const; tl_object_ptr<telegram_api::InputFile> input_file,
int32 ttl) const;
SecretInputMedia get_secret_input_media(FileId voice_note_file_id, SecretInputMedia get_secret_input_media(FileId voice_note_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file, tl_object_ptr<telegram_api::InputEncryptedFile> input_file,

View File

@ -4904,7 +4904,8 @@ class CliClient final : public Actor {
string voice_path; string voice_path;
get_args(args, chat_id, voice_path); get_args(args, chat_id, voice_path);
send_message(chat_id, td_api::make_object<td_api::inputMessageVoiceNote>(as_input_file(voice_path), 0, "abacaba", send_message(chat_id, td_api::make_object<td_api::inputMessageVoiceNote>(as_input_file(voice_path), 0, "abacaba",
as_caption("voice caption"))); as_caption("voice caption"),
get_message_self_destruct_type()));
} else if (op == "SendContact" || op == "scontact") { } else if (op == "SendContact" || op == "scontact") {
ChatId chat_id; ChatId chat_id;
string phone_number; string phone_number;
@ -5134,8 +5135,8 @@ class CliClient final : public Actor {
ChatId chat_id; ChatId chat_id;
string video_path; string video_path;
get_args(args, chat_id, video_path); get_args(args, chat_id, video_path);
send_message(chat_id, send_message(chat_id, td_api::make_object<td_api::inputMessageVideoNote>(as_input_file(video_path), nullptr, 10,
td_api::make_object<td_api::inputMessageVideoNote>(as_input_file(video_path), nullptr, 10, 5)); 5, get_message_self_destruct_type()));
} else if (op == "svenue") { } else if (op == "svenue") {
ChatId chat_id; ChatId chat_id;
string latitude; string latitude;