2019-06-19 02:18:44 +02:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
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"
|
2021-11-14 08:47:02 +01:00
|
|
|
#include "td/utils/logging.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 {
|
2021-04-16 16:43:51 +02:00
|
|
|
enum class Type : int32 {
|
|
|
|
Legacy,
|
|
|
|
Thumbnail,
|
|
|
|
DialogPhotoSmall,
|
|
|
|
DialogPhotoBig,
|
|
|
|
StickerSetThumbnail,
|
|
|
|
FullLegacy,
|
|
|
|
DialogPhotoSmallLegacy,
|
|
|
|
DialogPhotoBigLegacy,
|
|
|
|
StickerSetThumbnailLegacy,
|
|
|
|
StickerSetThumbnailVersion
|
|
|
|
};
|
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) {
|
|
|
|
}
|
|
|
|
|
2021-11-11 15:39:09 +01:00
|
|
|
FileType file_type = FileType::None;
|
2019-06-19 02:18:44 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
struct DialogPhotoSmall final : public DialogPhoto {
|
2019-06-20 03:35:08 +02:00
|
|
|
using DialogPhoto::DialogPhoto;
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
struct DialogPhotoBig final : public DialogPhoto {
|
2019-06-20 03:35:08 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-04-16 16:43:51 +02:00
|
|
|
// for legacy photos with volume_id, local_id, secret
|
|
|
|
struct FullLegacy {
|
|
|
|
FullLegacy() = default;
|
|
|
|
FullLegacy(int64 volume_id, int32 local_id, int64 secret)
|
|
|
|
: volume_id(volume_id), local_id(local_id), secret(secret) {
|
|
|
|
}
|
|
|
|
|
|
|
|
int64 volume_id = 0;
|
|
|
|
int32 local_id = 0;
|
|
|
|
int64 secret = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// for legacy dialog photos
|
|
|
|
struct DialogPhotoLegacy : public DialogPhoto {
|
|
|
|
DialogPhotoLegacy() = default;
|
|
|
|
DialogPhotoLegacy(DialogId dialog_id, int64 dialog_access_hash, int64 volume_id, int32 local_id)
|
|
|
|
: DialogPhoto(dialog_id, dialog_access_hash), volume_id(volume_id), local_id(local_id) {
|
|
|
|
}
|
|
|
|
|
|
|
|
int64 volume_id = 0;
|
|
|
|
int32 local_id = 0;
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
struct DialogPhotoSmallLegacy final : public DialogPhotoLegacy {
|
2021-04-16 16:43:51 +02:00
|
|
|
using DialogPhotoLegacy::DialogPhotoLegacy;
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
struct DialogPhotoBigLegacy final : public DialogPhotoLegacy {
|
2021-04-16 16:43:51 +02:00
|
|
|
using DialogPhotoLegacy::DialogPhotoLegacy;
|
|
|
|
};
|
|
|
|
|
|
|
|
// for legacy sticker set thumbnails
|
2021-07-04 04:58:54 +02:00
|
|
|
struct StickerSetThumbnailLegacy final : public StickerSetThumbnail {
|
2021-04-16 16:43:51 +02:00
|
|
|
StickerSetThumbnailLegacy() = default;
|
|
|
|
StickerSetThumbnailLegacy(int64 sticker_set_id, int64 sticker_set_access_hash, int64 volume_id, int32 local_id)
|
|
|
|
: StickerSetThumbnail(sticker_set_id, sticker_set_access_hash), volume_id(volume_id), local_id(local_id) {
|
|
|
|
}
|
|
|
|
|
|
|
|
int64 volume_id = 0;
|
|
|
|
int32 local_id = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// for sticker set thumbnails identified by version
|
2021-07-04 04:58:54 +02:00
|
|
|
struct StickerSetThumbnailVersion final : public StickerSetThumbnail {
|
2021-04-16 16:43:51 +02:00
|
|
|
StickerSetThumbnailVersion() = default;
|
|
|
|
StickerSetThumbnailVersion(int64 sticker_set_id, int64 sticker_set_access_hash, int32 version)
|
|
|
|
: StickerSetThumbnail(sticker_set_id, sticker_set_access_hash), version(version) {
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 version = 0;
|
|
|
|
};
|
|
|
|
|
2019-06-19 02:18:44 +02:00
|
|
|
PhotoSizeSource() = default;
|
2021-10-27 15:52:22 +02:00
|
|
|
|
|
|
|
static PhotoSizeSource thumbnail(FileType file_type, int32 thumbnail_type) {
|
|
|
|
return PhotoSizeSource(Thumbnail(file_type, thumbnail_type));
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
2021-10-27 15:52:22 +02:00
|
|
|
|
|
|
|
static PhotoSizeSource dialog_photo(DialogId dialog_id, int64 dialog_access_hash, bool is_big) {
|
2019-06-20 03:35:08 +02:00
|
|
|
if (is_big) {
|
2021-10-27 15:52:22 +02:00
|
|
|
return PhotoSizeSource(DialogPhotoBig(dialog_id, dialog_access_hash));
|
2019-06-20 03:35:08 +02:00
|
|
|
} else {
|
2021-10-27 15:52:22 +02:00
|
|
|
return PhotoSizeSource(DialogPhotoSmall(dialog_id, dialog_access_hash));
|
2019-06-20 03:35:08 +02:00
|
|
|
}
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
2021-10-27 15:52:22 +02:00
|
|
|
|
|
|
|
static PhotoSizeSource full_legacy(int64 volume_id, int32 local_id, int64 secret) {
|
|
|
|
return PhotoSizeSource(FullLegacy(volume_id, local_id, secret));
|
2021-04-16 16:43:51 +02:00
|
|
|
}
|
2021-10-27 15:52:22 +02:00
|
|
|
|
|
|
|
static PhotoSizeSource dialog_photo_legacy(DialogId dialog_id, int64 dialog_access_hash, bool is_big, int64 volume_id,
|
|
|
|
int32 local_id) {
|
2021-04-16 16:43:51 +02:00
|
|
|
if (is_big) {
|
2021-10-27 15:52:22 +02:00
|
|
|
return PhotoSizeSource(DialogPhotoBigLegacy(dialog_id, dialog_access_hash, volume_id, local_id));
|
2021-04-16 16:43:51 +02:00
|
|
|
} else {
|
2021-10-27 15:52:22 +02:00
|
|
|
return PhotoSizeSource(DialogPhotoSmallLegacy(dialog_id, dialog_access_hash, volume_id, local_id));
|
2021-04-16 16:43:51 +02:00
|
|
|
}
|
|
|
|
}
|
2021-10-27 15:52:22 +02:00
|
|
|
|
|
|
|
static PhotoSizeSource sticker_set_thumbnail_legacy(int64 sticker_set_id, int64 sticker_set_access_hash,
|
|
|
|
int64 volume_id, int32 local_id) {
|
|
|
|
return PhotoSizeSource(StickerSetThumbnailLegacy(sticker_set_id, sticker_set_access_hash, volume_id, local_id));
|
2021-04-16 16:43:51 +02:00
|
|
|
}
|
2021-10-27 15:52:22 +02:00
|
|
|
|
|
|
|
static PhotoSizeSource sticker_set_thumbnail(int64 sticker_set_id, int64 sticker_set_access_hash, int32 version) {
|
|
|
|
return PhotoSizeSource(StickerSetThumbnailVersion(sticker_set_id, sticker_set_access_hash, version));
|
2021-04-16 16:43:51 +02:00
|
|
|
}
|
2019-06-19 02:18:44 +02:00
|
|
|
|
2023-07-25 19:31:45 +02:00
|
|
|
static bool unique_less(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs);
|
|
|
|
|
|
|
|
static bool unique_equal(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs);
|
|
|
|
|
2021-11-14 08:47:02 +01:00
|
|
|
Type get_type(const char *source) const {
|
2021-10-27 15:52:22 +02:00
|
|
|
auto offset = variant_.get_offset();
|
2021-11-14 08:47:02 +01:00
|
|
|
LOG_CHECK(offset >= 0) << offset << ' ' << source;
|
2019-06-19 02:53:11 +02:00
|
|
|
return static_cast<Type>(offset);
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
|
|
|
|
2021-11-14 08:47:02 +01:00
|
|
|
FileType get_file_type(const char *source) const;
|
2019-06-19 02:18:44 +02:00
|
|
|
|
|
|
|
Thumbnail &thumbnail() {
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<Thumbnail>();
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
2019-06-19 02:53:11 +02:00
|
|
|
|
|
|
|
const Legacy &legacy() const {
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<Legacy>();
|
2019-06-19 02:53:11 +02:00
|
|
|
}
|
2019-06-19 02:18:44 +02:00
|
|
|
const Thumbnail &thumbnail() const {
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<Thumbnail>();
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
|
|
|
const DialogPhoto &dialog_photo() const {
|
2021-10-27 15:52:22 +02:00
|
|
|
switch (variant_.get_offset()) {
|
2021-04-16 16:43:51 +02:00
|
|
|
case 2:
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<DialogPhotoSmall>();
|
2021-04-16 16:43:51 +02:00
|
|
|
case 3:
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<DialogPhotoBig>();
|
2021-04-16 16:43:51 +02:00
|
|
|
case 6:
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<DialogPhotoSmallLegacy>();
|
2021-04-16 16:43:51 +02:00
|
|
|
case 7:
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<DialogPhotoBigLegacy>();
|
2021-04-16 16:43:51 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<DialogPhotoSmall>();
|
2019-06-20 03:35:08 +02:00
|
|
|
}
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
|
|
|
const StickerSetThumbnail &sticker_set_thumbnail() const {
|
2021-10-27 15:52:22 +02:00
|
|
|
switch (variant_.get_offset()) {
|
2021-04-16 16:43:51 +02:00
|
|
|
case 4:
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<StickerSetThumbnail>();
|
2021-04-16 16:43:51 +02:00
|
|
|
case 8:
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<StickerSetThumbnailLegacy>();
|
2021-04-16 16:43:51 +02:00
|
|
|
case 9:
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<StickerSetThumbnailVersion>();
|
2021-04-16 16:43:51 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<StickerSetThumbnail>();
|
2021-04-16 16:43:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const FullLegacy &full_legacy() const {
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<FullLegacy>();
|
2021-04-16 16:43:51 +02:00
|
|
|
}
|
|
|
|
const DialogPhotoLegacy &dialog_photo_legacy() const {
|
2021-10-27 15:52:22 +02:00
|
|
|
if (variant_.get_offset() == 6) {
|
|
|
|
return variant_.get<DialogPhotoSmallLegacy>();
|
2021-04-16 16:43:51 +02:00
|
|
|
} else {
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<DialogPhotoBigLegacy>();
|
2021-04-16 16:43:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const StickerSetThumbnailLegacy &sticker_set_thumbnail_legacy() const {
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<StickerSetThumbnailLegacy>();
|
2021-04-16 16:43:51 +02:00
|
|
|
}
|
|
|
|
const StickerSetThumbnailVersion &sticker_set_thumbnail_version() const {
|
2021-10-27 15:52:22 +02:00
|
|
|
return variant_.get<StickerSetThumbnailVersion>();
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
|
|
|
|
2021-04-16 16:43:51 +02:00
|
|
|
// returns unique representation of the source
|
2023-03-14 22:18:34 +01:00
|
|
|
string get_unique(const char *source) const;
|
2021-04-16 16:43:51 +02:00
|
|
|
|
|
|
|
// can't be called for Legacy sources
|
2023-03-14 22:18:34 +01:00
|
|
|
string get_unique_name(int64 photo_id, const char *source) const;
|
2021-04-16 16:43:51 +02:00
|
|
|
|
2019-06-19 02:18:44 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
|
|
|
|
2021-04-15 20:24:55 +02:00
|
|
|
friend bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs);
|
|
|
|
|
2019-06-19 02:18:44 +02:00
|
|
|
private:
|
2021-04-16 16:43:51 +02:00
|
|
|
Variant<Legacy, Thumbnail, DialogPhotoSmall, DialogPhotoBig, StickerSetThumbnail, FullLegacy, DialogPhotoSmallLegacy,
|
|
|
|
DialogPhotoBigLegacy, StickerSetThumbnailLegacy, StickerSetThumbnailVersion>
|
2021-10-27 15:52:22 +02:00
|
|
|
variant_;
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
explicit PhotoSizeSource(const T &variant) : variant_(variant) {
|
|
|
|
}
|
2023-07-25 19:31:45 +02:00
|
|
|
|
|
|
|
int32 get_compare_type(const char *source) const;
|
|
|
|
|
|
|
|
int64 get_compare_volume_id() const;
|
|
|
|
|
|
|
|
int32 get_compare_local_id() const;
|
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
|