Add layer 143 to secret chats.

This commit is contained in:
levlam 2022-05-11 07:46:06 +03:00
parent 81a8f832d3
commit 880a582959
22 changed files with 94 additions and 45 deletions

View File

@ -78,7 +78,7 @@ documentAttributeAudio45#ded218e0 duration:int title:string performer:string = D
decryptedMessage46#36b091de flags:# random_id:long ttl:int message:string media:flags.9?DecryptedMessageMedia entities:flags.7?Vector<MessageEntity> via_bot_name:flags.11?string reply_to_random_id:flags.3?long = DecryptedMessage;
decryptedMessageMediaPhoto#f1fa8d78 thumb:bytes thumb_w:int thumb_h:int w:int h:int size:int key:bytes iv:bytes caption:string = DecryptedMessageMedia;
decryptedMessageMediaVideo#970c8c0e thumb:bytes thumb_w:int thumb_h:int duration:int mime_type:string w:int h:int size:int key:bytes iv:bytes caption:string = DecryptedMessageMedia;
decryptedMessageMediaDocument#7afe8ae2 thumb:bytes thumb_w:int thumb_h:int mime_type:string size:int key:bytes iv:bytes attributes:Vector<DocumentAttribute> caption:string = DecryptedMessageMedia;
decryptedMessageMediaDocument46#7afe8ae2 thumb:bytes thumb_w:int thumb_h:int mime_type:string size:int key:bytes iv:bytes attributes:Vector<DocumentAttribute> caption:string = DecryptedMessageMedia;
documentAttributeSticker#3a556302 alt:string stickerset:InputStickerSet = DocumentAttribute;
documentAttributeAudio#9852f9c6 flags:# voice:flags.10?true duration:int title:flags.0?string performer:flags.1?string waveform:flags.2?bytes = DocumentAttribute;
messageEntityUnknown#bb92ba95 offset:int length:int = MessageEntity;
@ -117,6 +117,10 @@ messageEntityUnderline#9c4e7e8b offset:int length:int = MessageEntity;
messageEntityStrike#bf0693d4 offset:int length:int = MessageEntity;
messageEntityBlockquote#20df5d0 offset:int length:int = MessageEntity;
// layer 143
decryptedMessageMediaDocument#6abd9782 thumb:bytes thumb_w:int thumb_h:int mime_type:string size:long key:bytes iv:bytes attributes:Vector<DocumentAttribute> caption:string = DecryptedMessageMedia;
---functions---
test.dummyFunction = Bool;

View File

@ -740,7 +740,7 @@ secretChatStateClosed = SecretChatState;
//@is_outbound True, if the chat was created by the current user; otherwise false
//@key_hash Hash of the currently used key for comparison with the hash of the chat partner's key. This is a string of 36 little-endian bytes, which must be split into groups of 2 bits, each denoting a pixel of one of 4 colors FFFFFF, D5E6F3, 2D5775, and 2F99C9.
//-The pixels must be used to make a 12x12 square image filled from left to right, top to bottom. Alternatively, the first 32 bytes of the hash can be converted to the hexadecimal format and printed as 32 2-digit hex numbers
//@layer Secret chat layer; determines features supported by the chat partner's application. Nested text entities and underline and strikethrough entities are supported if the layer >= 101
//@layer Secret chat layer; determines features supported by the chat partner's application. Nested text entities and underline and strikethrough entities are supported if the layer >= 101, files bigger than 2000MB are supported if the layer >= 143
secretChat id:int32 user_id:int53 state:SecretChatState is_outbound:Bool key_hash:bytes layer:int32 = SecretChat;

View File

@ -384,7 +384,8 @@ tl_object_ptr<telegram_api::InputMedia> AnimationsManager::get_input_media(
SecretInputMedia AnimationsManager::get_secret_input_media(FileId animation_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
const string &caption, BufferSlice thumbnail) const {
const string &caption, BufferSlice thumbnail,
int32 layer) const {
auto *animation = get_animation(animation_file_id);
CHECK(animation != nullptr);
auto file_view = td_->file_manager_->get_file_view(animation_file_id);
@ -420,7 +421,8 @@ SecretInputMedia AnimationsManager::get_secret_input_media(FileId animation_file
animation->mime_type,
file_view,
std::move(attributes),
caption};
caption,
layer};
}
void AnimationsManager::on_update_animation_search_emojis(string animation_search_emojis) {

View File

@ -44,7 +44,7 @@ class AnimationsManager final : public Actor {
SecretInputMedia get_secret_input_media(FileId animation_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
const string &caption, BufferSlice thumbnail) const;
const string &caption, BufferSlice thumbnail, int32 layer) const;
FileId get_animation_thumbnail_file_id(FileId file_id) const;

View File

@ -206,7 +206,8 @@ void AudiosManager::create_audio(FileId file_id, string minithumbnail, PhotoSize
SecretInputMedia AudiosManager::get_secret_input_media(FileId audio_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
const string &caption, BufferSlice thumbnail) const {
const string &caption, BufferSlice thumbnail,
int32 layer) const {
auto *audio = get_audio(audio_file_id);
CHECK(audio != nullptr);
auto file_view = td_->file_manager_->get_file_view(audio_file_id);
@ -236,7 +237,8 @@ SecretInputMedia AudiosManager::get_secret_input_media(FileId audio_file_id,
audio->mime_type,
file_view,
std::move(attributes),
caption};
caption,
layer};
}
tl_object_ptr<telegram_api::InputMedia> AudiosManager::get_input_media(

View File

@ -39,7 +39,7 @@ class AudiosManager {
SecretInputMedia get_secret_input_media(FileId audio_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
const string &caption, BufferSlice thumbnail) const;
const string &caption, BufferSlice thumbnail, int32 layer) const;
FileId get_audio_thumbnail_file_id(FileId file_id) const;

View File

@ -598,7 +598,8 @@ bool DocumentsManager::has_input_media(FileId file_id, FileId thumbnail_file_id,
SecretInputMedia DocumentsManager::get_secret_input_media(FileId document_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
const string &caption, BufferSlice thumbnail) const {
const string &caption, BufferSlice thumbnail,
int32 layer) const {
const GeneralDocument *document = get_document(document_file_id);
CHECK(document != nullptr);
auto file_view = td_->file_manager_->get_file_view(document_file_id);
@ -624,7 +625,8 @@ SecretInputMedia DocumentsManager::get_secret_input_media(FileId document_file_i
document->mime_type,
file_view,
std::move(attributes),
caption};
caption,
layer};
}
tl_object_ptr<telegram_api::InputMedia> DocumentsManager::get_input_media(

View File

@ -89,7 +89,7 @@ class DocumentsManager {
SecretInputMedia get_secret_input_media(FileId document_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
const string &caption, BufferSlice thumbnail) const;
const string &caption, BufferSlice thumbnail, int32 layer) const;
tl_object_ptr<telegram_api::InputMedia> get_input_media(FileId file_id,
tl_object_ptr<telegram_api::InputFile> input_file,

View File

@ -2167,17 +2167,17 @@ bool can_have_input_media(const Td *td, const MessageContent *content, bool is_s
SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
BufferSlice thumbnail) {
BufferSlice thumbnail, int32 layer) {
switch (content->get_type()) {
case MessageContentType::Animation: {
const auto *m = static_cast<const MessageAnimation *>(content);
return td->animations_manager_->get_secret_input_media(m->file_id, std::move(input_file), m->caption.text,
std::move(thumbnail));
std::move(thumbnail), layer);
}
case MessageContentType::Audio: {
const auto *m = static_cast<const MessageAudio *>(content);
return td->audios_manager_->get_secret_input_media(m->file_id, std::move(input_file), m->caption.text,
std::move(thumbnail));
std::move(thumbnail), layer);
}
case MessageContentType::Contact: {
const auto *m = static_cast<const MessageContact *>(content);
@ -2186,7 +2186,7 @@ SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
case MessageContentType::Document: {
const auto *m = static_cast<const MessageDocument *>(content);
return td->documents_manager_->get_secret_input_media(m->file_id, std::move(input_file), m->caption.text,
std::move(thumbnail));
std::move(thumbnail), layer);
}
case MessageContentType::Location: {
const auto *m = static_cast<const MessageLocation *>(content);
@ -2199,7 +2199,8 @@ SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
}
case MessageContentType::Sticker: {
const auto *m = static_cast<const MessageSticker *>(content);
return td->stickers_manager_->get_secret_input_media(m->file_id, std::move(input_file), std::move(thumbnail));
return td->stickers_manager_->get_secret_input_media(m->file_id, std::move(input_file), std::move(thumbnail),
layer);
}
case MessageContentType::Text: {
CHECK(input_file == nullptr);
@ -2214,15 +2215,17 @@ SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
case MessageContentType::Video: {
const auto *m = static_cast<const MessageVideo *>(content);
return td->videos_manager_->get_secret_input_media(m->file_id, std::move(input_file), m->caption.text,
std::move(thumbnail));
std::move(thumbnail), layer);
}
case MessageContentType::VideoNote: {
const auto *m = static_cast<const MessageVideoNote *>(content);
return td->video_notes_manager_->get_secret_input_media(m->file_id, std::move(input_file), std::move(thumbnail));
return td->video_notes_manager_->get_secret_input_media(m->file_id, std::move(input_file), std::move(thumbnail),
layer);
}
case MessageContentType::VoiceNote: {
const auto *m = static_cast<const MessageVoiceNote *>(content);
return td->voice_notes_manager_->get_secret_input_media(m->file_id, std::move(input_file), m->caption.text);
return td->voice_notes_manager_->get_secret_input_media(m->file_id, std::move(input_file), m->caption.text,
layer);
}
case MessageContentType::Call:
case MessageContentType::Dice:
@ -4003,6 +4006,10 @@ unique_ptr<MessageContent> get_secret_message_content(
auto photo = static_cast<secret_api::decryptedMessageMediaPhoto *>(media.get());
return std::move(photo->caption_);
}
case secret_api::decryptedMessageMediaDocument46::ID: {
auto document = static_cast<secret_api::decryptedMessageMediaDocument46 *>(media.get());
return std::move(document->caption_);
}
case secret_api::decryptedMessageMediaDocument::ID: {
auto document = static_cast<secret_api::decryptedMessageMediaDocument *>(media.get());
return std::move(document->caption_);
@ -4034,9 +4041,18 @@ unique_ptr<MessageContent> get_secret_message_content(
// support of old layer and old constructions
switch (constructor_id) {
case secret_api::decryptedMessageMediaDocument46::ID: {
auto document = move_tl_object_as<secret_api::decryptedMessageMediaDocument46>(media);
media = make_tl_object<secret_api::decryptedMessageMediaDocument>(
std::move(document->thumb_), document->thumb_w_, document->thumb_h_, document->mime_type_, document->size_,
std::move(document->key_), std::move(document->iv_), std::move(document->attributes_), string());
constructor_id = secret_api::decryptedMessageMediaDocument::ID;
break;
}
case secret_api::decryptedMessageMediaVideo::ID: {
auto video = move_tl_object_as<secret_api::decryptedMessageMediaVideo>(media);
std::vector<tl_object_ptr<secret_api::DocumentAttribute>> attributes;
vector<tl_object_ptr<secret_api::DocumentAttribute>> attributes;
attributes.emplace_back(
make_tl_object<secret_api::documentAttributeVideo>(video->duration_, video->w_, video->h_));
media = make_tl_object<secret_api::decryptedMessageMediaDocument>(

View File

@ -109,7 +109,7 @@ bool can_have_input_media(const Td *td, const MessageContent *content, bool is_s
SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
BufferSlice thumbnail);
BufferSlice thumbnail, int32 layer);
tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *content, Td *td,
tl_object_ptr<telegram_api::InputFile> input_file,

View File

@ -8962,10 +8962,11 @@ void MessagesManager::do_send_secret_media(DialogId dialog_id, Message *m, FileI
LOG(INFO) << "Do send secret media file " << file_id << " with thumbnail " << thumbnail_file_id
<< ", have_input_file = " << have_input_file;
auto layer = td_->contacts_manager_->get_secret_chat_layer(dialog_id.get_secret_chat_id());
on_secret_message_media_uploaded(
dialog_id, m,
get_secret_input_media(m->content.get(), td_, std::move(input_encrypted_file), std::move(thumbnail)), file_id,
thumbnail_file_id);
get_secret_input_media(m->content.get(), td_, std::move(input_encrypted_file), std::move(thumbnail), layer),
file_id, thumbnail_file_id);
}
void MessagesManager::on_upload_media_error(FileId file_id, Status status) {
@ -25507,7 +25508,8 @@ void MessagesManager::do_send_message(DialogId dialog_id, const Message *m, vect
LOG(DEBUG) << "Need to send file " << file_id << " with thumbnail " << thumbnail_file_id;
if (is_secret) {
CHECK(!is_edit);
auto secret_input_media = get_secret_input_media(content, td_, nullptr, BufferSlice());
auto layer = td_->contacts_manager_->get_secret_chat_layer(dialog_id.get_secret_chat_id());
auto secret_input_media = get_secret_input_media(content, td_, nullptr, BufferSlice(), layer);
if (secret_input_media.empty()) {
LOG(INFO) << "Ask to upload encrypted file " << file_id;
CHECK(file_view.is_encrypted_secret());
@ -25990,7 +25992,8 @@ void MessagesManager::on_text_message_ready_to_send(DialogId dialog_id, MessageI
if (dialog_id.get_type() == DialogType::SecretChat) {
CHECK(!message_id.is_scheduled());
send_secret_message(dialog_id, m, get_secret_input_media(content, td_, nullptr, BufferSlice()));
auto layer = td_->contacts_manager_->get_secret_chat_layer(dialog_id.get_secret_chat_id());
send_secret_message(dialog_id, m, get_secret_input_media(content, td_, nullptr, BufferSlice(), layer));
} else {
const FormattedText *message_text = get_message_content_text(content);
CHECK(message_text != nullptr);

View File

@ -13,7 +13,8 @@ enum class SecretChatLayer : int32 {
Mtproto2 = 73,
NewEntities = 101,
DeleteMessagesOnClose = 123,
Current = DeleteMessagesOnClose
SupportBigFiles = 143,
Current = SupportBigFiles
};
} // namespace td

View File

@ -7,19 +7,32 @@
#include "td/telegram/SecretInputMedia.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/SecretChatLayer.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)
const string &caption, int32 layer)
: 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);
auto size = file_view.size();
if (layer >= static_cast<int32>(SecretChatLayer::SupportBigFiles)) {
decrypted_media_ = secret_api::make_object<secret_api::decryptedMessageMediaDocument>(
std::move(thumbnail), thumbnail_dimensions.width, thumbnail_dimensions.height, mime_type, size,
BufferSlice(encryption_key.key_slice()), BufferSlice(encryption_key.iv_slice()), std::move(attributes),
caption);
return;
}
if (size <= (2000 << 20)) {
decrypted_media_ = secret_api::make_object<secret_api::decryptedMessageMediaDocument46>(
std::move(thumbnail), thumbnail_dimensions.width, thumbnail_dimensions.height, mime_type,
narrow_cast<int32>(size), BufferSlice(encryption_key.key_slice()), BufferSlice(encryption_key.iv_slice()),
std::move(attributes), caption);
return;
}
input_file_ = nullptr;
}
} // namespace td

View File

@ -30,7 +30,8 @@ struct 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);
vector<tl_object_ptr<secret_api::DocumentAttribute>> &&attributes, const string &caption,
int32 layer);
bool empty() const {
return decrypted_media_ == nullptr;

View File

@ -2730,7 +2730,7 @@ bool StickersManager::has_input_media(FileId sticker_file_id, bool is_secret) co
SecretInputMedia StickersManager::get_secret_input_media(FileId sticker_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
BufferSlice thumbnail) const {
BufferSlice thumbnail, int32 layer) const {
const Sticker *sticker = get_sticker(sticker_file_id);
CHECK(sticker != nullptr);
auto file_view = td_->file_manager_->get_file_view(sticker_file_id);
@ -2779,7 +2779,8 @@ SecretInputMedia StickersManager::get_secret_input_media(FileId sticker_file_id,
get_sticker_format_mime_type(sticker->format),
file_view,
std::move(attributes),
string()};
string(),
layer};
} else {
CHECK(!file_view.is_encrypted());
auto &remote_location = file_view.remote_location();

View File

@ -107,7 +107,7 @@ class StickersManager final : public Actor {
SecretInputMedia get_secret_input_media(FileId sticker_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
BufferSlice thumbnail) const;
BufferSlice thumbnail, int32 layer) const;
vector<FileId> get_stickers(string emoji, int32 limit, bool force, Promise<Unit> &&promise);

View File

@ -155,7 +155,7 @@ void VideoNotesManager::create_video_note(FileId file_id, string minithumbnail,
SecretInputMedia VideoNotesManager::get_secret_input_media(FileId video_note_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
BufferSlice thumbnail) const {
BufferSlice thumbnail, int32 layer) const {
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);
@ -182,7 +182,8 @@ SecretInputMedia VideoNotesManager::get_secret_input_media(FileId video_note_fil
"video/mp4",
file_view,
std::move(attributes),
string()};
string(),
layer};
}
tl_object_ptr<telegram_api::InputMedia> VideoNotesManager::get_input_media(

View File

@ -38,7 +38,7 @@ class VideoNotesManager {
SecretInputMedia get_secret_input_media(FileId video_note_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
BufferSlice thumbnail) const;
BufferSlice thumbnail, int32 layer) const;
FileId get_video_note_thumbnail_file_id(FileId file_id) const;

View File

@ -10,6 +10,7 @@
#include "td/telegram/files/FileManager.h"
#include "td/telegram/PhotoFormat.h"
#include "td/telegram/secret_api.h"
#include "td/telegram/SecretChatLayer.h"
#include "td/telegram/Td.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
@ -201,7 +202,8 @@ void VideosManager::create_video(FileId file_id, string minithumbnail, PhotoSize
SecretInputMedia VideosManager::get_secret_input_media(FileId video_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
const string &caption, BufferSlice thumbnail) const {
const string &caption, BufferSlice thumbnail,
int32 layer) const {
const Video *video = get_video(video_file_id);
CHECK(video != nullptr);
auto file_view = td_->file_manager_->get_file_view(video_file_id);
@ -212,7 +214,7 @@ SecretInputMedia VideosManager::get_secret_input_media(FileId video_file_id,
input_file = file_view.main_remote_location().as_input_encrypted_file();
}
if (!input_file) {
return SecretInputMedia{};
return {};
}
if (video->thumbnail.file_id.is_valid() && thumbnail.empty()) {
return {};
@ -227,7 +229,8 @@ SecretInputMedia VideosManager::get_secret_input_media(FileId video_file_id,
video->mime_type,
file_view,
std::move(attributes),
caption};
caption,
layer};
}
tl_object_ptr<telegram_api::InputMedia> VideosManager::get_input_media(

View File

@ -40,7 +40,7 @@ class VideosManager {
SecretInputMedia get_secret_input_media(FileId video_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
const string &caption, BufferSlice thumbnail) const;
const string &caption, BufferSlice thumbnail, int32 layer) const;
FileId get_video_thumbnail_file_id(FileId file_id) const;

View File

@ -130,7 +130,7 @@ void VoiceNotesManager::create_voice_note(FileId file_id, string mime_type, int3
SecretInputMedia VoiceNotesManager::get_secret_input_media(FileId voice_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
const string &caption) const {
const string &caption, int32 layer) const {
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);
@ -149,7 +149,7 @@ SecretInputMedia VoiceNotesManager::get_secret_input_media(FileId voice_file_id,
false /*ignored*/, voice_note->duration, "", "", BufferSlice(voice_note->waveform)));
return {std::move(input_file), BufferSlice(), Dimensions(), voice_note->mime_type, file_view,
std::move(attributes), caption};
std::move(attributes), caption, layer};
}
tl_object_ptr<telegram_api::InputMedia> VoiceNotesManager::get_input_media(

View File

@ -33,7 +33,7 @@ class VoiceNotesManager {
SecretInputMedia get_secret_input_media(FileId voice_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
const string &caption) const;
const string &caption, int32 layer) const;
FileId dup_voice_note(FileId new_id, FileId old_id);