Skip to content

Commit

Permalink
Add minithumbnails to userProfilePhoto and chatPhotoInfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Apr 9, 2021
1 parent 969b52c commit 3786033
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
6 changes: 4 additions & 2 deletions td/generate/scheme/td_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -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
//@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
//@minithumbnail User profile photo minithumbnail; may be null
//@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
//@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
//@minithumbnail Chat photo minithumbnail; may be null
//@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
Expand Down
10 changes: 7 additions & 3 deletions td/telegram/Photo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ ProfilePhoto get_profile_photo(FileManager *file_manager, UserId user_id, int64
auto dc_id = DcId::create(profile_photo->dc_id_);
result.has_animation = (profile_photo->flags_ & telegram_api::userProfilePhoto::HAS_VIDEO_MASK) != 0;
result.id = profile_photo->photo_id_;
result.minithumbnail = profile_photo->stripped_thumb_.as_slice().str();
result.small_file_id =
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);
Expand All @@ -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>(
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) {
Expand All @@ -209,7 +211,7 @@ bool operator==(const ProfilePhoto &lhs, const ProfilePhoto &rhs) {
<< ", second profilePhoto: " << rhs;
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) {
Expand All @@ -235,6 +237,7 @@ DialogPhoto get_dialog_photo(FileManager *file_manager, DialogId dialog_id, int6

auto dc_id = DcId::create(chat_photo->dc_id_);
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 =
register_photo(file_manager, {dialog_id, dialog_access_hash, false}, 0, 0, "",
std::move(chat_photo->photo_small_), DialogId(), 0, dc_id, PhotoFormat::Jpeg);
Expand All @@ -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),
file_manager->get_file_object(dialog_photo->big_file_id),
get_minithumbnail_object(dialog_photo->minithumbnail),
dialog_photo->has_animation);
}

Expand Down Expand Up @@ -318,7 +322,7 @@ ProfilePhoto as_profile_photo(FileManager *file_manager, UserId user_id, int64 u

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 &&
lhs.has_animation == rhs.has_animation;
lhs.minithumbnail == rhs.minithumbnail && lhs.has_animation == rhs.has_animation;
}

bool operator!=(const DialogPhoto &lhs, const DialogPhoto &rhs) {
Expand Down
1 change: 1 addition & 0 deletions td/telegram/Photo.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct Dimensions {
struct DialogPhoto {
FileId small_file_id;
FileId big_file_id;
string minithumbnail;
bool has_animation = false;
};

Expand Down
10 changes: 10 additions & 0 deletions td/telegram/Photo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,39 @@ void parse(Dimensions &dimensions, ParserT &parser) {
template <class StorerT>
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_minithumbnail = !dialog_photo.minithumbnail.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_file_ids);
STORE_FLAG(dialog_photo.has_animation);
STORE_FLAG(has_minithumbnail);
END_STORE_FLAGS();
if (has_file_ids) {
store(dialog_photo.small_file_id, storer);
store(dialog_photo.big_file_id, storer);
}
if (has_minithumbnail) {
store(dialog_photo.minithumbnail, storer);
}
}

template <class ParserT>
void parse(DialogPhoto &dialog_photo, ParserT &parser) {
bool has_file_ids = true;
bool has_minithumbnail = false;
if (parser.version() >= static_cast<int32>(Version::AddDialogPhotoHasAnimation)) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_file_ids);
PARSE_FLAG(dialog_photo.has_animation);
PARSE_FLAG(has_minithumbnail);
END_PARSE_FLAGS();
}
if (has_file_ids) {
parse(dialog_photo.small_file_id, parser);
parse(dialog_photo.big_file_id, parser);
}
if (has_minithumbnail) {
parse(dialog_photo.minithumbnail, parser);
}
}

template <class StorerT>
Expand Down

0 comments on commit 3786033

Please sign in to comment.