2019-06-19 02:18:44 +02:00
|
|
|
//
|
2020-01-01 02:23:48 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020
|
2019-06-19 02:18:44 +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/DialogId.h"
|
|
|
|
#include "td/telegram/files/FileType.h"
|
|
|
|
|
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2019-09-02 02:51:41 +02:00
|
|
|
#include "td/utils/StringBuilder.h"
|
2019-06-19 02:18:44 +02:00
|
|
|
#include "td/utils/Variant.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
struct PhotoSizeSource {
|
2019-06-20 03:35:08 +02:00
|
|
|
enum class Type : int32 { Legacy, Thumbnail, DialogPhotoSmall, DialogPhotoBig, StickerSetThumbnail };
|
2019-06-19 02:53:11 +02:00
|
|
|
|
|
|
|
// for legacy photos with secret
|
|
|
|
struct Legacy {
|
|
|
|
Legacy() = default;
|
|
|
|
explicit Legacy(int64 secret) : secret(secret) {
|
|
|
|
}
|
|
|
|
|
|
|
|
int64 secret = 0;
|
|
|
|
};
|
2019-06-19 02:18:44 +02:00
|
|
|
|
|
|
|
// for photos, document thumbnails, encrypted thumbnails
|
|
|
|
struct Thumbnail {
|
|
|
|
Thumbnail() = default;
|
|
|
|
Thumbnail(FileType file_type, int32 thumbnail_type) : file_type(file_type), thumbnail_type(thumbnail_type) {
|
|
|
|
}
|
|
|
|
|
|
|
|
FileType file_type;
|
|
|
|
int32 thumbnail_type = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// for dialog photos
|
|
|
|
struct DialogPhoto {
|
|
|
|
DialogPhoto() = default;
|
2019-06-20 03:35:08 +02:00
|
|
|
DialogPhoto(DialogId dialog_id, int64 dialog_access_hash)
|
|
|
|
: dialog_id(dialog_id), dialog_access_hash(dialog_access_hash) {
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::InputPeer> get_input_peer() const;
|
|
|
|
|
|
|
|
DialogId dialog_id;
|
|
|
|
int64 dialog_access_hash = 0;
|
2019-06-20 03:35:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DialogPhotoSmall : public DialogPhoto {
|
|
|
|
using DialogPhoto::DialogPhoto;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DialogPhotoBig : public DialogPhoto {
|
|
|
|
using DialogPhoto::DialogPhoto;
|
2019-06-19 02:18:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// for sticker set thumbnails
|
|
|
|
struct StickerSetThumbnail {
|
|
|
|
int64 sticker_set_id = 0;
|
|
|
|
int64 sticker_set_access_hash = 0;
|
|
|
|
|
|
|
|
StickerSetThumbnail() = default;
|
|
|
|
StickerSetThumbnail(int64 sticker_set_id, int64 sticker_set_access_hash)
|
|
|
|
: sticker_set_id(sticker_set_id), sticker_set_access_hash(sticker_set_access_hash) {
|
|
|
|
}
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::InputStickerSet> get_input_sticker_set() const {
|
|
|
|
return make_tl_object<telegram_api::inputStickerSetID>(sticker_set_id, sticker_set_access_hash);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
PhotoSizeSource() = default;
|
2019-06-19 02:53:11 +02:00
|
|
|
explicit PhotoSizeSource(int64 secret) : variant(Legacy(secret)) {
|
|
|
|
}
|
2019-06-19 02:18:44 +02:00
|
|
|
PhotoSizeSource(FileType file_type, int32 thumbnail_type) : variant(Thumbnail(file_type, thumbnail_type)) {
|
|
|
|
}
|
2019-06-20 03:35:08 +02:00
|
|
|
PhotoSizeSource(DialogId dialog_id, int64 dialog_access_hash, bool is_big) {
|
|
|
|
if (is_big) {
|
|
|
|
variant = DialogPhotoBig(dialog_id, dialog_access_hash);
|
|
|
|
} else {
|
|
|
|
variant = DialogPhotoSmall(dialog_id, dialog_access_hash);
|
|
|
|
}
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
|
|
|
PhotoSizeSource(int64 sticker_set_id, int64 sticker_set_access_hash)
|
|
|
|
: variant(StickerSetThumbnail(sticker_set_id, sticker_set_access_hash)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Type get_type() const {
|
2019-06-19 02:53:11 +02:00
|
|
|
auto offset = variant.get_offset();
|
|
|
|
CHECK(offset >= 0);
|
|
|
|
return static_cast<Type>(offset);
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FileType get_file_type() const;
|
|
|
|
|
|
|
|
Thumbnail &thumbnail() {
|
|
|
|
return variant.get<Thumbnail>();
|
|
|
|
}
|
2019-06-19 02:53:11 +02:00
|
|
|
|
|
|
|
const Legacy &legacy() const {
|
|
|
|
return variant.get<Legacy>();
|
|
|
|
}
|
2019-06-19 02:18:44 +02:00
|
|
|
const Thumbnail &thumbnail() const {
|
|
|
|
return variant.get<Thumbnail>();
|
|
|
|
}
|
|
|
|
const DialogPhoto &dialog_photo() const {
|
2019-06-20 03:35:08 +02:00
|
|
|
if (variant.get_offset() == 2) {
|
|
|
|
return variant.get<DialogPhotoSmall>();
|
|
|
|
} else {
|
|
|
|
return variant.get<DialogPhotoBig>();
|
|
|
|
}
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
|
|
|
const StickerSetThumbnail &sticker_set_thumbnail() const {
|
|
|
|
return variant.get<StickerSetThumbnail>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
|
|
|
|
|
|
|
private:
|
2019-06-20 03:35:08 +02:00
|
|
|
Variant<Legacy, Thumbnail, DialogPhotoSmall, DialogPhotoBig, StickerSetThumbnail> variant;
|
2019-06-19 02:18:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs);
|
|
|
|
bool operator!=(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs);
|
|
|
|
|
2019-09-02 02:51:41 +02:00
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const PhotoSizeSource &source);
|
|
|
|
|
2019-06-19 02:18:44 +02:00
|
|
|
} // namespace td
|