2018-12-31 20:04:05 +01:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
2018-12-31 20:04:05 +01: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/files/FileId.hpp"
|
2020-07-08 21:59:31 +02:00
|
|
|
#include "td/telegram/Photo.h"
|
|
|
|
#include "td/telegram/Version.h"
|
2021-08-03 19:55:27 +02:00
|
|
|
#include "td/telegram/ConfigShared.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/utils/logging.h"
|
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
namespace td {
|
2019-06-12 13:42:06 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(Dimensions dimensions, StorerT &storer) {
|
|
|
|
store(static_cast<uint32>((static_cast<uint32>(dimensions.width) << 16) | dimensions.height), storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(Dimensions &dimensions, ParserT &parser) {
|
|
|
|
uint32 width_height;
|
|
|
|
parse(width_height, parser);
|
|
|
|
dimensions.width = static_cast<uint16>(width_height >> 16);
|
|
|
|
dimensions.height = static_cast<uint16>(width_height & 0xFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(const DialogPhoto &dialog_photo, StorerT &storer) {
|
2020-07-08 21:59:31 +02:00
|
|
|
bool has_file_ids = dialog_photo.small_file_id.is_valid() || dialog_photo.big_file_id.is_valid();
|
2021-04-09 16:01:58 +02:00
|
|
|
bool has_minithumbnail = !dialog_photo.minithumbnail.empty();
|
2020-07-08 21:59:31 +02:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_file_ids);
|
|
|
|
STORE_FLAG(dialog_photo.has_animation);
|
2021-08-03 19:55:27 +02:00
|
|
|
STORE_FLAG(!G()->shared_config().get_option_boolean("disable_minithumbnails") && has_minithumbnail);
|
2020-07-08 21:59:31 +02:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
if (has_file_ids) {
|
|
|
|
store(dialog_photo.small_file_id, storer);
|
|
|
|
store(dialog_photo.big_file_id, storer);
|
|
|
|
}
|
2021-08-03 19:55:27 +02:00
|
|
|
if (!G()->shared_config().get_option_boolean("disable_minithumbnails") && has_minithumbnail) {
|
2021-04-09 16:01:58 +02:00
|
|
|
store(dialog_photo.minithumbnail, storer);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(DialogPhoto &dialog_photo, ParserT &parser) {
|
2020-07-08 21:59:31 +02:00
|
|
|
bool has_file_ids = true;
|
2021-04-09 16:01:58 +02:00
|
|
|
bool has_minithumbnail = false;
|
2020-07-08 21:59:31 +02:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddDialogPhotoHasAnimation)) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_file_ids);
|
|
|
|
PARSE_FLAG(dialog_photo.has_animation);
|
2021-04-09 16:01:58 +02:00
|
|
|
PARSE_FLAG(has_minithumbnail);
|
2020-07-08 21:59:31 +02:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
}
|
|
|
|
if (has_file_ids) {
|
|
|
|
parse(dialog_photo.small_file_id, parser);
|
|
|
|
parse(dialog_photo.big_file_id, parser);
|
|
|
|
}
|
2021-04-09 16:01:58 +02:00
|
|
|
if (has_minithumbnail) {
|
2021-08-03 19:55:27 +02:00
|
|
|
std::basic_string<char> minithumbnail;
|
|
|
|
parse(minithumbnail, parser);
|
|
|
|
if (!G()->shared_config().get_option_boolean("disable_minithumbnails")) {
|
|
|
|
dialog_photo.minithumbnail = minithumbnail;
|
|
|
|
}
|
2021-04-09 16:01:58 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(const ProfilePhoto &profile_photo, StorerT &storer) {
|
|
|
|
store(static_cast<const DialogPhoto &>(profile_photo), storer);
|
|
|
|
store(profile_photo.id, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ProfilePhoto &profile_photo, ParserT &parser) {
|
|
|
|
parse(static_cast<DialogPhoto &>(profile_photo), parser);
|
|
|
|
parse(profile_photo.id, parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(const PhotoSize &photo_size, StorerT &storer) {
|
|
|
|
LOG(DEBUG) << "Store photo size " << photo_size;
|
|
|
|
store(photo_size.type, storer);
|
|
|
|
store(photo_size.dimensions, storer);
|
|
|
|
store(photo_size.size, storer);
|
|
|
|
store(photo_size.file_id, storer);
|
2020-08-25 14:09:24 +02:00
|
|
|
store(photo_size.progressive_sizes, storer);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(PhotoSize &photo_size, ParserT &parser) {
|
|
|
|
parse(photo_size.type, parser);
|
|
|
|
parse(photo_size.dimensions, parser);
|
|
|
|
parse(photo_size.size, parser);
|
|
|
|
parse(photo_size.file_id, parser);
|
2020-08-25 14:09:24 +02:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddPhotoProgressiveSizes)) {
|
|
|
|
parse(photo_size.progressive_sizes, parser);
|
|
|
|
} else {
|
|
|
|
photo_size.progressive_sizes.clear();
|
|
|
|
}
|
2021-04-16 16:43:51 +02:00
|
|
|
if (photo_size.type < 0 || photo_size.type >= 128) {
|
|
|
|
parser.set_error("Wrong PhotoSize type");
|
|
|
|
return;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
LOG(DEBUG) << "Parsed photo size " << photo_size;
|
|
|
|
}
|
|
|
|
|
2020-07-07 10:41:01 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void store(const AnimationSize &animation_size, StorerT &storer) {
|
|
|
|
store(static_cast<const PhotoSize &>(animation_size), storer);
|
|
|
|
store(animation_size.main_frame_timestamp, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(AnimationSize &animation_size, ParserT &parser) {
|
|
|
|
parse(static_cast<PhotoSize &>(animation_size), parser);
|
2020-07-27 16:52:21 +02:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddDialogPhotoHasAnimation)) {
|
|
|
|
parse(animation_size.main_frame_timestamp, parser);
|
|
|
|
} else {
|
|
|
|
animation_size.main_frame_timestamp = 0;
|
|
|
|
}
|
2020-07-07 10:41:01 +02:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(const Photo &photo, StorerT &storer) {
|
2019-03-01 20:51:33 +01:00
|
|
|
bool has_minithumbnail = !photo.minithumbnail.empty();
|
2020-07-07 10:41:01 +02:00
|
|
|
bool has_animations = !photo.animations.empty();
|
2018-12-31 20:04:05 +01:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(photo.has_stickers);
|
2021-08-03 19:55:27 +02:00
|
|
|
STORE_FLAG(!G()->shared_config().get_option_boolean("disable_minithumbnails") && has_minithumbnail);
|
2020-07-07 10:41:01 +02:00
|
|
|
STORE_FLAG(has_animations);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_STORE_FLAGS();
|
2020-07-06 14:26:29 +02:00
|
|
|
store(photo.id.get(), storer);
|
2018-12-31 20:04:05 +01:00
|
|
|
store(photo.date, storer);
|
|
|
|
store(photo.photos, storer);
|
|
|
|
if (photo.has_stickers) {
|
|
|
|
store(photo.sticker_file_ids, storer);
|
|
|
|
}
|
2021-08-03 19:55:27 +02:00
|
|
|
if (!G()->shared_config().get_option_boolean("disable_minithumbnails") && has_minithumbnail) {
|
2019-03-01 20:51:33 +01:00
|
|
|
store(photo.minithumbnail, storer);
|
|
|
|
}
|
2020-07-07 10:41:01 +02:00
|
|
|
if (has_animations) {
|
|
|
|
store(photo.animations, storer);
|
2020-06-24 13:13:33 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(Photo &photo, ParserT &parser) {
|
2019-03-01 20:51:33 +01:00
|
|
|
bool has_minithumbnail;
|
2020-07-07 10:41:01 +02:00
|
|
|
bool has_animations;
|
2018-12-31 20:04:05 +01:00
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(photo.has_stickers);
|
2019-03-01 20:51:33 +01:00
|
|
|
PARSE_FLAG(has_minithumbnail);
|
2020-07-07 10:41:01 +02:00
|
|
|
PARSE_FLAG(has_animations);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_PARSE_FLAGS();
|
2020-07-06 14:26:29 +02:00
|
|
|
int64 id;
|
|
|
|
parse(id, parser);
|
|
|
|
photo.id = id;
|
2018-12-31 20:04:05 +01:00
|
|
|
parse(photo.date, parser);
|
|
|
|
parse(photo.photos, parser);
|
|
|
|
if (photo.has_stickers) {
|
|
|
|
parse(photo.sticker_file_ids, parser);
|
|
|
|
}
|
2019-03-01 20:51:33 +01:00
|
|
|
if (has_minithumbnail) {
|
2021-08-03 19:55:27 +02:00
|
|
|
std::basic_string<char> minithumbnail;
|
|
|
|
parse(minithumbnail, parser);
|
|
|
|
if (!G()->shared_config().get_option_boolean("disable_minithumbnails")) {
|
|
|
|
photo.minithumbnail = minithumbnail;
|
|
|
|
}
|
2019-03-01 20:51:33 +01:00
|
|
|
}
|
2020-07-07 10:41:01 +02:00
|
|
|
if (has_animations) {
|
|
|
|
parse(photo.animations, parser);
|
2020-06-24 13:13:33 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|