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;
LOG(ERROR) << "Wrong photoSize \"" << type << "\" " << res;
} else {
res.type = static_cast<unsigned char>(type[0]);
res.type = static_cast<uint8>(type[0]);
}
if (source.type == PhotoSizeSource::Type::Thumbnail) {
source.thumbnail().thumbnail_type = res.type;

View File

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

View File

@ -6,6 +6,7 @@
//
#pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/Photo.h"
#include "td/telegram/files/FileId.hpp"
@ -13,13 +14,17 @@
#include "td/utils/logging.h"
#include "td/utils/tl_helpers.h"
#include <limits>
namespace td {
template <class StorerT>
void OfflineInputStickerSet::store(StorerT &storer) const {
using td::store;
store(sticker_set_id, storer);
store(sticker_set_access_hash, storer);
}
template <class ParserT>
void OfflineInputStickerSet::parse(ParserT &parser) {
using td::parse;
@ -39,11 +44,18 @@ void OfflineInputPeer::store(StorerT &storer) const {
store(dialog_id, storer);
store(dialog_access_hash, storer);
}
template <class ParserT>
void OfflineInputPeer::parse(ParserT &parser) {
using td::parse;
parse(dialog_id, 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>
@ -78,6 +90,7 @@ void PhotoSizeSource::store(StorerT &storer) const {
break;
}
}
template <class ParserT>
void PhotoSizeSource::parse(ParserT &parser) {
using td::parse;
@ -100,6 +113,9 @@ void PhotoSizeSource::parse(ParserT &parser) {
case Type::Thumbnail: {
Thumbnail thumbnail;
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;
break;
}

View File

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

View File

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

View File

@ -487,25 +487,22 @@ class FullRemoteFileLocation {
case FileType::Photo:
return make_tl_object<telegram_api::inputPhotoFileLocation>(
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:
return make_tl_object<telegram_api::inputDocumentFileLocation>(
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:
case FileType::EncryptedThumbnail:
UNREACHABLE();
}
}
case PhotoSizeSource::Type::DialogPhoto: {
LOG(ERROR) << "DIALOG PHOTO";
auto &dialog_photo = photo().source_.dialog_photo();
return make_tl_object<telegram_api::inputPeerPhotoFileLocation>(
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_);
}
case PhotoSizeSource::Type::StickerSetThumbnail: {
LOG(ERROR) << "StickerSetThumbnail";
auto &sticker_set_thumbnail = photo().source_.sticker_set_thumbnail();
return make_tl_object<telegram_api::inputStickerSetThumb>(
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/FileType.h"
#include "td/telegram/net/DcId.h"
#include "td/telegram/Photo.hpp"
#include "td/telegram/Version.h"
#include "td/utils/common.h"
#include "td/utils/tl_helpers.h"
#include "td/utils/Variant.h"
#include "td/telegram/Photo.hpp"
namespace td {
template <class StorerT>
@ -58,7 +58,7 @@ void PhotoRemoteFileLocation::parse(ParserT &parser) {
parse(volume_id_, parser);
parse(secret_, parser);
parse(local_id_, parser);
if (parser.version() >= static_cast<int32>(Version::PhotoSizeSource)) {
if (parser.version() >= static_cast<int32>(Version::AddPhotoSizeSource)) {
parse(source_, parser);
}
}

View File

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

View File

@ -13,8 +13,8 @@
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/TdDb.h"
#include "td/telegram/logevent/LogEvent.h" // WithVersion
#include "td/db/SqliteKeyValue.h"
@ -47,7 +47,6 @@ struct DbFileInfo {
int64 size;
};
// long and blocking
template <class CallbackT>
void scan_db(CancellationToken &token, CallbackT &&callback) {
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;
};
// long and blocking
template <class CallbackT>
void scan_fs(CancellationToken &token, CallbackT &&callback) {
for (int32 i = 0; i < file_type_size; i++) {
@ -108,33 +106,35 @@ void scan_fs(CancellationToken &token, CallbackT &&callback) {
continue;
}
auto files_dir = get_files_dir(file_type);
td::walk_path(files_dir, [&](CSlice path, WalkPath::Type type) {
if (token) {
return WalkPath::Action::Abort;
}
if (type != WalkPath::Type::NotDir) {
return WalkPath::Action::Continue;
}
auto r_stat = stat(path);
if (r_stat.is_error()) {
LOG(WARNING) << "Stat in files gc failed: " << r_stat.error();
return WalkPath::Action::Continue;
}
auto stat = r_stat.move_as_ok();
if (ends_with(path, "/.nomedia") && stat.size_ == 0) {
// skip .nomedia file
return WalkPath::Action::Continue;
}
td::walk_path(files_dir,
[&](CSlice path, WalkPath::Type type) {
if (token) {
return WalkPath::Action::Abort;
}
if (type != WalkPath::Type::NotDir) {
return WalkPath::Action::Continue;
}
auto r_stat = stat(path);
if (r_stat.is_error()) {
LOG(WARNING) << "Stat in files gc failed: " << r_stat.error();
return WalkPath::Action::Continue;
}
auto stat = r_stat.move_as_ok();
if (ends_with(path, "/.nomedia") && stat.size_ == 0) {
// skip .nomedia file
return WalkPath::Action::Continue;
}
FsFileInfo info;
info.path = path.str();
info.size = stat.size_;
info.file_type = file_type;
info.atime_nsec = stat.atime_nsec_;
info.mtime_nsec = stat.mtime_nsec_;
callback(info);
return WalkPath::Action::Continue;
}).ignore();
FsFileInfo info;
info.path = path.str();
info.size = stat.size_;
info.file_type = file_type;
info.atime_nsec = stat.atime_nsec_;
info.mtime_nsec = stat.mtime_nsec_;
callback(info);
return WalkPath::Action::Continue;
})
.ignore();
}
}
} // namespace