Add source to PhotoSizeSource::get_unique.

This commit is contained in:
levlam 2023-03-15 00:18:34 +03:00
parent a4c7d25c69
commit 0dc9aac724
5 changed files with 12 additions and 10 deletions

View File

@ -126,7 +126,7 @@ FileId register_photo_size(FileManager *file_manager, const PhotoSizeSource &sou
PhotoFormat format) { PhotoFormat format) {
LOG(DEBUG) << "Receive " << format << " photo " << id << " of type " << source.get_file_type("register_photo_size") LOG(DEBUG) << "Receive " << format << " photo " << id << " of type " << source.get_file_type("register_photo_size")
<< " from " << dc_id; << " from " << dc_id;
auto suggested_name = PSTRING() << source.get_unique_name(id) << '.' << format; auto suggested_name = PSTRING() << source.get_unique_name(id, "register_photo_size") << '.' << 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;
return file_manager->register_remote( return file_manager->register_remote(

View File

@ -64,11 +64,11 @@ FileType PhotoSizeSource::get_file_type(const char *source) const {
} }
} }
string PhotoSizeSource::get_unique() const { string PhotoSizeSource::get_unique(const char *source) 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("get_unique")) { switch (get_type(source)) {
case Type::Legacy: case Type::Legacy:
UNREACHABLE(); UNREACHABLE();
break; break;
@ -128,8 +128,8 @@ string PhotoSizeSource::get_unique() const {
return string(data.begin(), size); return string(data.begin(), size);
} }
string PhotoSizeSource::get_unique_name(int64 photo_id) const { string PhotoSizeSource::get_unique_name(int64 photo_id, const char *source) const {
switch (get_type("get_unique_name")) { switch (get_type(source)) {
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;

View File

@ -242,10 +242,10 @@ struct PhotoSizeSource {
} }
// returns unique representation of the source // returns unique representation of the source
string get_unique() const; string get_unique(const char *source) const;
// can't be called for Legacy sources // can't be called for Legacy sources
string get_unique_name(int64 photo_id) const; string get_unique_name(int64 photo_id, const char *source) const;
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const; void store(StorerT &storer) const;

View File

@ -102,10 +102,12 @@ struct PhotoRemoteFileLocation {
if (id_ != other.id_) { if (id_ != other.id_) {
return id_ < other.id_; return id_ < other.id_;
} }
return source_.get_unique() < other.source_.get_unique(); return source_.get_unique("PhotoRemoteFileLocation::operator<") <
other.source_.get_unique("PhotoRemoteFileLocation::operator<");
} }
bool operator==(const PhotoRemoteFileLocation &other) const { bool operator==(const PhotoRemoteFileLocation &other) const {
return id_ == other.id_ && source_.get_unique() == other.source_.get_unique(); return id_ == other.id_ && source_.get_unique("PhotoRemoteFileLocation::operator==") ==
other.source_.get_unique("PhotoRemoteFileLocation::operator==");
} }
}; };

View File

@ -105,7 +105,7 @@ void PhotoRemoteFileLocation::parse(ParserT &parser) {
template <class StorerT> 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("PhotoRemoteFileLocation::AsKey::store");
switch (key.source_.get_type("PhotoRemoteFileLocation::AsKey::store")) { switch (key.source_.get_type("PhotoRemoteFileLocation::AsKey::store")) {
case PhotoSizeSource::Type::Legacy: case PhotoSizeSource::Type::Legacy:
case PhotoSizeSource::Type::StickerSetThumbnail: case PhotoSizeSource::Type::StickerSetThumbnail: