Add Document.hpp.

GitOrigin-RevId: e26a6aa44453c2a5e2216d91782e94f5bda9686d
This commit is contained in:
levlam 2019-04-09 18:52:53 +03:00
parent dc79cdc0b1
commit 46a0b0036d
5 changed files with 104 additions and 67 deletions

View File

@ -617,6 +617,7 @@ set(TDLIB_SOURCE
td/telegram/AnimationsManager.hpp td/telegram/AnimationsManager.hpp
td/telegram/AudiosManager.hpp td/telegram/AudiosManager.hpp
td/telegram/AuthManager.hpp td/telegram/AuthManager.hpp
td/telegram/Document.hpp
td/telegram/DocumentsManager.hpp td/telegram/DocumentsManager.hpp
td/telegram/DraftMessage.hpp td/telegram/DraftMessage.hpp
td/telegram/FileReferenceManager.hpp td/telegram/FileReferenceManager.hpp

View File

@ -31,9 +31,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, const Document &documen
return "Unreachable"; return "Unreachable";
} }
}(); }();
return string_builder << '[' << type << ' ' << document.file_id << ']'; return string_builder << '[' << type << ' ' << document.file_id << ']';
} }
} // namespace td } // namespace td

View File

@ -21,7 +21,7 @@ struct Document {
FileId file_id; FileId file_id;
Document() = default; Document() = default;
Document(Type type, FileId file_id): type(type), file_id(file_id) { Document(Type type, FileId file_id) : type(type), file_id(file_id) {
} }
}; };

98
td/telegram/Document.hpp Normal file
View File

@ -0,0 +1,98 @@
//
// 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/Document.h"
#include "td/telegram/AnimationsManager.h"
#include "td/telegram/AudiosManager.h"
#include "td/telegram/DocumentsManager.h"
#include "td/telegram/files/FileId.hpp"
#include "td/telegram/StickersManager.h"
#include "td/telegram/Td.h"
#include "td/telegram/VideosManager.h"
#include "td/telegram/VideoNotesManager.h"
#include "td/telegram/VoiceNotesManager.h"
#include "td/utils/logging.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void store(const Document &document, StorerT &storer) {
Td *td = storer.context()->td().get_actor_unsafe();
CHECK(td != nullptr);
store(document.type, storer);
switch (document.type) {
case Document::Type::Animation:
td->animations_manager_->store_animation(document.file_id, storer);
break;
case Document::Type::Audio:
td->audios_manager_->store_audio(document.file_id, storer);
break;
case Document::Type::General:
td->documents_manager_->store_document(document.file_id, storer);
break;
case Document::Type::Sticker:
td->stickers_manager_->store_sticker(document.file_id, false, storer);
break;
case Document::Type::Video:
td->videos_manager_->store_video(document.file_id, storer);
break;
case Document::Type::VideoNote:
td->video_notes_manager_->store_video_note(document.file_id, storer);
break;
case Document::Type::VoiceNote:
td->voice_notes_manager_->store_voice_note(document.file_id, storer);
break;
case Document::Type::Unknown:
default:
UNREACHABLE();
}
}
template <class ParserT>
void parse(Document &document, ParserT &parser) {
Td *td = parser.context()->td().get_actor_unsafe();
CHECK(td != nullptr);
parse(document.type, parser);
switch (document.type) {
case Document::Type::Animation:
document.file_id = td->animations_manager_->parse_animation(parser);
break;
case Document::Type::Audio:
document.file_id = td->audios_manager_->parse_audio(parser);
break;
case Document::Type::General:
document.file_id = td->documents_manager_->parse_document(parser);
break;
case Document::Type::Sticker:
document.file_id = td->stickers_manager_->parse_sticker(false, parser);
break;
case Document::Type::Video:
document.file_id = td->videos_manager_->parse_video(parser);
break;
case Document::Type::VideoNote:
document.file_id = td->video_notes_manager_->parse_video_note(parser);
break;
case Document::Type::VoiceNote:
document.file_id = td->voice_notes_manager_->parse_voice_note(parser);
break;
case Document::Type::Unknown:
default:
UNREACHABLE();
}
if (!document.file_id.is_valid()) {
LOG(ERROR) << "Parse invalid document.file_id";
document = Document();
}
}
} // namespace td

View File

@ -16,6 +16,7 @@
#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/Document.h"
#include "td/telegram/Document.hpp"
#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"
@ -280,36 +281,7 @@ class WebPagesManager::WebPage {
store(author, storer); store(author, storer);
} }
if (has_document) { if (has_document) {
Td *td = storer.context()->td().get_actor_unsafe(); store(document, storer);
CHECK(td != nullptr);
store(document.type, storer);
switch (document.type) {
case Document::Type::Animation:
td->animations_manager_->store_animation(document.file_id, storer);
break;
case Document::Type::Audio:
td->audios_manager_->store_audio(document.file_id, storer);
break;
case Document::Type::General:
td->documents_manager_->store_document(document.file_id, storer);
break;
case Document::Type::Sticker:
td->stickers_manager_->store_sticker(document.file_id, false, storer);
break;
case Document::Type::Video:
td->videos_manager_->store_video(document.file_id, storer);
break;
case Document::Type::VideoNote:
td->video_notes_manager_->store_video_note(document.file_id, storer);
break;
case Document::Type::VoiceNote:
td->voice_notes_manager_->store_voice_note(document.file_id, storer);
break;
case Document::Type::Unknown:
default:
UNREACHABLE();
}
} }
} }
@ -382,40 +354,7 @@ class WebPagesManager::WebPage {
parse(author, parser); parse(author, parser);
} }
if (has_document) { if (has_document) {
Td *td = parser.context()->td().get_actor_unsafe(); parse(document, parser);
CHECK(td != nullptr);
parse(document.type, parser);
switch (document.type) {
case Document::Type::Animation:
document.file_id = td->animations_manager_->parse_animation(parser);
break;
case Document::Type::Audio:
document.file_id = td->audios_manager_->parse_audio(parser);
break;
case Document::Type::General:
document.file_id = td->documents_manager_->parse_document(parser);
break;
case Document::Type::Sticker:
document.file_id = td->stickers_manager_->parse_sticker(false, parser);
break;
case Document::Type::Video:
document.file_id = td->videos_manager_->parse_video(parser);
break;
case Document::Type::VideoNote:
document.file_id = td->video_notes_manager_->parse_video_note(parser);
break;
case Document::Type::VoiceNote:
document.file_id = td->voice_notes_manager_->parse_voice_note(parser);
break;
case Document::Type::Unknown:
default:
UNREACHABLE();
}
if (!document.file_id.is_valid()) {
LOG(ERROR) << "Parse invalid document.file_id";
document = Document();
}
} }
if (has_instant_view) { if (has_instant_view) {