PhotoSizeSource fixes.

GitOrigin-RevId: 7e7aa8a0f4a5daf50548f1dc0c4cc8ff7358942d
This commit is contained in:
levlam 2019-06-12 14:42:06 +03:00
parent cd519a5863
commit 3a2bdc5031
9 changed files with 67 additions and 43 deletions

View File

@ -328,7 +328,7 @@ Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, PhotoSizeSo
res.type = 0; res.type = 0;
LOG(ERROR) << "Wrong photoSize \"" << type << "\" " << res; LOG(ERROR) << "Wrong photoSize \"" << type << "\" " << res;
} else { } else {
res.type = static_cast<unsigned char>(type[0]); res.type = static_cast<uint8>(type[0]);
} }
if (source.type == PhotoSizeSource::Type::Thumbnail) { if (source.type == PhotoSizeSource::Type::Thumbnail) {
source.thumbnail().thumbnail_type = res.type; source.thumbnail().thumbnail_type = res.type;

View File

@ -50,22 +50,27 @@ struct PhotoSize {
struct OfflineInputStickerSet { struct OfflineInputStickerSet {
int64 sticker_set_id = 0; int64 sticker_set_id = 0;
int64 sticker_set_access_hash = 0; int64 sticker_set_access_hash = 0;
OfflineInputStickerSet() = default; OfflineInputStickerSet() = default;
OfflineInputStickerSet(int64 sticker_set_id, int64 sticker_set_access_hash) OfflineInputStickerSet(int64 sticker_set_id, int64 sticker_set_access_hash)
: sticker_set_id(sticker_set_id), sticker_set_access_hash(sticker_set_access_hash) { : sticker_set_id(sticker_set_id), sticker_set_access_hash(sticker_set_access_hash) {
} }
tl_object_ptr<telegram_api::InputStickerSet> as_telegram_api() const { tl_object_ptr<telegram_api::InputStickerSet> as_telegram_api() const {
return make_tl_object<telegram_api::inputStickerSetID>(sticker_set_id, sticker_set_access_hash); return make_tl_object<telegram_api::inputStickerSetID>(sticker_set_id, sticker_set_access_hash);
} }
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const; void store(StorerT &storer) const;
template <class ParserT> template <class ParserT>
void parse(ParserT &parser); void parse(ParserT &parser);
struct AsKey { struct AsKey {
const OfflineInputStickerSet &key; const OfflineInputStickerSet &key;
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const; void store(StorerT &storer) const;
}; };
AsKey as_key() const { AsKey as_key() const {
return AsKey{*this}; return AsKey{*this};
} }
@ -74,10 +79,12 @@ struct OfflineInputStickerSet {
struct OfflineInputPeer { struct OfflineInputPeer {
DialogId dialog_id; DialogId dialog_id;
int64 dialog_access_hash = 0; int64 dialog_access_hash = 0;
OfflineInputPeer() = default; OfflineInputPeer() = default;
OfflineInputPeer(DialogId dialog_id, int64 dialog_access_hash) OfflineInputPeer(DialogId dialog_id, int64 dialog_access_hash)
: dialog_id(dialog_id), dialog_access_hash(dialog_access_hash) { : dialog_id(dialog_id), dialog_access_hash(dialog_access_hash) {
} }
tl_object_ptr<telegram_api::InputPeer> as_telegram_api() const { tl_object_ptr<telegram_api::InputPeer> as_telegram_api() const {
switch (dialog_id.get_type()) { switch (dialog_id.get_type()) {
case DialogType::User: { case DialogType::User: {
@ -99,18 +106,20 @@ struct OfflineInputPeer {
default: default:
UNREACHABLE(); UNREACHABLE();
return nullptr; return nullptr;
} // namespace td }
} }
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const; void store(StorerT &storer) const;
template <class ParserT> template <class ParserT>
void parse(ParserT &parser); void parse(ParserT &parser);
struct AsKey { struct AsKey {
const OfflineInputPeer &key; const OfflineInputPeer &key;
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const; void store(StorerT &storer) const;
}; };
AsKey as_key() const { AsKey as_key() const {
return AsKey{*this}; return AsKey{*this};
} }
@ -124,7 +133,7 @@ struct PhotoSizeSource {
// for photos, document thumbnails, encrypted thumbnails // for photos, document thumbnails, encrypted thumbnails
struct Thumbnail { struct Thumbnail {
Thumbnail() = default; Thumbnail() = default;
Thumbnail(int32 thumbnail_type) : thumbnail_type(thumbnail_type) { explicit Thumbnail(int32 thumbnail_type) : thumbnail_type(thumbnail_type) {
} }
int32 thumbnail_type = 0; int32 thumbnail_type = 0;
}; };
@ -180,11 +189,13 @@ struct PhotoSizeSource {
void store(StorerT &storer) const; void store(StorerT &storer) const;
template <class ParserT> template <class ParserT>
void parse(ParserT &parser); void parse(ParserT &parser);
struct AsKey { struct AsKey {
const PhotoSizeSource &key; const PhotoSizeSource &key;
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const; void store(StorerT &storer) const;
}; };
AsKey as_key() const { AsKey as_key() const {
return AsKey{*this}; return AsKey{*this};
} }

View File

@ -6,6 +6,7 @@
// //
#pragma once #pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/Photo.h" #include "td/telegram/Photo.h"
#include "td/telegram/files/FileId.hpp" #include "td/telegram/files/FileId.hpp"
@ -13,13 +14,17 @@
#include "td/utils/logging.h" #include "td/utils/logging.h"
#include "td/utils/tl_helpers.h" #include "td/utils/tl_helpers.h"
#include <limits>
namespace td { namespace td {
template <class StorerT> template <class StorerT>
void OfflineInputStickerSet::store(StorerT &storer) const { void OfflineInputStickerSet::store(StorerT &storer) const {
using td::store; using td::store;
store(sticker_set_id, storer); store(sticker_set_id, storer);
store(sticker_set_access_hash, storer); store(sticker_set_access_hash, storer);
} }
template <class ParserT> template <class ParserT>
void OfflineInputStickerSet::parse(ParserT &parser) { void OfflineInputStickerSet::parse(ParserT &parser) {
using td::parse; using td::parse;
@ -39,11 +44,18 @@ void OfflineInputPeer::store(StorerT &storer) const {
store(dialog_id, storer); store(dialog_id, storer);
store(dialog_access_hash, storer); store(dialog_access_hash, storer);
} }
template <class ParserT> template <class ParserT>
void OfflineInputPeer::parse(ParserT &parser) { void OfflineInputPeer::parse(ParserT &parser) {
using td::parse; using td::parse;
parse(dialog_id, parser); parse(dialog_id, parser);
parse(dialog_access_hash, parser); parse(dialog_access_hash, parser);
switch (dialog_id.get_type()) {
case DialogType::SecretChat:
case DialogType::None:
parser.set_error("Invalid chat id");
break;
}
} }
template <class StorerT> template <class StorerT>
@ -78,6 +90,7 @@ void PhotoSizeSource::store(StorerT &storer) const {
break; break;
} }
} }
template <class ParserT> template <class ParserT>
void PhotoSizeSource::parse(ParserT &parser) { void PhotoSizeSource::parse(ParserT &parser) {
using td::parse; using td::parse;
@ -100,6 +113,9 @@ void PhotoSizeSource::parse(ParserT &parser) {
case Type::Thumbnail: { case Type::Thumbnail: {
Thumbnail thumbnail; Thumbnail thumbnail;
parse(thumbnail.thumbnail_type, parser); parse(thumbnail.thumbnail_type, parser);
if (thumbnail.thumbnail_type < 0 || thumbnail.thumbnail_type > std::numeric_limits<uint8>::max()) {
parser.set_error("Wrong thumbnail type");
}
variant = thumbnail; variant = thumbnail;
break; break;
} }

View File

@ -31,7 +31,7 @@ enum class Version : int32 {
AddNotificationGroupInfoMaxRemovedMessageId, AddNotificationGroupInfoMaxRemovedMessageId,
SupportMinithumbnails, SupportMinithumbnails,
AddVideoCallsSupport, AddVideoCallsSupport,
PhotoSizeSource, AddPhotoSizeSource,
Next Next
}; };

View File

@ -10,8 +10,8 @@
#include "td/telegram/files/FileData.hpp" #include "td/telegram/files/FileData.hpp"
#include "td/telegram/files/FileLocation.h" #include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileLocation.hpp" #include "td/telegram/files/FileLocation.hpp"
#include "td/telegram/Version.h"
#include "td/telegram/logevent/LogEvent.h" // WithVersion #include "td/telegram/logevent/LogEvent.h" // WithVersion
#include "td/telegram/Version.h"
#include "td/actor/actor.h" #include "td/actor/actor.h"

View File

@ -487,25 +487,22 @@ class FullRemoteFileLocation {
case FileType::Photo: case FileType::Photo:
return make_tl_object<telegram_api::inputPhotoFileLocation>( return make_tl_object<telegram_api::inputPhotoFileLocation>(
photo().id_, photo().access_hash_, BufferSlice(FileReferenceView(file_reference_).download()), photo().id_, photo().access_hash_, BufferSlice(FileReferenceView(file_reference_).download()),
std::string(1, thumbnail.thumbnail_type)); std::string(1, static_cast<char>(narrow_cast<uint8>(thumbnail.thumbnail_type))));
case FileType::Thumbnail: case FileType::Thumbnail:
return make_tl_object<telegram_api::inputDocumentFileLocation>( return make_tl_object<telegram_api::inputDocumentFileLocation>(
photo().id_, photo().access_hash_, BufferSlice(FileReferenceView(file_reference_).download()), photo().id_, photo().access_hash_, BufferSlice(FileReferenceView(file_reference_).download()),
std::string(1, thumbnail.thumbnail_type)); std::string(1, static_cast<char>(narrow_cast<uint8>(thumbnail.thumbnail_type))));
default: default:
case FileType::EncryptedThumbnail:
UNREACHABLE(); UNREACHABLE();
} }
} }
case PhotoSizeSource::Type::DialogPhoto: { case PhotoSizeSource::Type::DialogPhoto: {
LOG(ERROR) << "DIALOG PHOTO";
auto &dialog_photo = photo().source_.dialog_photo(); auto &dialog_photo = photo().source_.dialog_photo();
return make_tl_object<telegram_api::inputPeerPhotoFileLocation>( return make_tl_object<telegram_api::inputPeerPhotoFileLocation>(
dialog_photo.is_big * telegram_api::inputPeerPhotoFileLocation::Flags::BIG_MASK, dialog_photo.is_big, dialog_photo.is_big * telegram_api::inputPeerPhotoFileLocation::Flags::BIG_MASK, dialog_photo.is_big,
dialog_photo.input_peer.as_telegram_api(), photo().volume_id_, photo().local_id_); dialog_photo.input_peer.as_telegram_api(), photo().volume_id_, photo().local_id_);
} }
case PhotoSizeSource::Type::StickerSetThumbnail: { case PhotoSizeSource::Type::StickerSetThumbnail: {
LOG(ERROR) << "StickerSetThumbnail";
auto &sticker_set_thumbnail = photo().source_.sticker_set_thumbnail(); auto &sticker_set_thumbnail = photo().source_.sticker_set_thumbnail();
return make_tl_object<telegram_api::inputStickerSetThumb>( return make_tl_object<telegram_api::inputStickerSetThumb>(
sticker_set_thumbnail.input_sticker_set.as_telegram_api(), photo().volume_id_, photo().local_id_); sticker_set_thumbnail.input_sticker_set.as_telegram_api(), photo().volume_id_, photo().local_id_);

View File

@ -9,14 +9,14 @@
#include "td/telegram/files/FileLocation.h" #include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileType.h" #include "td/telegram/files/FileType.h"
#include "td/telegram/net/DcId.h"
#include "td/telegram/Photo.hpp"
#include "td/telegram/Version.h" #include "td/telegram/Version.h"
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/tl_helpers.h" #include "td/utils/tl_helpers.h"
#include "td/utils/Variant.h" #include "td/utils/Variant.h"
#include "td/telegram/Photo.hpp"
namespace td { namespace td {
template <class StorerT> template <class StorerT>
@ -58,7 +58,7 @@ void PhotoRemoteFileLocation::parse(ParserT &parser) {
parse(volume_id_, parser); parse(volume_id_, parser);
parse(secret_, parser); parse(secret_, parser);
parse(local_id_, parser); parse(local_id_, parser);
if (parser.version() >= static_cast<int32>(Version::PhotoSizeSource)) { if (parser.version() >= static_cast<int32>(Version::AddPhotoSizeSource)) {
parse(source_, parser); parse(source_, parser);
} }
} }

View File

@ -16,10 +16,10 @@
#include "td/telegram/files/FileLocation.h" #include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileLocation.hpp" #include "td/telegram/files/FileLocation.hpp"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/misc.h" #include "td/telegram/misc.h"
#include "td/telegram/SecureStorage.h" #include "td/telegram/SecureStorage.h"
#include "td/telegram/TdDb.h" #include "td/telegram/TdDb.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/actor/SleepActor.h" #include "td/actor/SleepActor.h"

View File

@ -13,8 +13,8 @@
#include "td/telegram/files/FileLocation.h" #include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileType.h" #include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/TdDb.h" #include "td/telegram/TdDb.h"
#include "td/telegram/logevent/LogEvent.h" // WithVersion
#include "td/db/SqliteKeyValue.h" #include "td/db/SqliteKeyValue.h"
@ -47,7 +47,6 @@ struct DbFileInfo {
int64 size; int64 size;
}; };
// long and blocking
template <class CallbackT> template <class CallbackT>
void scan_db(CancellationToken &token, CallbackT &&callback) { void scan_db(CancellationToken &token, CallbackT &&callback) {
G()->td_db()->get_file_db_shared()->pmc().get_by_range("file0", "file:", [&](Slice key, Slice value) { G()->td_db()->get_file_db_shared()->pmc().get_by_range("file0", "file:", [&](Slice key, Slice value) {
@ -99,7 +98,6 @@ struct FsFileInfo {
uint64 mtime_nsec; uint64 mtime_nsec;
}; };
// long and blocking
template <class CallbackT> template <class CallbackT>
void scan_fs(CancellationToken &token, CallbackT &&callback) { void scan_fs(CancellationToken &token, CallbackT &&callback) {
for (int32 i = 0; i < file_type_size; i++) { for (int32 i = 0; i < file_type_size; i++) {
@ -108,7 +106,8 @@ void scan_fs(CancellationToken &token, CallbackT &&callback) {
continue; continue;
} }
auto files_dir = get_files_dir(file_type); auto files_dir = get_files_dir(file_type);
td::walk_path(files_dir, [&](CSlice path, WalkPath::Type type) { td::walk_path(files_dir,
[&](CSlice path, WalkPath::Type type) {
if (token) { if (token) {
return WalkPath::Action::Abort; return WalkPath::Action::Abort;
} }
@ -134,7 +133,8 @@ void scan_fs(CancellationToken &token, CallbackT &&callback) {
info.mtime_nsec = stat.mtime_nsec_; info.mtime_nsec = stat.mtime_nsec_;
callback(info); callback(info);
return WalkPath::Action::Continue; return WalkPath::Action::Continue;
}).ignore(); })
.ignore();
} }
} }
} // namespace } // namespace