Fix sending of secret_api::documentAttributeVideo.

GitOrigin-RevId: b4247fe902cbf64dc12e67cc1f41f140b60db65a
This commit is contained in:
levlam 2018-12-04 21:18:07 +03:00
parent 7e3ab0348a
commit d580eb7818
11 changed files with 25 additions and 16 deletions

View File

@ -13,6 +13,7 @@
#include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/misc.h"
#include "td/telegram/SecretChatActor.h"
#include "td/telegram/Td.h"
#include "td/telegram/secret_api.h"
@ -305,7 +306,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);
@ -327,8 +329,13 @@ SecretInputMedia AnimationsManager::get_secret_input_media(FileId animation_file
attributes.push_back(make_tl_object<secret_api::documentAttributeFilename>(animation->file_name));
}
if (animation->duration != 0 && animation->mime_type == "video/mp4") {
attributes.push_back(make_tl_object<secret_api::documentAttributeVideo>(
animation->duration, animation->dimensions.width, animation->dimensions.height));
if (layer >= SecretChatActor::VIDEO_NOTES_LAYER) {
attributes.push_back(make_tl_object<secret_api::documentAttributeVideo66>(
0, false, animation->duration, animation->dimensions.width, animation->dimensions.height));
} else {
attributes.push_back(make_tl_object<secret_api::documentAttributeVideo>(
animation->duration, animation->dimensions.width, animation->dimensions.height));
}
}
if (animation->dimensions.width != 0 && animation->dimensions.height != 0) {
attributes.push_back(make_tl_object<secret_api::documentAttributeImageSize>(animation->dimensions.width,

View File

@ -45,7 +45,7 @@ class AnimationsManager : 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

@ -201,7 +201,7 @@ SecretInputMedia AudiosManager::get_secret_input_media(FileId audio_file_id,
attributes.push_back(make_tl_object<secret_api::documentAttributeFilename>(audio->file_name));
}
attributes.push_back(make_tl_object<secret_api::documentAttributeAudio>(
secret_api::documentAttributeAudio::Flags::TITLE_MASK | secret_api::documentAttributeAudio::Flags::PERFORMER_MASK,
secret_api::documentAttributeAudio::TITLE_MASK | secret_api::documentAttributeAudio::PERFORMER_MASK,
false /*ignored*/, audio->duration, audio->title, audio->performer, BufferSlice()));
return SecretInputMedia{

View File

@ -43,10 +43,10 @@ CallProtocol CallProtocol::from_telegram_api(const telegram_api::phoneCallProtoc
tl_object_ptr<telegram_api::phoneCallProtocol> CallProtocol::as_telegram_api() const {
int32 flags = 0;
if (udp_p2p) {
flags |= telegram_api::phoneCallProtocol::Flags::UDP_P2P_MASK;
flags |= telegram_api::phoneCallProtocol::UDP_P2P_MASK;
}
if (udp_reflector) {
flags |= telegram_api::phoneCallProtocol::Flags::UDP_REFLECTOR_MASK;
flags |= telegram_api::phoneCallProtocol::UDP_REFLECTOR_MASK;
}
return make_tl_object<telegram_api::phoneCallProtocol>(flags, udp_p2p, udp_reflector, min_layer, max_layer);
}

View File

@ -139,7 +139,7 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
default_document_type == DocumentType::VoiceNote) {
bool is_voice_note = default_document_type == DocumentType::VoiceNote;
if (audio != nullptr) {
is_voice_note = (audio->flags_ & telegram_api::documentAttributeAudio::Flags::VOICE_MASK) != 0;
is_voice_note = (audio->flags_ & telegram_api::documentAttributeAudio::VOICE_MASK) != 0;
}
if (is_voice_note) {
document_type = DocumentType::VoiceNote;

View File

@ -1710,7 +1710,7 @@ SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
case MessageContentType::Animation: {
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: {
auto m = static_cast<const MessageAudio *>(content);

View File

@ -14684,7 +14684,7 @@ Status MessagesManager::can_send_message_content(DialogId dialog_id, const Messa
if (!can_send_media) {
return Status::Error(400, "Not enough rights to send video notes to the chat");
}
if (secret_chat_layer < SecretChatActor::VOICE_NOTES_LAYER) {
if (secret_chat_layer < SecretChatActor::VIDEO_NOTES_LAYER) {
return Status::Error(400, PSLICE()
<< "Video notes can't be sent to secret chat with layer " << secret_chat_layer);
}

View File

@ -237,7 +237,7 @@ static int32 get_min_layer(const secret_api::decryptedMessageActionTyping &messa
switch (message.action_->get_id()) {
case secret_api::sendMessageRecordRoundAction::ID:
case secret_api::sendMessageUploadRoundAction::ID:
return SecretChatActor::VOICE_NOTES_LAYER;
return SecretChatActor::VIDEO_NOTES_LAYER;
}
return 0;
}
@ -252,7 +252,7 @@ static int32 get_min_layer(const secret_api::decryptedMessageService &message) {
static int32 get_min_layer(const secret_api::DocumentAttribute &attribute) {
switch (attribute.get_id()) {
case secret_api::documentAttributeVideo66::ID:
return SecretChatActor::VOICE_NOTES_LAYER;
return SecretChatActor::VIDEO_NOTES_LAYER;
default:
return 0;
}

View File

@ -41,13 +41,14 @@
#include <utility>
namespace td {
class BinlogInterface;
class NetQueryCreator;
class SecretChatActor : public NetQueryCallback {
public:
// do not change DEFAULT_LAYER, unless all it's usages are fixed
enum : int32 { DEFAULT_LAYER = 46, VOICE_NOTES_LAYER = 66, MTPROTO_2_LAYER = 73, MY_LAYER = MTPROTO_2_LAYER };
enum : int32 { DEFAULT_LAYER = 46, VIDEO_NOTES_LAYER = 66, MTPROTO_2_LAYER = 73, MY_LAYER = MTPROTO_2_LAYER };
class Context {
public:
@ -684,4 +685,5 @@ class SecretChatActor : public NetQueryCallback {
<< tag("his_in_seq_no", state.his_in_seq_no) << "]";
}
};
} // namespace td

View File

@ -175,10 +175,10 @@ SecretInputMedia VideoNotesManager::get_secret_input_media(FileId video_note_fil
if (video_note->thumbnail.file_id.is_valid() && thumbnail.empty()) {
return SecretInputMedia{};
}
CHECK(layer >= SecretChatActor::VOICE_NOTES_LAYER);
CHECK(layer >= SecretChatActor::VIDEO_NOTES_LAYER);
vector<tl_object_ptr<secret_api::DocumentAttribute>> attributes;
attributes.push_back(make_tl_object<secret_api::documentAttributeVideo66>(
secret_api::documentAttributeVideo66::Flags::ROUND_MESSAGE_MASK, true, video_note->duration,
secret_api::documentAttributeVideo66::ROUND_MESSAGE_MASK, true, video_note->duration,
video_note->dimensions.width, video_note->dimensions.height));
return SecretInputMedia{
std::move(input_file),

View File

@ -154,7 +154,7 @@ SecretInputMedia VoiceNotesManager::get_secret_input_media(FileId voice_file_id,
}
vector<tl_object_ptr<secret_api::DocumentAttribute>> attributes;
attributes.push_back(make_tl_object<secret_api::documentAttributeAudio>(
secret_api::documentAttributeAudio::Flags::VOICE_MASK | secret_api::documentAttributeAudio::Flags::WAVEFORM_MASK,
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>(