Add Document class.
GitOrigin-RevId: e1a5a8235f341cf0955ee37086a99a17e7b123de
This commit is contained in:
parent
78704b6918
commit
dc79cdc0b1
@ -362,6 +362,7 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/DialogDb.cpp
|
td/telegram/DialogDb.cpp
|
||||||
td/telegram/DialogId.cpp
|
td/telegram/DialogId.cpp
|
||||||
td/telegram/DialogParticipant.cpp
|
td/telegram/DialogParticipant.cpp
|
||||||
|
td/telegram/Document.cpp
|
||||||
td/telegram/DocumentsManager.cpp
|
td/telegram/DocumentsManager.cpp
|
||||||
td/telegram/DraftMessage.cpp
|
td/telegram/DraftMessage.cpp
|
||||||
td/telegram/FileReferenceManager.cpp
|
td/telegram/FileReferenceManager.cpp
|
||||||
@ -494,6 +495,7 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/DialogDb.h
|
td/telegram/DialogDb.h
|
||||||
td/telegram/DialogId.h
|
td/telegram/DialogId.h
|
||||||
td/telegram/DialogParticipant.h
|
td/telegram/DialogParticipant.h
|
||||||
|
td/telegram/Document.h
|
||||||
td/telegram/DocumentsManager.h
|
td/telegram/DocumentsManager.h
|
||||||
td/telegram/DraftMessage.h
|
td/telegram/DraftMessage.h
|
||||||
td/telegram/FileReferenceManager.h
|
td/telegram/FileReferenceManager.h
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "td/telegram/AuthManager.h"
|
#include "td/telegram/AuthManager.h"
|
||||||
#include "td/telegram/DialogId.h"
|
#include "td/telegram/DialogId.h"
|
||||||
|
#include "td/telegram/Document.h"
|
||||||
#include "td/telegram/DocumentsManager.h"
|
#include "td/telegram/DocumentsManager.h"
|
||||||
#include "td/telegram/FileReferenceManager.h"
|
#include "td/telegram/FileReferenceManager.h"
|
||||||
#include "td/telegram/files/FileManager.h"
|
#include "td/telegram/files/FileManager.h"
|
||||||
@ -549,12 +550,12 @@ void AnimationsManager::on_get_saved_animations(
|
|||||||
CHECK(document_constructor_id == telegram_api::document::ID);
|
CHECK(document_constructor_id == telegram_api::document::ID);
|
||||||
auto document =
|
auto document =
|
||||||
td_->documents_manager_->on_get_document(move_tl_object_as<telegram_api::document>(document_ptr), DialogId());
|
td_->documents_manager_->on_get_document(move_tl_object_as<telegram_api::document>(document_ptr), DialogId());
|
||||||
if (document.first != DocumentsManager::DocumentType::Animation) {
|
if (document.type != Document::Type::Animation) {
|
||||||
LOG(ERROR) << "Receive " << static_cast<int>(document.first) << " instead of animation as saved animation";
|
LOG(ERROR) << "Receive " << document << " instead of animation as saved animation";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!is_repair) {
|
if (!is_repair) {
|
||||||
saved_animation_ids.push_back(document.second);
|
saved_animation_ids.push_back(document.file_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
39
td/telegram/Document.cpp
Normal file
39
td/telegram/Document.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
||||||
|
//
|
||||||
|
// 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/Document.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
StringBuilder &operator<<(StringBuilder &string_builder, const Document &document) {
|
||||||
|
auto type = [&] {
|
||||||
|
switch (document.type) {
|
||||||
|
case Document::Type::Unknown:
|
||||||
|
return "Unknown";
|
||||||
|
case Document::Type::Animation:
|
||||||
|
return "Animation";
|
||||||
|
case Document::Type::Audio:
|
||||||
|
return "Audio";
|
||||||
|
case Document::Type::General:
|
||||||
|
return "Document";
|
||||||
|
case Document::Type::Sticker:
|
||||||
|
return "Sticker";
|
||||||
|
case Document::Type::Video:
|
||||||
|
return "Video";
|
||||||
|
case Document::Type::VideoNote:
|
||||||
|
return "VideoNote";
|
||||||
|
case Document::Type::VoiceNote:
|
||||||
|
return "VoiceNote";
|
||||||
|
default:
|
||||||
|
return "Unreachable";
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
return string_builder << '[' << type << ' ' << document.file_id << ']';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace td
|
30
td/telegram/Document.h
Normal file
30
td/telegram/Document.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/telegram/files/FileId.h"
|
||||||
|
|
||||||
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/StringBuilder.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
struct Document {
|
||||||
|
// append only
|
||||||
|
enum class Type : int32 { Unknown, Animation, Audio, General, Sticker, Video, VideoNote, VoiceNote };
|
||||||
|
|
||||||
|
Type type = Type::Unknown;
|
||||||
|
FileId file_id;
|
||||||
|
|
||||||
|
Document() = default;
|
||||||
|
Document(Type type, FileId file_id): type(type), file_id(file_id) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
StringBuilder &operator<<(StringBuilder &string_builder, const Document &document);
|
||||||
|
|
||||||
|
} // namespace td
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "td/telegram/AnimationsManager.h"
|
#include "td/telegram/AnimationsManager.h"
|
||||||
#include "td/telegram/AudiosManager.h"
|
#include "td/telegram/AudiosManager.h"
|
||||||
|
#include "td/telegram/Document.h"
|
||||||
#include "td/telegram/files/FileEncryptionKey.h"
|
#include "td/telegram/files/FileEncryptionKey.h"
|
||||||
#include "td/telegram/files/FileLocation.h"
|
#include "td/telegram/files/FileLocation.h"
|
||||||
#include "td/telegram/files/FileManager.h"
|
#include "td/telegram/files/FileManager.h"
|
||||||
@ -59,9 +60,9 @@ tl_object_ptr<td_api::document> DocumentsManager::get_document_object(FileId fil
|
|||||||
td_->file_manager_->get_file_object(file_id));
|
td_->file_manager_->get_file_object(file_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_document(
|
Document DocumentsManager::on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id,
|
||||||
RemoteDocument remote_document, DialogId owner_dialog_id, MultiPromiseActor *load_data_multipromise_ptr,
|
MultiPromiseActor *load_data_multipromise_ptr,
|
||||||
DocumentType default_document_type) {
|
Document::Type default_document_type) {
|
||||||
tl_object_ptr<telegram_api::documentAttributeAnimated> animated;
|
tl_object_ptr<telegram_api::documentAttributeAnimated> animated;
|
||||||
tl_object_ptr<telegram_api::documentAttributeVideo> video;
|
tl_object_ptr<telegram_api::documentAttributeVideo> video;
|
||||||
tl_object_ptr<telegram_api::documentAttributeAudio> audio;
|
tl_object_ptr<telegram_api::documentAttributeAudio> audio;
|
||||||
@ -132,37 +133,37 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
|
|||||||
Slice default_extension;
|
Slice default_extension;
|
||||||
bool supports_streaming = false;
|
bool supports_streaming = false;
|
||||||
bool has_webp_thumbnail = false;
|
bool has_webp_thumbnail = false;
|
||||||
if (type_attributes == 1 || default_document_type != DocumentType::General) { // not a general document
|
if (type_attributes == 1 || default_document_type != Document::Type::General) { // not a general document
|
||||||
if (animated != nullptr || default_document_type == DocumentType::Animation) {
|
if (animated != nullptr || default_document_type == Document::Type::Animation) {
|
||||||
document_type = DocumentType::Animation;
|
document_type = Document::Type::Animation;
|
||||||
file_type = FileType::Animation;
|
file_type = FileType::Animation;
|
||||||
default_extension = Slice("mp4");
|
default_extension = Slice("mp4");
|
||||||
} else if (audio != nullptr || default_document_type == DocumentType::Audio ||
|
} else if (audio != nullptr || default_document_type == Document::Type::Audio ||
|
||||||
default_document_type == DocumentType::VoiceNote) {
|
default_document_type == Document::Type::VoiceNote) {
|
||||||
bool is_voice_note = default_document_type == DocumentType::VoiceNote;
|
bool is_voice_note = default_document_type == Document::Type::VoiceNote;
|
||||||
if (audio != nullptr) {
|
if (audio != nullptr) {
|
||||||
is_voice_note = (audio->flags_ & telegram_api::documentAttributeAudio::VOICE_MASK) != 0;
|
is_voice_note = (audio->flags_ & telegram_api::documentAttributeAudio::VOICE_MASK) != 0;
|
||||||
}
|
}
|
||||||
if (is_voice_note) {
|
if (is_voice_note) {
|
||||||
document_type = DocumentType::VoiceNote;
|
document_type = Document::Type::VoiceNote;
|
||||||
file_type = FileType::VoiceNote;
|
file_type = FileType::VoiceNote;
|
||||||
default_extension = Slice("oga");
|
default_extension = Slice("oga");
|
||||||
file_name.clear();
|
file_name.clear();
|
||||||
} else {
|
} else {
|
||||||
document_type = DocumentType::Audio;
|
document_type = Document::Type::Audio;
|
||||||
file_type = FileType::Audio;
|
file_type = FileType::Audio;
|
||||||
default_extension = Slice("mp3");
|
default_extension = Slice("mp3");
|
||||||
}
|
}
|
||||||
} else if (sticker != nullptr || default_document_type == DocumentType::Sticker) {
|
} else if (sticker != nullptr || default_document_type == Document::Type::Sticker) {
|
||||||
document_type = DocumentType::Sticker;
|
document_type = Document::Type::Sticker;
|
||||||
file_type = FileType::Sticker;
|
file_type = FileType::Sticker;
|
||||||
default_extension = Slice("webp");
|
default_extension = Slice("webp");
|
||||||
owner_dialog_id = DialogId();
|
owner_dialog_id = DialogId();
|
||||||
file_name.clear();
|
file_name.clear();
|
||||||
has_webp_thumbnail = td_->stickers_manager_->has_webp_thumbnail(sticker);
|
has_webp_thumbnail = td_->stickers_manager_->has_webp_thumbnail(sticker);
|
||||||
} else if (video != nullptr || default_document_type == DocumentType::Video ||
|
} else if (video != nullptr || default_document_type == Document::Type::Video ||
|
||||||
default_document_type == DocumentType::VideoNote) {
|
default_document_type == Document::Type::VideoNote) {
|
||||||
bool is_video_note = default_document_type == DocumentType::VideoNote;
|
bool is_video_note = default_document_type == Document::Type::VideoNote;
|
||||||
if (video != nullptr) {
|
if (video != nullptr) {
|
||||||
is_video_note = (video->flags_ & telegram_api::documentAttributeVideo::ROUND_MESSAGE_MASK) != 0;
|
is_video_note = (video->flags_ & telegram_api::documentAttributeVideo::ROUND_MESSAGE_MASK) != 0;
|
||||||
if (!is_video_note) {
|
if (!is_video_note) {
|
||||||
@ -170,11 +171,11 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_video_note) {
|
if (is_video_note) {
|
||||||
document_type = DocumentType::VideoNote;
|
document_type = Document::Type::VideoNote;
|
||||||
file_type = FileType::VideoNote;
|
file_type = FileType::VideoNote;
|
||||||
file_name.clear();
|
file_name.clear();
|
||||||
} else {
|
} else {
|
||||||
document_type = DocumentType::Video;
|
document_type = Document::Type::Video;
|
||||||
file_type = FileType::Video;
|
file_type = FileType::Video;
|
||||||
}
|
}
|
||||||
default_extension = Slice("mp4");
|
default_extension = Slice("mp4");
|
||||||
@ -207,7 +208,7 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
|
|||||||
mime_type = std::move(document->mime_type_);
|
mime_type = std::move(document->mime_type_);
|
||||||
file_reference = document->file_reference_.as_slice().str();
|
file_reference = document->file_reference_.as_slice().str();
|
||||||
|
|
||||||
if (document_type != DocumentType::VoiceNote) {
|
if (document_type != Document::Type::VoiceNote) {
|
||||||
thumbnail = get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, "", owner_dialog_id,
|
thumbnail = get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, "", owner_dialog_id,
|
||||||
std::move(document->thumb_), has_webp_thumbnail);
|
std::move(document->thumb_), has_webp_thumbnail);
|
||||||
}
|
}
|
||||||
@ -224,10 +225,10 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
|
|||||||
file_type = FileType::Encrypted;
|
file_type = FileType::Encrypted;
|
||||||
encryption_key = FileEncryptionKey{document->key_.as_slice(), document->iv_.as_slice()};
|
encryption_key = FileEncryptionKey{document->key_.as_slice(), document->iv_.as_slice()};
|
||||||
if (encryption_key.empty()) {
|
if (encryption_key.empty()) {
|
||||||
return {DocumentType::Unknown, FileId()};
|
return {Document::Type::Unknown, FileId()};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document_type != DocumentType::VoiceNote) {
|
if (document_type != Document::Type::VoiceNote) {
|
||||||
thumbnail = get_thumbnail_photo_size(td_->file_manager_.get(), std::move(document->thumb_), owner_dialog_id,
|
thumbnail = get_thumbnail_photo_size(td_->file_manager_.get(), std::move(document->thumb_), owner_dialog_id,
|
||||||
document->thumb_w_, document->thumb_h_);
|
document->thumb_w_, document->thumb_h_);
|
||||||
}
|
}
|
||||||
@ -245,7 +246,7 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
|
|||||||
auto r_http_url = parse_url(web_document->url_);
|
auto r_http_url = parse_url(web_document->url_);
|
||||||
if (r_http_url.is_error()) {
|
if (r_http_url.is_error()) {
|
||||||
LOG(ERROR) << "Can't parse URL " << web_document->url_;
|
LOG(ERROR) << "Can't parse URL " << web_document->url_;
|
||||||
return {DocumentType::Unknown, FileId()};
|
return {Document::Type::Unknown, FileId()};
|
||||||
}
|
}
|
||||||
auto http_url = r_http_url.move_as_ok();
|
auto http_url = r_http_url.move_as_ok();
|
||||||
|
|
||||||
@ -262,7 +263,7 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
|
|||||||
|
|
||||||
if (web_document->url_.find('.') == string::npos) {
|
if (web_document->url_.find('.') == string::npos) {
|
||||||
LOG(ERROR) << "Receive invalid URL " << web_document->url_;
|
LOG(ERROR) << "Receive invalid URL " << web_document->url_;
|
||||||
return {DocumentType::Unknown, FileId()};
|
return {Document::Type::Unknown, FileId()};
|
||||||
}
|
}
|
||||||
|
|
||||||
url = std::move(web_document->url_);
|
url = std::move(web_document->url_);
|
||||||
@ -279,7 +280,7 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
|
|||||||
LOG(DEBUG) << "Receive document with id = " << id << " of type " << static_cast<int32>(document_type);
|
LOG(DEBUG) << "Receive document with id = " << id << " of type " << static_cast<int32>(document_type);
|
||||||
if (!is_web && !DcId::is_valid(dc_id)) {
|
if (!is_web && !DcId::is_valid(dc_id)) {
|
||||||
LOG(ERROR) << "Wrong dc_id = " << dc_id;
|
LOG(ERROR) << "Wrong dc_id = " << dc_id;
|
||||||
return {DocumentType::Unknown, FileId()};
|
return {Document::Type::Unknown, FileId()};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto suggested_file_name = file_name;
|
auto suggested_file_name = file_name;
|
||||||
@ -307,7 +308,7 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
|
|||||||
auto r_file_id = td_->file_manager_->from_persistent_id(url, file_type);
|
auto r_file_id = td_->file_manager_->from_persistent_id(url, file_type);
|
||||||
if (r_file_id.is_error()) {
|
if (r_file_id.is_error()) {
|
||||||
LOG(ERROR) << "Can't register URL: " << r_file_id.error();
|
LOG(ERROR) << "Can't register URL: " << r_file_id.error();
|
||||||
return {DocumentType::Unknown, FileId()};
|
return {Document::Type::Unknown, FileId()};
|
||||||
}
|
}
|
||||||
file_id = r_file_id.move_as_ok();
|
file_id = r_file_id.move_as_ok();
|
||||||
}
|
}
|
||||||
@ -321,12 +322,12 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (document_type) {
|
switch (document_type) {
|
||||||
case DocumentType::Animation:
|
case Document::Type::Animation:
|
||||||
// TODO use has_stickers
|
// TODO use has_stickers
|
||||||
td_->animations_manager_->create_animation(file_id, std::move(thumbnail), std::move(file_name),
|
td_->animations_manager_->create_animation(file_id, std::move(thumbnail), std::move(file_name),
|
||||||
std::move(mime_type), video_duration, dimensions, !is_web);
|
std::move(mime_type), video_duration, dimensions, !is_web);
|
||||||
break;
|
break;
|
||||||
case DocumentType::Audio: {
|
case Document::Type::Audio: {
|
||||||
int32 duration = 0;
|
int32 duration = 0;
|
||||||
string title;
|
string title;
|
||||||
string performer;
|
string performer;
|
||||||
@ -339,23 +340,23 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
|
|||||||
duration, std::move(title), std::move(performer), !is_web);
|
duration, std::move(title), std::move(performer), !is_web);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DocumentType::General:
|
case Document::Type::General:
|
||||||
td_->documents_manager_->create_document(file_id, std::move(thumbnail), std::move(file_name),
|
td_->documents_manager_->create_document(file_id, std::move(thumbnail), std::move(file_name),
|
||||||
std::move(mime_type), !is_web);
|
std::move(mime_type), !is_web);
|
||||||
break;
|
break;
|
||||||
case DocumentType::Sticker:
|
case Document::Type::Sticker:
|
||||||
td_->stickers_manager_->create_sticker(file_id, std::move(thumbnail), dimensions, true, std::move(sticker),
|
td_->stickers_manager_->create_sticker(file_id, std::move(thumbnail), dimensions, true, std::move(sticker),
|
||||||
load_data_multipromise_ptr);
|
load_data_multipromise_ptr);
|
||||||
break;
|
break;
|
||||||
case DocumentType::Video:
|
case Document::Type::Video:
|
||||||
td_->videos_manager_->create_video(file_id, std::move(thumbnail), has_stickers, vector<FileId>(),
|
td_->videos_manager_->create_video(file_id, std::move(thumbnail), has_stickers, vector<FileId>(),
|
||||||
std::move(file_name), std::move(mime_type), video_duration, dimensions,
|
std::move(file_name), std::move(mime_type), video_duration, dimensions,
|
||||||
supports_streaming, !is_web);
|
supports_streaming, !is_web);
|
||||||
break;
|
break;
|
||||||
case DocumentType::VideoNote:
|
case Document::Type::VideoNote:
|
||||||
td_->video_notes_manager_->create_video_note(file_id, std::move(thumbnail), video_duration, dimensions, !is_web);
|
td_->video_notes_manager_->create_video_note(file_id, std::move(thumbnail), video_duration, dimensions, !is_web);
|
||||||
break;
|
break;
|
||||||
case DocumentType::VoiceNote: {
|
case Document::Type::VoiceNote: {
|
||||||
int32 duration = 0;
|
int32 duration = 0;
|
||||||
string waveform;
|
string waveform;
|
||||||
if (audio != nullptr) {
|
if (audio != nullptr) {
|
||||||
@ -366,14 +367,14 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
|
|||||||
!is_web);
|
!is_web);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DocumentType::Unknown:
|
case Document::Type::Unknown:
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
return {document_type, file_id};
|
return {document_type, file_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
FileId DocumentsManager::on_get_document(unique_ptr<Document> new_document, bool replace) {
|
FileId DocumentsManager::on_get_document(unique_ptr<GeneralDocument> new_document, bool replace) {
|
||||||
auto file_id = new_document->file_id;
|
auto file_id = new_document->file_id;
|
||||||
LOG(INFO) << "Receive document " << file_id;
|
LOG(INFO) << "Receive document " << file_id;
|
||||||
auto &d = documents_[new_document->file_id];
|
auto &d = documents_[new_document->file_id];
|
||||||
@ -408,7 +409,7 @@ FileId DocumentsManager::on_get_document(unique_ptr<Document> new_document, bool
|
|||||||
|
|
||||||
void DocumentsManager::create_document(FileId file_id, PhotoSize thumbnail, string file_name, string mime_type,
|
void DocumentsManager::create_document(FileId file_id, PhotoSize thumbnail, string file_name, string mime_type,
|
||||||
bool replace) {
|
bool replace) {
|
||||||
auto d = make_unique<Document>();
|
auto d = make_unique<GeneralDocument>();
|
||||||
d->file_id = file_id;
|
d->file_id = file_id;
|
||||||
d->file_name = std::move(file_name);
|
d->file_name = std::move(file_name);
|
||||||
d->mime_type = std::move(mime_type);
|
d->mime_type = std::move(mime_type);
|
||||||
@ -416,7 +417,7 @@ void DocumentsManager::create_document(FileId file_id, PhotoSize thumbnail, stri
|
|||||||
on_get_document(std::move(d), replace);
|
on_get_document(std::move(d), replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
const DocumentsManager::Document *DocumentsManager::get_document(FileId file_id) const {
|
const DocumentsManager::GeneralDocument *DocumentsManager::get_document(FileId file_id) const {
|
||||||
auto document = documents_.find(file_id);
|
auto document = documents_.find(file_id);
|
||||||
if (document == documents_.end()) {
|
if (document == documents_.end()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -448,7 +449,7 @@ bool DocumentsManager::has_input_media(FileId file_id, FileId thumbnail_file_id,
|
|||||||
SecretInputMedia DocumentsManager::get_secret_input_media(FileId document_file_id,
|
SecretInputMedia DocumentsManager::get_secret_input_media(FileId document_file_id,
|
||||||
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
|
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
|
||||||
const string &caption, BufferSlice thumbnail) const {
|
const string &caption, BufferSlice thumbnail) const {
|
||||||
const Document *document = get_document(document_file_id);
|
const GeneralDocument *document = get_document(document_file_id);
|
||||||
CHECK(document != nullptr);
|
CHECK(document != nullptr);
|
||||||
auto file_view = td_->file_manager_->get_file_view(document_file_id);
|
auto file_view = td_->file_manager_->get_file_view(document_file_id);
|
||||||
auto &encryption_key = file_view.encryption_key();
|
auto &encryption_key = file_view.encryption_key();
|
||||||
@ -491,7 +492,7 @@ tl_object_ptr<telegram_api::InputMedia> DocumentsManager::get_input_media(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (input_file != nullptr) {
|
if (input_file != nullptr) {
|
||||||
const Document *document = get_document(file_id);
|
const GeneralDocument *document = get_document(file_id);
|
||||||
CHECK(document != nullptr);
|
CHECK(document != nullptr);
|
||||||
|
|
||||||
vector<tl_object_ptr<telegram_api::DocumentAttribute>> attributes;
|
vector<tl_object_ptr<telegram_api::DocumentAttribute>> attributes;
|
||||||
@ -525,11 +526,11 @@ void DocumentsManager::delete_document_thumbnail(FileId file_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FileId DocumentsManager::dup_document(FileId new_id, FileId old_id) {
|
FileId DocumentsManager::dup_document(FileId new_id, FileId old_id) {
|
||||||
const Document *old_document = get_document(old_id);
|
const GeneralDocument *old_document = get_document(old_id);
|
||||||
CHECK(old_document != nullptr);
|
CHECK(old_document != nullptr);
|
||||||
auto &new_document = documents_[new_id];
|
auto &new_document = documents_[new_id];
|
||||||
CHECK(!new_document);
|
CHECK(!new_document);
|
||||||
new_document = make_unique<Document>(*old_document);
|
new_document = make_unique<GeneralDocument>(*old_document);
|
||||||
new_document->file_id = new_id;
|
new_document->file_id = new_id;
|
||||||
new_document->thumbnail.file_id = td_->file_manager_->dup_file_id(new_document->thumbnail.file_id);
|
new_document->thumbnail.file_id = td_->file_manager_->dup_file_id(new_document->thumbnail.file_id);
|
||||||
return new_id;
|
return new_id;
|
||||||
@ -542,7 +543,7 @@ bool DocumentsManager::merge_documents(FileId new_id, FileId old_id, bool can_de
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG(INFO) << "Merge documents " << new_id << " and " << old_id;
|
LOG(INFO) << "Merge documents " << new_id << " and " << old_id;
|
||||||
const Document *old_ = get_document(old_id);
|
const GeneralDocument *old_ = get_document(old_id);
|
||||||
CHECK(old_ != nullptr);
|
CHECK(old_ != nullptr);
|
||||||
if (old_id == new_id) {
|
if (old_id == new_id) {
|
||||||
return old_->is_changed;
|
return old_->is_changed;
|
||||||
@ -559,7 +560,7 @@ bool DocumentsManager::merge_documents(FileId new_id, FileId old_id, bool can_de
|
|||||||
documents_.emplace(new_id, std::move(old));
|
documents_.emplace(new_id, std::move(old));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Document *new_ = new_it->second.get();
|
GeneralDocument *new_ = new_it->second.get();
|
||||||
CHECK(new_ != nullptr);
|
CHECK(new_ != nullptr);
|
||||||
|
|
||||||
if (old_->thumbnail != new_->thumbnail) {
|
if (old_->thumbnail != new_->thumbnail) {
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
|
|
||||||
#include "td/telegram/DialogId.h"
|
#include "td/telegram/DialogId.h"
|
||||||
|
#include "td/telegram/Document.h"
|
||||||
#include "td/telegram/files/FileId.h"
|
#include "td/telegram/files/FileId.h"
|
||||||
#include "td/telegram/Photo.h"
|
#include "td/telegram/Photo.h"
|
||||||
#include "td/telegram/SecretInputMedia.h"
|
#include "td/telegram/SecretInputMedia.h"
|
||||||
@ -30,8 +31,6 @@ class DocumentsManager {
|
|||||||
public:
|
public:
|
||||||
explicit DocumentsManager(Td *td);
|
explicit DocumentsManager(Td *td);
|
||||||
|
|
||||||
enum class DocumentType : int32 { Unknown, Animation, Audio, General, Sticker, Video, VideoNote, VoiceNote };
|
|
||||||
|
|
||||||
class RemoteDocument {
|
class RemoteDocument {
|
||||||
public:
|
public:
|
||||||
tl_object_ptr<telegram_api::document> document;
|
tl_object_ptr<telegram_api::document> document;
|
||||||
@ -77,9 +76,9 @@ class DocumentsManager {
|
|||||||
|
|
||||||
tl_object_ptr<td_api::document> get_document_object(FileId file_id);
|
tl_object_ptr<td_api::document> get_document_object(FileId file_id);
|
||||||
|
|
||||||
std::pair<DocumentType, FileId> on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id,
|
Document on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id,
|
||||||
MultiPromiseActor *load_data_multipromise_ptr = nullptr,
|
MultiPromiseActor *load_data_multipromise_ptr = nullptr,
|
||||||
DocumentType default_document_type = DocumentType::General);
|
Document::Type default_document_type = Document::Type::General);
|
||||||
|
|
||||||
void create_document(FileId file_id, PhotoSize thumbnail, string file_name, string mime_type, bool replace);
|
void create_document(FileId file_id, PhotoSize thumbnail, string file_name, string mime_type, bool replace);
|
||||||
|
|
||||||
@ -110,7 +109,7 @@ class DocumentsManager {
|
|||||||
string get_document_search_text(FileId file_id) const;
|
string get_document_search_text(FileId file_id) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Document {
|
class GeneralDocument {
|
||||||
public:
|
public:
|
||||||
string file_name;
|
string file_name;
|
||||||
string mime_type;
|
string mime_type;
|
||||||
@ -120,12 +119,12 @@ class DocumentsManager {
|
|||||||
bool is_changed = true;
|
bool is_changed = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Document *get_document(FileId file_id) const;
|
const GeneralDocument *get_document(FileId file_id) const;
|
||||||
|
|
||||||
FileId on_get_document(unique_ptr<Document> new_document, bool replace);
|
FileId on_get_document(unique_ptr<GeneralDocument> new_document, bool replace);
|
||||||
|
|
||||||
Td *td_;
|
Td *td_;
|
||||||
std::unordered_map<FileId, unique_ptr<Document>, FileIdHash> documents_; // file_id -> Document
|
std::unordered_map<FileId, unique_ptr<GeneralDocument>, FileIdHash> documents_; // file_id -> GeneralDocument
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -21,7 +21,7 @@ void DocumentsManager::store_document(FileId file_id, StorerT &storer) const {
|
|||||||
LOG(DEBUG) << "Store document " << file_id;
|
LOG(DEBUG) << "Store document " << file_id;
|
||||||
auto it = documents_.find(file_id);
|
auto it = documents_.find(file_id);
|
||||||
CHECK(it != documents_.end());
|
CHECK(it != documents_.end());
|
||||||
const Document *document = it->second.get();
|
const GeneralDocument *document = it->second.get();
|
||||||
store(document->file_name, storer);
|
store(document->file_name, storer);
|
||||||
store(document->mime_type, storer);
|
store(document->mime_type, storer);
|
||||||
store(document->thumbnail, storer);
|
store(document->thumbnail, storer);
|
||||||
@ -30,7 +30,7 @@ void DocumentsManager::store_document(FileId file_id, StorerT &storer) const {
|
|||||||
|
|
||||||
template <class ParserT>
|
template <class ParserT>
|
||||||
FileId DocumentsManager::parse_document(ParserT &parser) {
|
FileId DocumentsManager::parse_document(ParserT &parser) {
|
||||||
auto document = make_unique<Document>();
|
auto document = make_unique<GeneralDocument>();
|
||||||
parse(document->file_name, parser);
|
parse(document->file_name, parser);
|
||||||
parse(document->mime_type, parser);
|
parse(document->mime_type, parser);
|
||||||
parse(document->thumbnail, parser);
|
parse(document->thumbnail, parser);
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "td/telegram/AnimationsManager.h"
|
#include "td/telegram/AnimationsManager.h"
|
||||||
#include "td/telegram/ContactsManager.h"
|
#include "td/telegram/ContactsManager.h"
|
||||||
|
#include "td/telegram/Document.h"
|
||||||
#include "td/telegram/DocumentsManager.h"
|
#include "td/telegram/DocumentsManager.h"
|
||||||
#include "td/telegram/misc.h"
|
#include "td/telegram/misc.h"
|
||||||
#include "td/telegram/Photo.h"
|
#include "td/telegram/Photo.h"
|
||||||
@ -42,21 +43,10 @@ Game::Game(Td *td, string title, string description, tl_object_ptr<telegram_api:
|
|||||||
if (document_id == telegram_api::document::ID) {
|
if (document_id == telegram_api::document::ID) {
|
||||||
auto parsed_document =
|
auto parsed_document =
|
||||||
td->documents_manager_->on_get_document(move_tl_object_as<telegram_api::document>(document), owner_dialog_id);
|
td->documents_manager_->on_get_document(move_tl_object_as<telegram_api::document>(document), owner_dialog_id);
|
||||||
switch (parsed_document.first) {
|
if (parsed_document.type == Document::Type::Animation) {
|
||||||
case DocumentsManager::DocumentType::Animation:
|
animation_file_id_ = parsed_document.file_id;
|
||||||
animation_file_id_ = parsed_document.second;
|
} else {
|
||||||
break;
|
|
||||||
case DocumentsManager::DocumentType::Audio:
|
|
||||||
case DocumentsManager::DocumentType::General:
|
|
||||||
case DocumentsManager::DocumentType::Sticker:
|
|
||||||
case DocumentsManager::DocumentType::Video:
|
|
||||||
case DocumentsManager::DocumentType::VideoNote:
|
|
||||||
case DocumentsManager::DocumentType::VoiceNote:
|
|
||||||
case DocumentsManager::DocumentType::Unknown:
|
|
||||||
LOG(ERROR) << "Receive non-animation document in the game";
|
LOG(ERROR) << "Receive non-animation document in the game";
|
||||||
break;
|
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "td/telegram/AuthManager.h"
|
#include "td/telegram/AuthManager.h"
|
||||||
#include "td/telegram/Contact.h"
|
#include "td/telegram/Contact.h"
|
||||||
#include "td/telegram/ContactsManager.h"
|
#include "td/telegram/ContactsManager.h"
|
||||||
|
#include "td/telegram/Document.h"
|
||||||
#include "td/telegram/DocumentsManager.h"
|
#include "td/telegram/DocumentsManager.h"
|
||||||
#include "td/telegram/files/FileManager.h"
|
#include "td/telegram/files/FileManager.h"
|
||||||
#include "td/telegram/files/FileType.h"
|
#include "td/telegram/files/FileType.h"
|
||||||
@ -1150,17 +1151,17 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
|
|||||||
|
|
||||||
auto parsed_document = td_->documents_manager_->on_get_document(
|
auto parsed_document = td_->documents_manager_->on_get_document(
|
||||||
move_tl_object_as<telegram_api::document>(document_ptr), DialogId());
|
move_tl_object_as<telegram_api::document>(document_ptr), DialogId());
|
||||||
switch (parsed_document.first) {
|
switch (parsed_document.type) {
|
||||||
case DocumentsManager::DocumentType::Animation: {
|
case Document::Type::Animation: {
|
||||||
LOG_IF(WARNING, result->type_ != "gif") << "Wrong result type " << result->type_;
|
LOG_IF(WARNING, result->type_ != "gif") << "Wrong result type " << result->type_;
|
||||||
|
|
||||||
auto animation = make_tl_object<td_api::inlineQueryResultAnimation>();
|
auto animation = make_tl_object<td_api::inlineQueryResultAnimation>();
|
||||||
animation->id_ = std::move(result->id_);
|
animation->id_ = std::move(result->id_);
|
||||||
animation->animation_ =
|
animation->animation_ =
|
||||||
td_->animations_manager_->get_animation_object(parsed_document.second, "inlineQueryResultAnimation");
|
td_->animations_manager_->get_animation_object(parsed_document.file_id, "inlineQueryResultAnimation");
|
||||||
animation->title_ = std::move(result->title_);
|
animation->title_ = std::move(result->title_);
|
||||||
|
|
||||||
if (!register_inline_message_content(results->query_id_, animation->id_, parsed_document.second,
|
if (!register_inline_message_content(results->query_id_, animation->id_, parsed_document.file_id,
|
||||||
std::move(result->send_message_),
|
std::move(result->send_message_),
|
||||||
td_api::inputMessageAnimation::ID)) {
|
td_api::inputMessageAnimation::ID)) {
|
||||||
continue;
|
continue;
|
||||||
@ -1168,30 +1169,30 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
|
|||||||
output_result = std::move(animation);
|
output_result = std::move(animation);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DocumentsManager::DocumentType::Audio: {
|
case Document::Type::Audio: {
|
||||||
LOG_IF(WARNING, result->type_ != "audio") << "Wrong result type " << result->type_;
|
LOG_IF(WARNING, result->type_ != "audio") << "Wrong result type " << result->type_;
|
||||||
|
|
||||||
auto audio = make_tl_object<td_api::inlineQueryResultAudio>();
|
auto audio = make_tl_object<td_api::inlineQueryResultAudio>();
|
||||||
audio->id_ = std::move(result->id_);
|
audio->id_ = std::move(result->id_);
|
||||||
audio->audio_ = td_->audios_manager_->get_audio_object(parsed_document.second);
|
audio->audio_ = td_->audios_manager_->get_audio_object(parsed_document.file_id);
|
||||||
|
|
||||||
if (!register_inline_message_content(results->query_id_, audio->id_, parsed_document.second,
|
if (!register_inline_message_content(results->query_id_, audio->id_, parsed_document.file_id,
|
||||||
std::move(result->send_message_), td_api::inputMessageAudio::ID)) {
|
std::move(result->send_message_), td_api::inputMessageAudio::ID)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
output_result = std::move(audio);
|
output_result = std::move(audio);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DocumentsManager::DocumentType::General: {
|
case Document::Type::General: {
|
||||||
LOG_IF(WARNING, result->type_ != "file") << "Wrong result type " << result->type_;
|
LOG_IF(WARNING, result->type_ != "file") << "Wrong result type " << result->type_;
|
||||||
|
|
||||||
auto document = make_tl_object<td_api::inlineQueryResultDocument>();
|
auto document = make_tl_object<td_api::inlineQueryResultDocument>();
|
||||||
document->id_ = std::move(result->id_);
|
document->id_ = std::move(result->id_);
|
||||||
document->document_ = td_->documents_manager_->get_document_object(parsed_document.second);
|
document->document_ = td_->documents_manager_->get_document_object(parsed_document.file_id);
|
||||||
document->title_ = std::move(result->title_);
|
document->title_ = std::move(result->title_);
|
||||||
document->description_ = std::move(result->description_);
|
document->description_ = std::move(result->description_);
|
||||||
|
|
||||||
if (!register_inline_message_content(results->query_id_, document->id_, parsed_document.second,
|
if (!register_inline_message_content(results->query_id_, document->id_, parsed_document.file_id,
|
||||||
std::move(result->send_message_),
|
std::move(result->send_message_),
|
||||||
td_api::inputMessageDocument::ID)) {
|
td_api::inputMessageDocument::ID)) {
|
||||||
continue;
|
continue;
|
||||||
@ -1199,48 +1200,48 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
|
|||||||
output_result = std::move(document);
|
output_result = std::move(document);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DocumentsManager::DocumentType::Sticker: {
|
case Document::Type::Sticker: {
|
||||||
LOG_IF(WARNING, result->type_ != "sticker") << "Wrong result type " << result->type_;
|
LOG_IF(WARNING, result->type_ != "sticker") << "Wrong result type " << result->type_;
|
||||||
|
|
||||||
auto sticker = make_tl_object<td_api::inlineQueryResultSticker>();
|
auto sticker = make_tl_object<td_api::inlineQueryResultSticker>();
|
||||||
sticker->id_ = std::move(result->id_);
|
sticker->id_ = std::move(result->id_);
|
||||||
sticker->sticker_ = td_->stickers_manager_->get_sticker_object(parsed_document.second);
|
sticker->sticker_ = td_->stickers_manager_->get_sticker_object(parsed_document.file_id);
|
||||||
|
|
||||||
if (!register_inline_message_content(results->query_id_, sticker->id_, parsed_document.second,
|
if (!register_inline_message_content(results->query_id_, sticker->id_, parsed_document.file_id,
|
||||||
std::move(result->send_message_), td_api::inputMessageSticker::ID)) {
|
std::move(result->send_message_), td_api::inputMessageSticker::ID)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
output_result = std::move(sticker);
|
output_result = std::move(sticker);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DocumentsManager::DocumentType::Video: {
|
case Document::Type::Video: {
|
||||||
LOG_IF(WARNING, result->type_ != "video") << "Wrong result type " << result->type_;
|
LOG_IF(WARNING, result->type_ != "video") << "Wrong result type " << result->type_;
|
||||||
|
|
||||||
auto video = make_tl_object<td_api::inlineQueryResultVideo>();
|
auto video = make_tl_object<td_api::inlineQueryResultVideo>();
|
||||||
video->id_ = std::move(result->id_);
|
video->id_ = std::move(result->id_);
|
||||||
video->video_ = td_->videos_manager_->get_video_object(parsed_document.second);
|
video->video_ = td_->videos_manager_->get_video_object(parsed_document.file_id);
|
||||||
video->title_ = std::move(result->title_);
|
video->title_ = std::move(result->title_);
|
||||||
video->description_ = std::move(result->description_);
|
video->description_ = std::move(result->description_);
|
||||||
|
|
||||||
if (!register_inline_message_content(results->query_id_, video->id_, parsed_document.second,
|
if (!register_inline_message_content(results->query_id_, video->id_, parsed_document.file_id,
|
||||||
std::move(result->send_message_), td_api::inputMessageVideo::ID)) {
|
std::move(result->send_message_), td_api::inputMessageVideo::ID)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
output_result = std::move(video);
|
output_result = std::move(video);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DocumentsManager::DocumentType::VideoNote:
|
case Document::Type::VideoNote:
|
||||||
// FIXME
|
// FIXME
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::VoiceNote: {
|
case Document::Type::VoiceNote: {
|
||||||
LOG_IF(WARNING, result->type_ != "voice") << "Wrong result type " << result->type_;
|
LOG_IF(WARNING, result->type_ != "voice") << "Wrong result type " << result->type_;
|
||||||
|
|
||||||
auto voice_note = make_tl_object<td_api::inlineQueryResultVoiceNote>();
|
auto voice_note = make_tl_object<td_api::inlineQueryResultVoiceNote>();
|
||||||
voice_note->id_ = std::move(result->id_);
|
voice_note->id_ = std::move(result->id_);
|
||||||
voice_note->voice_note_ = td_->voice_notes_manager_->get_voice_note_object(parsed_document.second);
|
voice_note->voice_note_ = td_->voice_notes_manager_->get_voice_note_object(parsed_document.file_id);
|
||||||
voice_note->title_ = std::move(result->title_);
|
voice_note->title_ = std::move(result->title_);
|
||||||
|
|
||||||
if (!register_inline_message_content(results->query_id_, voice_note->id_, parsed_document.second,
|
if (!register_inline_message_content(results->query_id_, voice_note->id_, parsed_document.file_id,
|
||||||
std::move(result->send_message_),
|
std::move(result->send_message_),
|
||||||
td_api::inputMessageVoiceNote::ID)) {
|
td_api::inputMessageVoiceNote::ID)) {
|
||||||
continue;
|
continue;
|
||||||
@ -1248,7 +1249,7 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
|
|||||||
output_result = std::move(voice_note);
|
output_result = std::move(voice_note);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DocumentsManager::DocumentType::Unknown:
|
case Document::Type::Unknown:
|
||||||
// invalid document
|
// invalid document
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -1418,21 +1419,21 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
|
|||||||
}
|
}
|
||||||
auto default_document_type = [type = result->type_, is_animation] {
|
auto default_document_type = [type = result->type_, is_animation] {
|
||||||
if (type == "audio") {
|
if (type == "audio") {
|
||||||
return DocumentsManager::DocumentType::Audio;
|
return Document::Type::Audio;
|
||||||
}
|
}
|
||||||
if (is_animation) {
|
if (is_animation) {
|
||||||
return DocumentsManager::DocumentType::Animation;
|
return Document::Type::Animation;
|
||||||
}
|
}
|
||||||
if (type == "sticker") {
|
if (type == "sticker") {
|
||||||
return DocumentsManager::DocumentType::Sticker;
|
return Document::Type::Sticker;
|
||||||
}
|
}
|
||||||
if (type == "video") {
|
if (type == "video") {
|
||||||
return DocumentsManager::DocumentType::Video;
|
return Document::Type::Video;
|
||||||
}
|
}
|
||||||
if (type == "voice") {
|
if (type == "voice") {
|
||||||
return DocumentsManager::DocumentType::VoiceNote;
|
return Document::Type::VoiceNote;
|
||||||
}
|
}
|
||||||
return DocumentsManager::DocumentType::General;
|
return Document::Type::General;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
auto parsed_document = td_->documents_manager_->on_get_document(
|
auto parsed_document = td_->documents_manager_->on_get_document(
|
||||||
@ -1441,11 +1442,11 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
|
|||||||
std::move(result->thumb_)),
|
std::move(result->thumb_)),
|
||||||
std::move(attributes)},
|
std::move(attributes)},
|
||||||
DialogId(), nullptr, default_document_type);
|
DialogId(), nullptr, default_document_type);
|
||||||
auto file_id = parsed_document.second;
|
auto file_id = parsed_document.file_id;
|
||||||
if (!file_id.is_valid()) {
|
if (!file_id.is_valid()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (result->type_ == "audio" && parsed_document.first == DocumentsManager::DocumentType::Audio) {
|
if (result->type_ == "audio" && parsed_document.type == Document::Type::Audio) {
|
||||||
auto audio = make_tl_object<td_api::inlineQueryResultAudio>();
|
auto audio = make_tl_object<td_api::inlineQueryResultAudio>();
|
||||||
audio->id_ = std::move(result->id_);
|
audio->id_ = std::move(result->id_);
|
||||||
audio->audio_ = td_->audios_manager_->get_audio_object(file_id);
|
audio->audio_ = td_->audios_manager_->get_audio_object(file_id);
|
||||||
@ -1454,7 +1455,7 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
output_result = std::move(audio);
|
output_result = std::move(audio);
|
||||||
} else if (result->type_ == "file" && parsed_document.first == DocumentsManager::DocumentType::General) {
|
} else if (result->type_ == "file" && parsed_document.type == Document::Type::General) {
|
||||||
auto document = make_tl_object<td_api::inlineQueryResultDocument>();
|
auto document = make_tl_object<td_api::inlineQueryResultDocument>();
|
||||||
document->id_ = std::move(result->id_);
|
document->id_ = std::move(result->id_);
|
||||||
document->document_ = td_->documents_manager_->get_document_object(file_id);
|
document->document_ = td_->documents_manager_->get_document_object(file_id);
|
||||||
@ -1465,7 +1466,7 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
output_result = std::move(document);
|
output_result = std::move(document);
|
||||||
} else if (is_animation && parsed_document.first == DocumentsManager::DocumentType::Animation) {
|
} else if (is_animation && parsed_document.type == Document::Type::Animation) {
|
||||||
auto animation = make_tl_object<td_api::inlineQueryResultAnimation>();
|
auto animation = make_tl_object<td_api::inlineQueryResultAnimation>();
|
||||||
animation->id_ = std::move(result->id_);
|
animation->id_ = std::move(result->id_);
|
||||||
animation->animation_ =
|
animation->animation_ =
|
||||||
@ -1476,7 +1477,7 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
output_result = std::move(animation);
|
output_result = std::move(animation);
|
||||||
} else if (result->type_ == "sticker" && parsed_document.first == DocumentsManager::DocumentType::Sticker) {
|
} else if (result->type_ == "sticker" && parsed_document.type == Document::Type::Sticker) {
|
||||||
auto sticker = make_tl_object<td_api::inlineQueryResultSticker>();
|
auto sticker = make_tl_object<td_api::inlineQueryResultSticker>();
|
||||||
sticker->id_ = std::move(result->id_);
|
sticker->id_ = std::move(result->id_);
|
||||||
sticker->sticker_ = td_->stickers_manager_->get_sticker_object(file_id);
|
sticker->sticker_ = td_->stickers_manager_->get_sticker_object(file_id);
|
||||||
@ -1485,7 +1486,7 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
output_result = std::move(sticker);
|
output_result = std::move(sticker);
|
||||||
} else if (result->type_ == "video" && parsed_document.first == DocumentsManager::DocumentType::Video) {
|
} else if (result->type_ == "video" && parsed_document.type == Document::Type::Video) {
|
||||||
auto video = make_tl_object<td_api::inlineQueryResultVideo>();
|
auto video = make_tl_object<td_api::inlineQueryResultVideo>();
|
||||||
video->id_ = std::move(result->id_);
|
video->id_ = std::move(result->id_);
|
||||||
video->video_ = td_->videos_manager_->get_video_object(file_id);
|
video->video_ = td_->videos_manager_->get_video_object(file_id);
|
||||||
@ -1496,7 +1497,7 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
output_result = std::move(video);
|
output_result = std::move(video);
|
||||||
} else if (result->type_ == "voice" && parsed_document.first == DocumentsManager::DocumentType::VoiceNote) {
|
} else if (result->type_ == "voice" && parsed_document.type == Document::Type::VoiceNote) {
|
||||||
auto voice_note = make_tl_object<td_api::inlineQueryResultVoiceNote>();
|
auto voice_note = make_tl_object<td_api::inlineQueryResultVoiceNote>();
|
||||||
voice_note->id_ = std::move(result->id_);
|
voice_note->id_ = std::move(result->id_);
|
||||||
voice_note->voice_note_ = td_->voice_notes_manager_->get_voice_note_object(file_id);
|
voice_note->voice_note_ = td_->voice_notes_manager_->get_voice_note_object(file_id);
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "td/telegram/ChatId.h"
|
#include "td/telegram/ChatId.h"
|
||||||
#include "td/telegram/Contact.h"
|
#include "td/telegram/Contact.h"
|
||||||
#include "td/telegram/ContactsManager.h"
|
#include "td/telegram/ContactsManager.h"
|
||||||
|
#include "td/telegram/Document.h"
|
||||||
#include "td/telegram/DocumentsManager.h"
|
#include "td/telegram/DocumentsManager.h"
|
||||||
#include "td/telegram/DocumentsManager.hpp"
|
#include "td/telegram/DocumentsManager.hpp"
|
||||||
#include "td/telegram/files/FileId.h"
|
#include "td/telegram/files/FileId.h"
|
||||||
@ -3491,29 +3492,28 @@ static tl_object_ptr<ToT> secret_to_telegram(FromT &from) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unique_ptr<MessageContent> get_document_message_content(
|
static unique_ptr<MessageContent> get_document_message_content(Document &&parsed_document, FormattedText &&caption,
|
||||||
std::pair<DocumentsManager::DocumentType, FileId> &&parsed_document, FormattedText &&caption, bool is_opened) {
|
bool is_opened) {
|
||||||
auto document_type = parsed_document.first;
|
auto file_id = parsed_document.file_id;
|
||||||
auto file_id = parsed_document.second;
|
if (parsed_document.type != Document::Type::Unknown) {
|
||||||
if (document_type != DocumentsManager::DocumentType::Unknown) {
|
|
||||||
CHECK(file_id.is_valid());
|
CHECK(file_id.is_valid());
|
||||||
}
|
}
|
||||||
switch (document_type) {
|
switch (parsed_document.type) {
|
||||||
case DocumentsManager::DocumentType::Animation:
|
case Document::Type::Animation:
|
||||||
return make_unique<MessageAnimation>(file_id, std::move(caption));
|
return make_unique<MessageAnimation>(file_id, std::move(caption));
|
||||||
case DocumentsManager::DocumentType::Audio:
|
case Document::Type::Audio:
|
||||||
return make_unique<MessageAudio>(file_id, std::move(caption));
|
return make_unique<MessageAudio>(file_id, std::move(caption));
|
||||||
case DocumentsManager::DocumentType::General:
|
case Document::Type::General:
|
||||||
return make_unique<MessageDocument>(file_id, std::move(caption));
|
return make_unique<MessageDocument>(file_id, std::move(caption));
|
||||||
case DocumentsManager::DocumentType::Sticker:
|
case Document::Type::Sticker:
|
||||||
return make_unique<MessageSticker>(file_id);
|
return make_unique<MessageSticker>(file_id);
|
||||||
case DocumentsManager::DocumentType::Unknown:
|
case Document::Type::Unknown:
|
||||||
return make_unique<MessageUnsupported>();
|
return make_unique<MessageUnsupported>();
|
||||||
case DocumentsManager::DocumentType::Video:
|
case Document::Type::Video:
|
||||||
return make_unique<MessageVideo>(file_id, std::move(caption));
|
return make_unique<MessageVideo>(file_id, std::move(caption));
|
||||||
case DocumentsManager::DocumentType::VideoNote:
|
case Document::Type::VideoNote:
|
||||||
return make_unique<MessageVideoNote>(file_id, is_opened);
|
return make_unique<MessageVideoNote>(file_id, is_opened);
|
||||||
case DocumentsManager::DocumentType::VoiceNote:
|
case Document::Type::VoiceNote:
|
||||||
return make_unique<MessageVoiceNote>(file_id, std::move(caption), is_opened);
|
return make_unique<MessageVoiceNote>(file_id, std::move(caption), is_opened);
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "td/telegram/ConfigShared.h"
|
#include "td/telegram/ConfigShared.h"
|
||||||
#include "td/telegram/ContactsManager.h"
|
#include "td/telegram/ContactsManager.h"
|
||||||
#include "td/telegram/DeviceTokenManager.h"
|
#include "td/telegram/DeviceTokenManager.h"
|
||||||
|
#include "td/telegram/Document.h"
|
||||||
#include "td/telegram/DocumentsManager.h"
|
#include "td/telegram/DocumentsManager.h"
|
||||||
#include "td/telegram/files/FileManager.h"
|
#include "td/telegram/files/FileManager.h"
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
@ -3236,18 +3237,17 @@ Status NotificationManager::process_push_notification_payload(string payload, Pr
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case telegram_api::document::ID: {
|
case telegram_api::document::ID: {
|
||||||
std::pair<DocumentsManager::DocumentType, FileId> attached_document =
|
auto parsed_document = td_->documents_manager_->on_get_document(
|
||||||
td_->documents_manager_->on_get_document(telegram_api::move_object_as<telegram_api::document>(result),
|
telegram_api::move_object_as<telegram_api::document>(result), dialog_id);
|
||||||
dialog_id);
|
switch (parsed_document.type) {
|
||||||
switch (attached_document.first) {
|
case Document::Type::Animation:
|
||||||
case DocumentsManager::DocumentType::Animation:
|
case Document::Type::Audio:
|
||||||
case DocumentsManager::DocumentType::Audio:
|
case Document::Type::General:
|
||||||
case DocumentsManager::DocumentType::General:
|
case Document::Type::Sticker:
|
||||||
case DocumentsManager::DocumentType::Sticker:
|
case Document::Type::Unknown:
|
||||||
case DocumentsManager::DocumentType::Unknown:
|
case Document::Type::Video:
|
||||||
case DocumentsManager::DocumentType::Video:
|
case Document::Type::VideoNote:
|
||||||
case DocumentsManager::DocumentType::VideoNote:
|
case Document::Type::VoiceNote:
|
||||||
case DocumentsManager::DocumentType::VoiceNote:
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "td/telegram/ConfigShared.h"
|
#include "td/telegram/ConfigShared.h"
|
||||||
#include "td/telegram/ContactsManager.h"
|
#include "td/telegram/ContactsManager.h"
|
||||||
#include "td/telegram/DialogId.h"
|
#include "td/telegram/DialogId.h"
|
||||||
|
#include "td/telegram/Document.h"
|
||||||
#include "td/telegram/DocumentsManager.h"
|
#include "td/telegram/DocumentsManager.h"
|
||||||
#include "td/telegram/FileReferenceManager.h"
|
#include "td/telegram/FileReferenceManager.h"
|
||||||
#include "td/telegram/files/FileLocation.h"
|
#include "td/telegram/files/FileLocation.h"
|
||||||
@ -3432,11 +3433,11 @@ void StickersManager::on_uploaded_sticker_file(FileId file_id, tl_object_ptr<tel
|
|||||||
|
|
||||||
auto parsed_document = td_->documents_manager_->on_get_document(
|
auto parsed_document = td_->documents_manager_->on_get_document(
|
||||||
move_tl_object_as<telegram_api::document>(document_ptr), DialogId(), nullptr);
|
move_tl_object_as<telegram_api::document>(document_ptr), DialogId(), nullptr);
|
||||||
if (parsed_document.first != DocumentsManager::DocumentType::General) {
|
if (parsed_document.type != Document::Type::General) {
|
||||||
return promise.set_error(Status::Error(400, "Wrong file type"));
|
return promise.set_error(Status::Error(400, "Wrong file type"));
|
||||||
}
|
}
|
||||||
|
|
||||||
td_->documents_manager_->merge_documents(parsed_document.second, file_id, true);
|
td_->documents_manager_->merge_documents(parsed_document.file_id, file_id, true);
|
||||||
promise.set_value(Unit());
|
promise.set_value(Unit());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "td/telegram/AudiosManager.hpp"
|
#include "td/telegram/AudiosManager.hpp"
|
||||||
#include "td/telegram/ChannelId.h"
|
#include "td/telegram/ChannelId.h"
|
||||||
#include "td/telegram/ContactsManager.h"
|
#include "td/telegram/ContactsManager.h"
|
||||||
|
#include "td/telegram/Document.h"
|
||||||
#include "td/telegram/DocumentsManager.h"
|
#include "td/telegram/DocumentsManager.h"
|
||||||
#include "td/telegram/DocumentsManager.hpp"
|
#include "td/telegram/DocumentsManager.hpp"
|
||||||
#include "td/telegram/FileReferenceManager.h"
|
#include "td/telegram/FileReferenceManager.h"
|
||||||
@ -209,8 +210,7 @@ class WebPagesManager::WebPage {
|
|||||||
Dimensions embed_dimensions;
|
Dimensions embed_dimensions;
|
||||||
int32 duration = 0;
|
int32 duration = 0;
|
||||||
string author;
|
string author;
|
||||||
DocumentsManager::DocumentType document_type = DocumentsManager::DocumentType::Unknown;
|
Document document;
|
||||||
FileId document_file_id;
|
|
||||||
WebPageInstantView instant_view;
|
WebPageInstantView instant_view;
|
||||||
|
|
||||||
FileSourceId file_source_id;
|
FileSourceId file_source_id;
|
||||||
@ -229,7 +229,7 @@ class WebPagesManager::WebPage {
|
|||||||
bool has_embed_dimensions = has_embed && embed_dimensions != Dimensions();
|
bool has_embed_dimensions = has_embed && embed_dimensions != Dimensions();
|
||||||
bool has_duration = duration > 0;
|
bool has_duration = duration > 0;
|
||||||
bool has_author = !author.empty();
|
bool has_author = !author.empty();
|
||||||
bool has_document = document_type != DocumentsManager::DocumentType::Unknown;
|
bool has_document = document.type != Document::Type::Unknown;
|
||||||
bool has_instant_view = !instant_view.is_empty;
|
bool has_instant_view = !instant_view.is_empty;
|
||||||
bool is_instant_view_v2 = instant_view.is_v2;
|
bool is_instant_view_v2 = instant_view.is_v2;
|
||||||
bool has_no_hash = true;
|
bool has_no_hash = true;
|
||||||
@ -283,30 +283,30 @@ class WebPagesManager::WebPage {
|
|||||||
Td *td = storer.context()->td().get_actor_unsafe();
|
Td *td = storer.context()->td().get_actor_unsafe();
|
||||||
CHECK(td != nullptr);
|
CHECK(td != nullptr);
|
||||||
|
|
||||||
store(document_type, storer);
|
store(document.type, storer);
|
||||||
switch (document_type) {
|
switch (document.type) {
|
||||||
case DocumentsManager::DocumentType::Animation:
|
case Document::Type::Animation:
|
||||||
td->animations_manager_->store_animation(document_file_id, storer);
|
td->animations_manager_->store_animation(document.file_id, storer);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::Audio:
|
case Document::Type::Audio:
|
||||||
td->audios_manager_->store_audio(document_file_id, storer);
|
td->audios_manager_->store_audio(document.file_id, storer);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::General:
|
case Document::Type::General:
|
||||||
td->documents_manager_->store_document(document_file_id, storer);
|
td->documents_manager_->store_document(document.file_id, storer);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::Sticker:
|
case Document::Type::Sticker:
|
||||||
td->stickers_manager_->store_sticker(document_file_id, false, storer);
|
td->stickers_manager_->store_sticker(document.file_id, false, storer);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::Video:
|
case Document::Type::Video:
|
||||||
td->videos_manager_->store_video(document_file_id, storer);
|
td->videos_manager_->store_video(document.file_id, storer);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::VideoNote:
|
case Document::Type::VideoNote:
|
||||||
td->video_notes_manager_->store_video_note(document_file_id, storer);
|
td->video_notes_manager_->store_video_note(document.file_id, storer);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::VoiceNote:
|
case Document::Type::VoiceNote:
|
||||||
td->voice_notes_manager_->store_voice_note(document_file_id, storer);
|
td->voice_notes_manager_->store_voice_note(document.file_id, storer);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::Unknown:
|
case Document::Type::Unknown:
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
@ -385,36 +385,36 @@ class WebPagesManager::WebPage {
|
|||||||
Td *td = parser.context()->td().get_actor_unsafe();
|
Td *td = parser.context()->td().get_actor_unsafe();
|
||||||
CHECK(td != nullptr);
|
CHECK(td != nullptr);
|
||||||
|
|
||||||
parse(document_type, parser);
|
parse(document.type, parser);
|
||||||
switch (document_type) {
|
switch (document.type) {
|
||||||
case DocumentsManager::DocumentType::Animation:
|
case Document::Type::Animation:
|
||||||
document_file_id = td->animations_manager_->parse_animation(parser);
|
document.file_id = td->animations_manager_->parse_animation(parser);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::Audio:
|
case Document::Type::Audio:
|
||||||
document_file_id = td->audios_manager_->parse_audio(parser);
|
document.file_id = td->audios_manager_->parse_audio(parser);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::General:
|
case Document::Type::General:
|
||||||
document_file_id = td->documents_manager_->parse_document(parser);
|
document.file_id = td->documents_manager_->parse_document(parser);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::Sticker:
|
case Document::Type::Sticker:
|
||||||
document_file_id = td->stickers_manager_->parse_sticker(false, parser);
|
document.file_id = td->stickers_manager_->parse_sticker(false, parser);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::Video:
|
case Document::Type::Video:
|
||||||
document_file_id = td->videos_manager_->parse_video(parser);
|
document.file_id = td->videos_manager_->parse_video(parser);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::VideoNote:
|
case Document::Type::VideoNote:
|
||||||
document_file_id = td->video_notes_manager_->parse_video_note(parser);
|
document.file_id = td->video_notes_manager_->parse_video_note(parser);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::VoiceNote:
|
case Document::Type::VoiceNote:
|
||||||
document_file_id = td->voice_notes_manager_->parse_voice_note(parser);
|
document.file_id = td->voice_notes_manager_->parse_voice_note(parser);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::Unknown:
|
case Document::Type::Unknown:
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
if (!document_file_id.is_valid()) {
|
if (!document.file_id.is_valid()) {
|
||||||
LOG(ERROR) << "Parse invalid document_file_id";
|
LOG(ERROR) << "Parse invalid document.file_id";
|
||||||
document_type = DocumentsManager::DocumentType::Unknown;
|
document = Document();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2207,8 +2207,7 @@ WebPageId WebPagesManager::on_get_web_page(tl_object_ptr<telegram_api::WebPage>
|
|||||||
if (document_id == telegram_api::document::ID) {
|
if (document_id == telegram_api::document::ID) {
|
||||||
auto parsed_document = td_->documents_manager_->on_get_document(
|
auto parsed_document = td_->documents_manager_->on_get_document(
|
||||||
move_tl_object_as<telegram_api::document>(web_page->document_), owner_dialog_id);
|
move_tl_object_as<telegram_api::document>(web_page->document_), owner_dialog_id);
|
||||||
page->document_type = parsed_document.first;
|
page->document = parsed_document;
|
||||||
page->document_file_id = parsed_document.second;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (web_page->flags_ & WEBPAGE_FLAG_HAS_INSTANT_VIEW) {
|
if (web_page->flags_ & WEBPAGE_FLAG_HAS_INSTANT_VIEW) {
|
||||||
@ -2808,26 +2807,26 @@ tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId we
|
|||||||
web_page->url, web_page->display_url, web_page->type, web_page->site_name, web_page->title, web_page->description,
|
web_page->url, web_page->display_url, web_page->type, web_page->site_name, web_page->title, web_page->description,
|
||||||
get_photo_object(td_->file_manager_.get(), &web_page->photo), web_page->embed_url, web_page->embed_type,
|
get_photo_object(td_->file_manager_.get(), &web_page->photo), web_page->embed_url, web_page->embed_type,
|
||||||
web_page->embed_dimensions.width, web_page->embed_dimensions.height, web_page->duration, web_page->author,
|
web_page->embed_dimensions.width, web_page->embed_dimensions.height, web_page->duration, web_page->author,
|
||||||
web_page->document_type == DocumentsManager::DocumentType::Animation
|
web_page->document.type == Document::Type::Animation
|
||||||
? td_->animations_manager_->get_animation_object(web_page->document_file_id, "get_web_page_object")
|
? td_->animations_manager_->get_animation_object(web_page->document.file_id, "get_web_page_object")
|
||||||
: nullptr,
|
: nullptr,
|
||||||
web_page->document_type == DocumentsManager::DocumentType::Audio
|
web_page->document.type == Document::Type::Audio
|
||||||
? td_->audios_manager_->get_audio_object(web_page->document_file_id)
|
? td_->audios_manager_->get_audio_object(web_page->document.file_id)
|
||||||
: nullptr,
|
: nullptr,
|
||||||
web_page->document_type == DocumentsManager::DocumentType::General
|
web_page->document.type == Document::Type::General
|
||||||
? td_->documents_manager_->get_document_object(web_page->document_file_id)
|
? td_->documents_manager_->get_document_object(web_page->document.file_id)
|
||||||
: nullptr,
|
: nullptr,
|
||||||
web_page->document_type == DocumentsManager::DocumentType::Sticker
|
web_page->document.type == Document::Type::Sticker
|
||||||
? td_->stickers_manager_->get_sticker_object(web_page->document_file_id)
|
? td_->stickers_manager_->get_sticker_object(web_page->document.file_id)
|
||||||
: nullptr,
|
: nullptr,
|
||||||
web_page->document_type == DocumentsManager::DocumentType::Video
|
web_page->document.type == Document::Type::Video
|
||||||
? td_->videos_manager_->get_video_object(web_page->document_file_id)
|
? td_->videos_manager_->get_video_object(web_page->document.file_id)
|
||||||
: nullptr,
|
: nullptr,
|
||||||
web_page->document_type == DocumentsManager::DocumentType::VideoNote
|
web_page->document.type == Document::Type::VideoNote
|
||||||
? td_->video_notes_manager_->get_video_note_object(web_page->document_file_id)
|
? td_->video_notes_manager_->get_video_note_object(web_page->document.file_id)
|
||||||
: nullptr,
|
: nullptr,
|
||||||
web_page->document_type == DocumentsManager::DocumentType::VoiceNote
|
web_page->document.type == Document::Type::VoiceNote
|
||||||
? td_->voice_notes_manager_->get_voice_note_object(web_page->document_file_id)
|
? td_->voice_notes_manager_->get_voice_note_object(web_page->document.file_id)
|
||||||
: nullptr,
|
: nullptr,
|
||||||
instant_view_version);
|
instant_view_version);
|
||||||
}
|
}
|
||||||
@ -3534,47 +3533,47 @@ void WebPagesManager::on_get_web_page_instant_view(WebPage *web_page, tl_object_
|
|||||||
auto document = move_tl_object_as<telegram_api::document>(document_ptr);
|
auto document = move_tl_object_as<telegram_api::document>(document_ptr);
|
||||||
auto document_id = document->id_;
|
auto document_id = document->id_;
|
||||||
auto parsed_document = td_->documents_manager_->on_get_document(std::move(document), owner_dialog_id);
|
auto parsed_document = td_->documents_manager_->on_get_document(std::move(document), owner_dialog_id);
|
||||||
if (parsed_document.first == DocumentsManager::DocumentType::Animation) {
|
if (parsed_document.type == Document::Type::Animation) {
|
||||||
animations.emplace(document_id, parsed_document.second);
|
animations.emplace(document_id, parsed_document.file_id);
|
||||||
} else if (parsed_document.first == DocumentsManager::DocumentType::Audio) {
|
} else if (parsed_document.type == Document::Type::Audio) {
|
||||||
audios.emplace(document_id, parsed_document.second);
|
audios.emplace(document_id, parsed_document.file_id);
|
||||||
} else if (parsed_document.first == DocumentsManager::DocumentType::General) {
|
} else if (parsed_document.type == Document::Type::General) {
|
||||||
documents.emplace(document_id, parsed_document.second);
|
documents.emplace(document_id, parsed_document.file_id);
|
||||||
} else if (parsed_document.first == DocumentsManager::DocumentType::Video) {
|
} else if (parsed_document.type == Document::Type::Video) {
|
||||||
videos.emplace(document_id, parsed_document.second);
|
videos.emplace(document_id, parsed_document.file_id);
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << "Receive document of the wrong type " << static_cast<int32>(parsed_document.first);
|
LOG(ERROR) << "Receive document of the wrong type: " << parsed_document;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (web_page->document_type == DocumentsManager::DocumentType::Animation) {
|
if (web_page->document.type == Document::Type::Animation) {
|
||||||
auto file_view = td_->file_manager_->get_file_view(web_page->document_file_id);
|
auto file_view = td_->file_manager_->get_file_view(web_page->document.file_id);
|
||||||
if (file_view.has_remote_location()) {
|
if (file_view.has_remote_location()) {
|
||||||
animations.emplace(file_view.remote_location().get_id(), web_page->document_file_id);
|
animations.emplace(file_view.remote_location().get_id(), web_page->document.file_id);
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << "Animation has no remote location";
|
LOG(ERROR) << "Animation has no remote location";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (web_page->document_type == DocumentsManager::DocumentType::Audio) {
|
if (web_page->document.type == Document::Type::Audio) {
|
||||||
auto file_view = td_->file_manager_->get_file_view(web_page->document_file_id);
|
auto file_view = td_->file_manager_->get_file_view(web_page->document.file_id);
|
||||||
if (file_view.has_remote_location()) {
|
if (file_view.has_remote_location()) {
|
||||||
audios.emplace(file_view.remote_location().get_id(), web_page->document_file_id);
|
audios.emplace(file_view.remote_location().get_id(), web_page->document.file_id);
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << "Audio has no remote location";
|
LOG(ERROR) << "Audio has no remote location";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (web_page->document_type == DocumentsManager::DocumentType::General) {
|
if (web_page->document.type == Document::Type::General) {
|
||||||
auto file_view = td_->file_manager_->get_file_view(web_page->document_file_id);
|
auto file_view = td_->file_manager_->get_file_view(web_page->document.file_id);
|
||||||
if (file_view.has_remote_location()) {
|
if (file_view.has_remote_location()) {
|
||||||
documents.emplace(file_view.remote_location().get_id(), web_page->document_file_id);
|
documents.emplace(file_view.remote_location().get_id(), web_page->document.file_id);
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << "Document has no remote location";
|
LOG(ERROR) << "Document has no remote location";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (web_page->document_type == DocumentsManager::DocumentType::Video) {
|
if (web_page->document.type == Document::Type::Video) {
|
||||||
auto file_view = td_->file_manager_->get_file_view(web_page->document_file_id);
|
auto file_view = td_->file_manager_->get_file_view(web_page->document.file_id);
|
||||||
if (file_view.has_remote_location()) {
|
if (file_view.has_remote_location()) {
|
||||||
videos.emplace(file_view.remote_location().get_id(), web_page->document_file_id);
|
videos.emplace(file_view.remote_location().get_id(), web_page->document.file_id);
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << "Video has no remote location";
|
LOG(ERROR) << "Video has no remote location";
|
||||||
}
|
}
|
||||||
@ -3827,27 +3826,27 @@ vector<FileId> WebPagesManager::get_web_page_file_ids(const WebPage *web_page) c
|
|||||||
}
|
}
|
||||||
|
|
||||||
vector<FileId> result = photo_get_file_ids(web_page->photo);
|
vector<FileId> result = photo_get_file_ids(web_page->photo);
|
||||||
if (web_page->document_file_id.is_valid()) {
|
if (web_page->document.file_id.is_valid()) {
|
||||||
result.push_back(web_page->document_file_id);
|
result.push_back(web_page->document.file_id);
|
||||||
FileId thumbnail_file_id;
|
FileId thumbnail_file_id;
|
||||||
switch (web_page->document_type) {
|
switch (web_page->document.type) {
|
||||||
case DocumentsManager::DocumentType::Animation:
|
case Document::Type::Animation:
|
||||||
thumbnail_file_id = td_->animations_manager_->get_animation_thumbnail_file_id(web_page->document_file_id);
|
thumbnail_file_id = td_->animations_manager_->get_animation_thumbnail_file_id(web_page->document.file_id);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::Audio:
|
case Document::Type::Audio:
|
||||||
thumbnail_file_id = td_->audios_manager_->get_audio_thumbnail_file_id(web_page->document_file_id);
|
thumbnail_file_id = td_->audios_manager_->get_audio_thumbnail_file_id(web_page->document.file_id);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::General:
|
case Document::Type::General:
|
||||||
thumbnail_file_id = td_->documents_manager_->get_document_thumbnail_file_id(web_page->document_file_id);
|
thumbnail_file_id = td_->documents_manager_->get_document_thumbnail_file_id(web_page->document.file_id);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::Sticker:
|
case Document::Type::Sticker:
|
||||||
thumbnail_file_id = td_->stickers_manager_->get_sticker_thumbnail_file_id(web_page->document_file_id);
|
thumbnail_file_id = td_->stickers_manager_->get_sticker_thumbnail_file_id(web_page->document.file_id);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::Video:
|
case Document::Type::Video:
|
||||||
thumbnail_file_id = td_->videos_manager_->get_video_thumbnail_file_id(web_page->document_file_id);
|
thumbnail_file_id = td_->videos_manager_->get_video_thumbnail_file_id(web_page->document.file_id);
|
||||||
break;
|
break;
|
||||||
case DocumentsManager::DocumentType::VideoNote:
|
case Document::Type::VideoNote:
|
||||||
thumbnail_file_id = td_->video_notes_manager_->get_video_note_thumbnail_file_id(web_page->document_file_id);
|
thumbnail_file_id = td_->video_notes_manager_->get_video_note_thumbnail_file_id(web_page->document.file_id);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user