Add source to PhotoSizeSource::get_type.
This commit is contained in:
parent
6dd7c73765
commit
e52508bdc1
@ -362,7 +362,7 @@ void FileReferenceManager::repair_file_reference(NodeId node_id, Promise<> promi
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileReferenceManager::reload_photo(PhotoSizeSource source, Promise<Unit> promise) {
|
void FileReferenceManager::reload_photo(PhotoSizeSource source, Promise<Unit> promise) {
|
||||||
switch (source.get_type()) {
|
switch (source.get_type("reload_photo")) {
|
||||||
case PhotoSizeSource::Type::DialogPhotoBig:
|
case PhotoSizeSource::Type::DialogPhotoBig:
|
||||||
case PhotoSizeSource::Type::DialogPhotoSmall:
|
case PhotoSizeSource::Type::DialogPhotoSmall:
|
||||||
case PhotoSizeSource::Type::DialogPhotoBigLegacy:
|
case PhotoSizeSource::Type::DialogPhotoBigLegacy:
|
||||||
|
@ -1727,7 +1727,7 @@ static Result<InputMessageContent> create_input_message_content(
|
|||||||
int32 type = 'i';
|
int32 type = 'i';
|
||||||
if (file_view.has_remote_location() && !file_view.remote_location().is_web()) {
|
if (file_view.has_remote_location() && !file_view.remote_location().is_web()) {
|
||||||
auto photo_size_source = file_view.remote_location().get_source();
|
auto photo_size_source = file_view.remote_location().get_source();
|
||||||
if (photo_size_source.get_type() == PhotoSizeSource::Type::Thumbnail) {
|
if (photo_size_source.get_type("create_input_message_content") == PhotoSizeSource::Type::Thumbnail) {
|
||||||
auto old_type = photo_size_source.thumbnail().thumbnail_type;
|
auto old_type = photo_size_source.thumbnail().thumbnail_type;
|
||||||
if (old_type != 't') {
|
if (old_type != 't') {
|
||||||
type = old_type;
|
type = old_type;
|
||||||
|
@ -138,7 +138,8 @@ static StringBuilder &operator<<(StringBuilder &string_builder, PhotoFormat form
|
|||||||
static FileId register_photo(FileManager *file_manager, const PhotoSizeSource &source, int64 id, int64 access_hash,
|
static FileId register_photo(FileManager *file_manager, const PhotoSizeSource &source, int64 id, int64 access_hash,
|
||||||
std::string file_reference, DialogId owner_dialog_id, int32 file_size, DcId dc_id,
|
std::string file_reference, DialogId owner_dialog_id, int32 file_size, DcId dc_id,
|
||||||
PhotoFormat format) {
|
PhotoFormat format) {
|
||||||
LOG(DEBUG) << "Receive " << format << " photo " << id << " of type " << source.get_file_type() << " from " << dc_id;
|
LOG(DEBUG) << "Receive " << format << " photo " << id << " of type " << source.get_file_type("register_photo")
|
||||||
|
<< " from " << dc_id;
|
||||||
auto suggested_name = PSTRING() << source.get_unique_name(id) << '.' << format;
|
auto suggested_name = PSTRING() << source.get_unique_name(id) << '.' << format;
|
||||||
auto file_location_source = owner_dialog_id.get_type() == DialogType::SecretChat ? FileLocationSource::FromUser
|
auto file_location_source = owner_dialog_id.get_type() == DialogType::SecretChat ? FileLocationSource::FromUser
|
||||||
: FileLocationSource::FromServer;
|
: FileLocationSource::FromServer;
|
||||||
@ -429,7 +430,7 @@ Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, PhotoSizeSo
|
|||||||
res.type = 0;
|
res.type = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (source.get_type() == PhotoSizeSource::Type::Thumbnail) {
|
if (source.get_type("get_photo_size") == PhotoSizeSource::Type::Thumbnail) {
|
||||||
source.thumbnail().thumbnail_type = res.type;
|
source.thumbnail().thumbnail_type = res.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,7 +463,7 @@ AnimationSize get_animation_size(FileManager *file_manager, PhotoSizeSource sour
|
|||||||
res.main_frame_timestamp = size->video_start_ts_;
|
res.main_frame_timestamp = size->video_start_ts_;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source.get_type() == PhotoSizeSource::Type::Thumbnail) {
|
if (source.get_type("get_animation_size") == PhotoSizeSource::Type::Thumbnail) {
|
||||||
source.thumbnail().thumbnail_type = res.type;
|
source.thumbnail().thumbnail_type = res.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ tl_object_ptr<telegram_api::InputPeer> PhotoSizeSource::DialogPhoto::get_input_p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileType PhotoSizeSource::get_file_type() const {
|
FileType PhotoSizeSource::get_file_type(const char *source) const {
|
||||||
switch (get_type()) {
|
switch (get_type(source)) {
|
||||||
case Type::Thumbnail:
|
case Type::Thumbnail:
|
||||||
return thumbnail().file_type;
|
return thumbnail().file_type;
|
||||||
case Type::DialogPhotoSmall:
|
case Type::DialogPhotoSmall:
|
||||||
@ -68,7 +68,7 @@ string PhotoSizeSource::get_unique() const {
|
|||||||
auto ptr = StackAllocator::alloc(16);
|
auto ptr = StackAllocator::alloc(16);
|
||||||
MutableSlice data = ptr.as_slice();
|
MutableSlice data = ptr.as_slice();
|
||||||
TlStorerUnsafe storer(data.ubegin());
|
TlStorerUnsafe storer(data.ubegin());
|
||||||
switch (get_type()) {
|
switch (get_type("get_unique")) {
|
||||||
case Type::Legacy:
|
case Type::Legacy:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
break;
|
break;
|
||||||
@ -129,7 +129,7 @@ string PhotoSizeSource::get_unique() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string PhotoSizeSource::get_unique_name(int64 photo_id) const {
|
string PhotoSizeSource::get_unique_name(int64 photo_id) const {
|
||||||
switch (get_type()) {
|
switch (get_type("get_unique_name")) {
|
||||||
case Type::Thumbnail:
|
case Type::Thumbnail:
|
||||||
CHECK(0 <= thumbnail().thumbnail_type && thumbnail().thumbnail_type <= 127);
|
CHECK(0 <= thumbnail().thumbnail_type && thumbnail().thumbnail_type <= 127);
|
||||||
return PSTRING() << photo_id << '_' << thumbnail().thumbnail_type;
|
return PSTRING() << photo_id << '_' << thumbnail().thumbnail_type;
|
||||||
@ -226,7 +226,7 @@ bool operator!=(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder &operator<<(StringBuilder &string_builder, const PhotoSizeSource &source) {
|
StringBuilder &operator<<(StringBuilder &string_builder, const PhotoSizeSource &source) {
|
||||||
switch (source.get_type()) {
|
switch (source.get_type("operator<<")) {
|
||||||
case PhotoSizeSource::Type::Legacy:
|
case PhotoSizeSource::Type::Legacy:
|
||||||
return string_builder << "PhotoSizeSourceLegacy[]";
|
return string_builder << "PhotoSizeSourceLegacy[]";
|
||||||
case PhotoSizeSource::Type::Thumbnail:
|
case PhotoSizeSource::Type::Thumbnail:
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/StringBuilder.h"
|
#include "td/utils/StringBuilder.h"
|
||||||
#include "td/utils/Variant.h"
|
#include "td/utils/Variant.h"
|
||||||
|
|
||||||
@ -177,13 +178,13 @@ struct PhotoSizeSource {
|
|||||||
return PhotoSizeSource(StickerSetThumbnailVersion(sticker_set_id, sticker_set_access_hash, version));
|
return PhotoSizeSource(StickerSetThumbnailVersion(sticker_set_id, sticker_set_access_hash, version));
|
||||||
}
|
}
|
||||||
|
|
||||||
Type get_type() const {
|
Type get_type(const char *source) const {
|
||||||
auto offset = variant_.get_offset();
|
auto offset = variant_.get_offset();
|
||||||
CHECK(offset >= 0);
|
LOG_CHECK(offset >= 0) << offset << ' ' << source;
|
||||||
return static_cast<Type>(offset);
|
return static_cast<Type>(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileType get_file_type() const;
|
FileType get_file_type(const char *source) const;
|
||||||
|
|
||||||
Thumbnail &thumbnail() {
|
Thumbnail &thumbnail() {
|
||||||
return variant_.get<Thumbnail>();
|
return variant_.get<Thumbnail>();
|
||||||
|
@ -334,7 +334,7 @@ class FullRemoteFileLocation {
|
|||||||
|
|
||||||
void set_source(PhotoSizeSource source) {
|
void set_source(PhotoSizeSource source) {
|
||||||
CHECK(is_photo());
|
CHECK(is_photo());
|
||||||
file_type_ = source.get_file_type();
|
file_type_ = source.get_file_type("set_source");
|
||||||
photo().source_ = std::move(source);
|
photo().source_ = std::move(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,7 +399,7 @@ class FullRemoteFileLocation {
|
|||||||
const auto &id = photo().id_;
|
const auto &id = photo().id_;
|
||||||
const auto &access_hash = photo().access_hash_;
|
const auto &access_hash = photo().access_hash_;
|
||||||
const auto &source = photo().source_;
|
const auto &source = photo().source_;
|
||||||
switch (source.get_type()) {
|
switch (source.get_type("as_input_file_location")) {
|
||||||
case PhotoSizeSource::Type::Legacy:
|
case PhotoSizeSource::Type::Legacy:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
break;
|
break;
|
||||||
@ -423,7 +423,7 @@ class FullRemoteFileLocation {
|
|||||||
case PhotoSizeSource::Type::DialogPhotoSmall:
|
case PhotoSizeSource::Type::DialogPhotoSmall:
|
||||||
case PhotoSizeSource::Type::DialogPhotoBig: {
|
case PhotoSizeSource::Type::DialogPhotoBig: {
|
||||||
auto &dialog_photo = source.dialog_photo();
|
auto &dialog_photo = source.dialog_photo();
|
||||||
bool is_big = source.get_type() == PhotoSizeSource::Type::DialogPhotoBig;
|
bool is_big = source.get_type("as_input_file_location 2") == PhotoSizeSource::Type::DialogPhotoBig;
|
||||||
return make_tl_object<telegram_api::inputPeerPhotoFileLocation>(
|
return make_tl_object<telegram_api::inputPeerPhotoFileLocation>(
|
||||||
is_big * telegram_api::inputPeerPhotoFileLocation::BIG_MASK, false /*ignored*/,
|
is_big * telegram_api::inputPeerPhotoFileLocation::BIG_MASK, false /*ignored*/,
|
||||||
dialog_photo.get_input_peer(), id);
|
dialog_photo.get_input_peer(), id);
|
||||||
@ -440,7 +440,7 @@ class FullRemoteFileLocation {
|
|||||||
case PhotoSizeSource::Type::DialogPhotoSmallLegacy:
|
case PhotoSizeSource::Type::DialogPhotoSmallLegacy:
|
||||||
case PhotoSizeSource::Type::DialogPhotoBigLegacy: {
|
case PhotoSizeSource::Type::DialogPhotoBigLegacy: {
|
||||||
auto &dialog_photo = source.dialog_photo_legacy();
|
auto &dialog_photo = source.dialog_photo_legacy();
|
||||||
bool is_big = source.get_type() == PhotoSizeSource::Type::DialogPhotoBigLegacy;
|
bool is_big = source.get_type("as_input_file_location 3") == PhotoSizeSource::Type::DialogPhotoBigLegacy;
|
||||||
return make_tl_object<telegram_api::inputPeerPhotoFileLocationLegacy>(
|
return make_tl_object<telegram_api::inputPeerPhotoFileLocationLegacy>(
|
||||||
is_big * telegram_api::inputPeerPhotoFileLocationLegacy::BIG_MASK, false /*ignored*/,
|
is_big * telegram_api::inputPeerPhotoFileLocationLegacy::BIG_MASK, false /*ignored*/,
|
||||||
dialog_photo.get_input_peer(), dialog_photo.volume_id, dialog_photo.local_id);
|
dialog_photo.get_input_peer(), dialog_photo.volume_id, dialog_photo.local_id);
|
||||||
@ -510,7 +510,7 @@ class FullRemoteFileLocation {
|
|||||||
// photo
|
// photo
|
||||||
FullRemoteFileLocation(const PhotoSizeSource &source, int64 id, int64 access_hash, DcId dc_id,
|
FullRemoteFileLocation(const PhotoSizeSource &source, int64 id, int64 access_hash, DcId dc_id,
|
||||||
std::string file_reference)
|
std::string file_reference)
|
||||||
: file_type_(source.get_file_type())
|
: file_type_(source.get_file_type("FullRemoteFileLocation"))
|
||||||
, dc_id_(dc_id)
|
, dc_id_(dc_id)
|
||||||
, file_reference_(std::move(file_reference))
|
, file_reference_(std::move(file_reference))
|
||||||
, variant_(PhotoRemoteFileLocation{id, access_hash, source}) {
|
, variant_(PhotoRemoteFileLocation{id, access_hash, source}) {
|
||||||
|
@ -73,7 +73,7 @@ void PhotoRemoteFileLocation::parse(ParserT &parser) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (source.get_type()) {
|
switch (source.get_type("PhotoRemoteFileLocation::parse")) {
|
||||||
case PhotoSizeSource::Type::Legacy:
|
case PhotoSizeSource::Type::Legacy:
|
||||||
source_ = PhotoSizeSource::full_legacy(volume_id, local_id, source.legacy().secret);
|
source_ = PhotoSizeSource::full_legacy(volume_id, local_id, source.legacy().secret);
|
||||||
break;
|
break;
|
||||||
@ -84,7 +84,7 @@ void PhotoRemoteFileLocation::parse(ParserT &parser) {
|
|||||||
case PhotoSizeSource::Type::DialogPhotoSmall:
|
case PhotoSizeSource::Type::DialogPhotoSmall:
|
||||||
case PhotoSizeSource::Type::DialogPhotoBig: {
|
case PhotoSizeSource::Type::DialogPhotoBig: {
|
||||||
auto &dialog_photo = source.dialog_photo();
|
auto &dialog_photo = source.dialog_photo();
|
||||||
bool is_big = source.get_type() == PhotoSizeSource::Type::DialogPhotoBig;
|
bool is_big = source.get_type("PhotoRemoteFileLocation::parse") == PhotoSizeSource::Type::DialogPhotoBig;
|
||||||
source_ = PhotoSizeSource::dialog_photo_legacy(dialog_photo.dialog_id, dialog_photo.dialog_access_hash, is_big,
|
source_ = PhotoSizeSource::dialog_photo_legacy(dialog_photo.dialog_id, dialog_photo.dialog_access_hash, is_big,
|
||||||
volume_id, local_id);
|
volume_id, local_id);
|
||||||
break;
|
break;
|
||||||
@ -106,7 +106,7 @@ template <class StorerT>
|
|||||||
void PhotoRemoteFileLocation::AsKey::store(StorerT &storer) const {
|
void PhotoRemoteFileLocation::AsKey::store(StorerT &storer) const {
|
||||||
using td::store;
|
using td::store;
|
||||||
auto unique = key.source_.get_unique();
|
auto unique = key.source_.get_unique();
|
||||||
switch (key.source_.get_type()) {
|
switch (key.source_.get_type("PhotoRemoteFileLocation::AsKey::store")) {
|
||||||
case PhotoSizeSource::Type::Legacy:
|
case PhotoSizeSource::Type::Legacy:
|
||||||
case PhotoSizeSource::Type::StickerSetThumbnail:
|
case PhotoSizeSource::Type::StickerSetThumbnail:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
@ -231,12 +231,12 @@ void FullRemoteFileLocation::parse(ParserT &parser) {
|
|||||||
if (parser.get_error() != nullptr) {
|
if (parser.get_error() != nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (photo().source_.get_type()) {
|
switch (photo().source_.get_type("FullRemoteFileLocation::parse")) {
|
||||||
case PhotoSizeSource::Type::Legacy:
|
case PhotoSizeSource::Type::Legacy:
|
||||||
case PhotoSizeSource::Type::FullLegacy:
|
case PhotoSizeSource::Type::FullLegacy:
|
||||||
break;
|
break;
|
||||||
case PhotoSizeSource::Type::Thumbnail:
|
case PhotoSizeSource::Type::Thumbnail:
|
||||||
if (photo().source_.get_file_type() != file_type_ ||
|
if (photo().source_.get_file_type("FullRemoteFileLocation::parse") != file_type_ ||
|
||||||
(file_type_ != FileType::Photo && file_type_ != FileType::Thumbnail &&
|
(file_type_ != FileType::Photo && file_type_ != FileType::Thumbnail &&
|
||||||
file_type_ != FileType::EncryptedThumbnail)) {
|
file_type_ != FileType::EncryptedThumbnail)) {
|
||||||
parser.set_error("Invalid FileType in PhotoRemoteFileLocation Thumbnail");
|
parser.set_error("Invalid FileType in PhotoRemoteFileLocation Thumbnail");
|
||||||
|
@ -321,7 +321,7 @@ class FileView {
|
|||||||
if (!remote_location().is_photo()) {
|
if (!remote_location().is_photo()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto type = remote_location().get_source().get_type();
|
auto type = remote_location().get_source().get_type("may_reload_photo");
|
||||||
return type != PhotoSizeSource::Type::Legacy && type != PhotoSizeSource::Type::FullLegacy &&
|
return type != PhotoSizeSource::Type::Legacy && type != PhotoSizeSource::Type::FullLegacy &&
|
||||||
type != PhotoSizeSource::Type::Thumbnail;
|
type != PhotoSizeSource::Type::Thumbnail;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user