2019-04-09 17:52:53 +02:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
2019-04-09 17:52:53 +02:00
|
|
|
//
|
|
|
|
// 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"
|
2019-04-09 23:55:54 +02:00
|
|
|
#include "td/telegram/AnimationsManager.hpp"
|
2019-04-09 17:52:53 +02:00
|
|
|
#include "td/telegram/AudiosManager.h"
|
2019-04-09 23:55:54 +02:00
|
|
|
#include "td/telegram/AudiosManager.hpp"
|
2019-04-09 17:52:53 +02:00
|
|
|
#include "td/telegram/DocumentsManager.h"
|
2019-04-09 23:55:54 +02:00
|
|
|
#include "td/telegram/DocumentsManager.hpp"
|
2019-04-09 17:52:53 +02:00
|
|
|
#include "td/telegram/files/FileId.hpp"
|
|
|
|
#include "td/telegram/StickersManager.h"
|
2019-04-09 23:55:54 +02:00
|
|
|
#include "td/telegram/StickersManager.hpp"
|
2019-04-09 17:52:53 +02:00
|
|
|
#include "td/telegram/Td.h"
|
|
|
|
#include "td/telegram/VideoNotesManager.h"
|
2019-04-09 23:55:54 +02:00
|
|
|
#include "td/telegram/VideoNotesManager.hpp"
|
2019-04-26 01:21:12 +02:00
|
|
|
#include "td/telegram/VideosManager.h"
|
|
|
|
#include "td/telegram/VideosManager.hpp"
|
2019-04-09 17:52:53 +02:00
|
|
|
#include "td/telegram/VoiceNotesManager.h"
|
2019-04-09 23:55:54 +02:00
|
|
|
#include "td/telegram/VoiceNotesManager.hpp"
|
2019-04-09 17:52:53 +02:00
|
|
|
|
|
|
|
#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();
|
2020-05-23 21:27:24 +02:00
|
|
|
if (td == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-09 17:52:53 +02:00
|
|
|
|
|
|
|
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();
|
2020-05-23 21:27:24 +02:00
|
|
|
if (td == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-09 17:52:53 +02:00
|
|
|
|
|
|
|
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
|