2022-09-22 00:46:12 +02:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2022-09-22 00:46:12 +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/MessageExtendedMedia.h"
|
|
|
|
#include "td/telegram/Photo.hpp"
|
|
|
|
#include "td/telegram/Td.h"
|
|
|
|
#include "td/telegram/VideosManager.h"
|
|
|
|
|
2022-10-12 14:59:58 +02:00
|
|
|
#include "td/utils/logging.h"
|
2022-09-22 00:46:12 +02:00
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void MessageExtendedMedia::store(StorerT &storer) const {
|
2022-09-22 14:30:12 +02:00
|
|
|
bool has_unsupported_version = unsupported_version_ != 0;
|
2022-09-22 00:46:12 +02:00
|
|
|
bool has_duration = duration_ != 0;
|
|
|
|
bool has_dimensions = dimensions_.width != 0 || dimensions_.height != 0;
|
|
|
|
bool has_minithumbnail = !minithumbnail_.empty();
|
|
|
|
bool has_photo = !photo_.is_empty();
|
|
|
|
bool has_video = video_file_id_.is_valid();
|
|
|
|
BEGIN_STORE_FLAGS();
|
2024-06-24 15:31:07 +02:00
|
|
|
STORE_FLAG(false); // has_caption
|
2022-09-22 14:30:12 +02:00
|
|
|
STORE_FLAG(has_unsupported_version);
|
2022-09-22 00:46:12 +02:00
|
|
|
STORE_FLAG(has_duration);
|
|
|
|
STORE_FLAG(has_dimensions);
|
|
|
|
STORE_FLAG(has_minithumbnail);
|
|
|
|
STORE_FLAG(has_photo);
|
|
|
|
STORE_FLAG(has_video);
|
|
|
|
END_STORE_FLAGS();
|
|
|
|
td::store(type_, storer);
|
2022-09-22 14:30:12 +02:00
|
|
|
if (has_unsupported_version) {
|
|
|
|
td::store(unsupported_version_, storer);
|
|
|
|
}
|
2022-09-22 00:46:12 +02:00
|
|
|
if (has_duration) {
|
|
|
|
td::store(duration_, storer);
|
|
|
|
}
|
|
|
|
if (has_dimensions) {
|
|
|
|
td::store(dimensions_, storer);
|
|
|
|
}
|
|
|
|
if (has_minithumbnail) {
|
|
|
|
td::store(minithumbnail_, storer);
|
|
|
|
}
|
|
|
|
if (has_photo) {
|
|
|
|
td::store(photo_, storer);
|
|
|
|
}
|
|
|
|
if (has_video) {
|
|
|
|
Td *td = storer.context()->td().get_actor_unsafe();
|
|
|
|
td->videos_manager_->store_video(video_file_id_, storer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void MessageExtendedMedia::parse(ParserT &parser) {
|
|
|
|
bool has_caption;
|
2022-09-22 14:30:12 +02:00
|
|
|
bool has_unsupported_version;
|
2022-09-22 00:46:12 +02:00
|
|
|
bool has_duration;
|
|
|
|
bool has_dimensions;
|
|
|
|
bool has_minithumbnail;
|
|
|
|
bool has_photo;
|
|
|
|
bool has_video;
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_caption);
|
2022-09-22 14:30:12 +02:00
|
|
|
PARSE_FLAG(has_unsupported_version);
|
2022-09-22 00:46:12 +02:00
|
|
|
PARSE_FLAG(has_duration);
|
|
|
|
PARSE_FLAG(has_dimensions);
|
|
|
|
PARSE_FLAG(has_minithumbnail);
|
|
|
|
PARSE_FLAG(has_photo);
|
|
|
|
PARSE_FLAG(has_video);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
td::parse(type_, parser);
|
|
|
|
if (has_caption) {
|
2024-06-24 15:31:07 +02:00
|
|
|
FormattedText caption;
|
|
|
|
td::parse(caption, parser);
|
2022-09-22 00:46:12 +02:00
|
|
|
}
|
2022-09-22 14:30:12 +02:00
|
|
|
if (has_unsupported_version) {
|
|
|
|
td::parse(unsupported_version_, parser);
|
|
|
|
}
|
2022-09-22 00:46:12 +02:00
|
|
|
if (has_duration) {
|
|
|
|
td::parse(duration_, parser);
|
|
|
|
}
|
|
|
|
if (has_dimensions) {
|
|
|
|
td::parse(dimensions_, parser);
|
|
|
|
}
|
|
|
|
if (has_minithumbnail) {
|
|
|
|
td::parse(minithumbnail_, parser);
|
|
|
|
}
|
|
|
|
bool is_bad = false;
|
|
|
|
if (has_photo) {
|
|
|
|
td::parse(photo_, parser);
|
2022-09-22 17:25:20 +02:00
|
|
|
is_bad = photo_.is_bad();
|
2022-09-22 00:46:12 +02:00
|
|
|
}
|
|
|
|
if (has_video) {
|
|
|
|
Td *td = parser.context()->td().get_actor_unsafe();
|
|
|
|
video_file_id_ = td->videos_manager_->parse_video(parser);
|
|
|
|
is_bad = !video_file_id_.is_valid();
|
|
|
|
}
|
2024-06-24 15:31:07 +02:00
|
|
|
if (is_bad || has_caption) {
|
|
|
|
if (is_bad) {
|
|
|
|
LOG(ERROR) << "Failed to parse MessageExtendedMedia";
|
|
|
|
}
|
2022-09-22 00:46:12 +02:00
|
|
|
photo_ = Photo();
|
|
|
|
video_file_id_ = FileId();
|
|
|
|
type_ = Type::Unsupported;
|
2022-09-22 14:30:12 +02:00
|
|
|
unsupported_version_ = 0;
|
2022-09-22 00:46:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|