Add minithumbnails to userProfilePhoto and chatPhotoInfo.

This commit is contained in:
levlam 2021-04-09 17:01:58 +03:00
parent 969b52cc82
commit 3786033316
4 changed files with 22 additions and 5 deletions

View File

@ -318,14 +318,16 @@ poll id:int64 question:string options:vector<pollOption> total_voter_count:int32
//@description Describes a user profile photo @id Photo identifier; 0 for an empty photo. Can be used to find a photo in a list of user profile photos //@description Describes a user profile photo @id Photo identifier; 0 for an empty photo. Can be used to find a photo in a list of user profile photos
//@small A small (160x160) user profile photo. The file can be downloaded only before the photo is changed //@small A small (160x160) user profile photo. The file can be downloaded only before the photo is changed
//@big A big (640x640) user profile photo. The file can be downloaded only before the photo is changed //@big A big (640x640) user profile photo. The file can be downloaded only before the photo is changed
//@minithumbnail User profile photo minithumbnail; may be null
//@has_animation True, if the photo has animated variant //@has_animation True, if the photo has animated variant
profilePhoto id:int64 small:file big:file has_animation:Bool = ProfilePhoto; profilePhoto id:int64 small:file big:file minithumbnail:minithumbnail has_animation:Bool = ProfilePhoto;
//@description Contains basic information about the photo of a chat //@description Contains basic information about the photo of a chat
//@small A small (160x160) chat photo variant in JPEG format. The file can be downloaded only before the photo is changed //@small A small (160x160) chat photo variant in JPEG format. The file can be downloaded only before the photo is changed
//@big A big (640x640) chat photo variant in JPEG format. The file can be downloaded only before the photo is changed //@big A big (640x640) chat photo variant in JPEG format. The file can be downloaded only before the photo is changed
//@minithumbnail Chat photo minithumbnail; may be null
//@has_animation True, if the photo has animated variant //@has_animation True, if the photo has animated variant
chatPhotoInfo small:file big:file has_animation:Bool = ChatPhotoInfo; chatPhotoInfo small:file big:file minithumbnail:minithumbnail has_animation:Bool = ChatPhotoInfo;
//@class UserType @description Represents the type of a user. The following types are possible: regular users, deleted users and bots //@class UserType @description Represents the type of a user. The following types are possible: regular users, deleted users and bots

View File

@ -168,6 +168,7 @@ ProfilePhoto get_profile_photo(FileManager *file_manager, UserId user_id, int64
auto dc_id = DcId::create(profile_photo->dc_id_); auto dc_id = DcId::create(profile_photo->dc_id_);
result.has_animation = (profile_photo->flags_ & telegram_api::userProfilePhoto::HAS_VIDEO_MASK) != 0; result.has_animation = (profile_photo->flags_ & telegram_api::userProfilePhoto::HAS_VIDEO_MASK) != 0;
result.id = profile_photo->photo_id_; result.id = profile_photo->photo_id_;
result.minithumbnail = profile_photo->stripped_thumb_.as_slice().str();
result.small_file_id = result.small_file_id =
register_photo(file_manager, {DialogId(user_id), user_access_hash, false}, result.id, 0, "", register_photo(file_manager, {DialogId(user_id), user_access_hash, false}, result.id, 0, "",
std::move(profile_photo->photo_small_), DialogId(), 0, dc_id, PhotoFormat::Jpeg); std::move(profile_photo->photo_small_), DialogId(), 0, dc_id, PhotoFormat::Jpeg);
@ -191,7 +192,8 @@ tl_object_ptr<td_api::profilePhoto> get_profile_photo_object(FileManager *file_m
} }
return td_api::make_object<td_api::profilePhoto>( return td_api::make_object<td_api::profilePhoto>(
profile_photo.id, file_manager->get_file_object(profile_photo.small_file_id), profile_photo.id, file_manager->get_file_object(profile_photo.small_file_id),
file_manager->get_file_object(profile_photo.big_file_id), profile_photo.has_animation); file_manager->get_file_object(profile_photo.big_file_id), get_minithumbnail_object(profile_photo.minithumbnail),
profile_photo.has_animation);
} }
bool operator==(const ProfilePhoto &lhs, const ProfilePhoto &rhs) { bool operator==(const ProfilePhoto &lhs, const ProfilePhoto &rhs) {
@ -209,7 +211,7 @@ bool operator==(const ProfilePhoto &lhs, const ProfilePhoto &rhs) {
<< ", second profilePhoto: " << rhs; << ", second profilePhoto: " << rhs;
return false; return false;
} }
return lhs.has_animation == rhs.has_animation && !id_differs; return lhs.has_animation == rhs.has_animation && lhs.minithumbnail == rhs.minithumbnail && !id_differs;
} }
bool operator!=(const ProfilePhoto &lhs, const ProfilePhoto &rhs) { bool operator!=(const ProfilePhoto &lhs, const ProfilePhoto &rhs) {
@ -235,6 +237,7 @@ DialogPhoto get_dialog_photo(FileManager *file_manager, DialogId dialog_id, int6
auto dc_id = DcId::create(chat_photo->dc_id_); auto dc_id = DcId::create(chat_photo->dc_id_);
result.has_animation = (chat_photo->flags_ & telegram_api::chatPhoto::HAS_VIDEO_MASK) != 0; result.has_animation = (chat_photo->flags_ & telegram_api::chatPhoto::HAS_VIDEO_MASK) != 0;
result.minithumbnail = chat_photo->stripped_thumb_.as_slice().str();
result.small_file_id = result.small_file_id =
register_photo(file_manager, {dialog_id, dialog_access_hash, false}, 0, 0, "", register_photo(file_manager, {dialog_id, dialog_access_hash, false}, 0, 0, "",
std::move(chat_photo->photo_small_), DialogId(), 0, dc_id, PhotoFormat::Jpeg); std::move(chat_photo->photo_small_), DialogId(), 0, dc_id, PhotoFormat::Jpeg);
@ -258,6 +261,7 @@ tl_object_ptr<td_api::chatPhotoInfo> get_chat_photo_info_object(FileManager *fil
} }
return td_api::make_object<td_api::chatPhotoInfo>(file_manager->get_file_object(dialog_photo->small_file_id), return td_api::make_object<td_api::chatPhotoInfo>(file_manager->get_file_object(dialog_photo->small_file_id),
file_manager->get_file_object(dialog_photo->big_file_id), file_manager->get_file_object(dialog_photo->big_file_id),
get_minithumbnail_object(dialog_photo->minithumbnail),
dialog_photo->has_animation); dialog_photo->has_animation);
} }
@ -318,7 +322,7 @@ ProfilePhoto as_profile_photo(FileManager *file_manager, UserId user_id, int64 u
bool operator==(const DialogPhoto &lhs, const DialogPhoto &rhs) { bool operator==(const DialogPhoto &lhs, const DialogPhoto &rhs) {
return lhs.small_file_id == rhs.small_file_id && lhs.big_file_id == rhs.big_file_id && return lhs.small_file_id == rhs.small_file_id && lhs.big_file_id == rhs.big_file_id &&
lhs.has_animation == rhs.has_animation; lhs.minithumbnail == rhs.minithumbnail && lhs.has_animation == rhs.has_animation;
} }
bool operator!=(const DialogPhoto &lhs, const DialogPhoto &rhs) { bool operator!=(const DialogPhoto &lhs, const DialogPhoto &rhs) {

View File

@ -36,6 +36,7 @@ struct Dimensions {
struct DialogPhoto { struct DialogPhoto {
FileId small_file_id; FileId small_file_id;
FileId big_file_id; FileId big_file_id;
string minithumbnail;
bool has_animation = false; bool has_animation = false;
}; };

View File

@ -31,29 +31,39 @@ void parse(Dimensions &dimensions, ParserT &parser) {
template <class StorerT> template <class StorerT>
void store(const DialogPhoto &dialog_photo, StorerT &storer) { void store(const DialogPhoto &dialog_photo, StorerT &storer) {
bool has_file_ids = dialog_photo.small_file_id.is_valid() || dialog_photo.big_file_id.is_valid(); bool has_file_ids = dialog_photo.small_file_id.is_valid() || dialog_photo.big_file_id.is_valid();
bool has_minithumbnail = !dialog_photo.minithumbnail.empty();
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(has_file_ids); STORE_FLAG(has_file_ids);
STORE_FLAG(dialog_photo.has_animation); STORE_FLAG(dialog_photo.has_animation);
STORE_FLAG(has_minithumbnail);
END_STORE_FLAGS(); END_STORE_FLAGS();
if (has_file_ids) { if (has_file_ids) {
store(dialog_photo.small_file_id, storer); store(dialog_photo.small_file_id, storer);
store(dialog_photo.big_file_id, storer); store(dialog_photo.big_file_id, storer);
} }
if (has_minithumbnail) {
store(dialog_photo.minithumbnail, storer);
}
} }
template <class ParserT> template <class ParserT>
void parse(DialogPhoto &dialog_photo, ParserT &parser) { void parse(DialogPhoto &dialog_photo, ParserT &parser) {
bool has_file_ids = true; bool has_file_ids = true;
bool has_minithumbnail = false;
if (parser.version() >= static_cast<int32>(Version::AddDialogPhotoHasAnimation)) { if (parser.version() >= static_cast<int32>(Version::AddDialogPhotoHasAnimation)) {
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_file_ids); PARSE_FLAG(has_file_ids);
PARSE_FLAG(dialog_photo.has_animation); PARSE_FLAG(dialog_photo.has_animation);
PARSE_FLAG(has_minithumbnail);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
} }
if (has_file_ids) { if (has_file_ids) {
parse(dialog_photo.small_file_id, parser); parse(dialog_photo.small_file_id, parser);
parse(dialog_photo.big_file_id, parser); parse(dialog_photo.big_file_id, parser);
} }
if (has_minithumbnail) {
parse(dialog_photo.minithumbnail, parser);
}
} }
template <class StorerT> template <class StorerT>