Skip to content

Commit ee0d4fd

Browse files
committed
Fixed profile pictures after the first 80 never loading in the avatar gallery. (#463)
1 parent 19e44dd commit ee0d4fd

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

TMessagesProj/src/main/java/org/telegram/messenger/FileRefController.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ public void requestReference(Object parentObject, Object... args) {
357357
sendErrorToObject(args, 0);
358358
return;
359359
}
360+
if (parentObject instanceof String && ((String) parentObject).startsWith("avatar_") && Utilities.parseLong((String) parentObject) > 0) {
361+
long photoId = getRequestedPhotoId(args[0]);
362+
if (photoId != 0) {
363+
parentKey += "_" + photoId;
364+
}
365+
}
360366

361367
Requester requester = new Requester();
362368
requester.args = args;
@@ -595,9 +601,16 @@ private void requestReferenceFromServer(Object parentObject, String locationKey,
595601
long id = Utilities.parseLong(string);
596602
if (id > 0) {
597603
TLRPC.TL_photos_getUserPhotos req = new TLRPC.TL_photos_getUserPhotos();
598-
req.limit = 80;
599-
req.offset = 0;
600-
req.max_id = 0;
604+
long photoId = getRequestedPhotoId(args[0]);
605+
if (photoId != 0) {
606+
req.limit = 1;
607+
req.offset = -1;
608+
req.max_id = photoId;
609+
} else {
610+
req.limit = 80;
611+
req.offset = 0;
612+
req.max_id = 0;
613+
}
601614
req.user_id = getMessagesController().getInputUser(id);
602615
getConnectionsManager().sendRequest(req, (response, error) -> onRequestComplete(locationKey, parentKey, response, error, true, false));
603616
} else {
@@ -652,6 +665,16 @@ private void requestReferenceFromServer(Object parentObject, String locationKey,
652665
}
653666
}
654667

668+
private static long getRequestedPhotoId(Object arg) {
669+
if (arg instanceof TLRPC.TL_inputPhotoFileLocation) {
670+
return ((TLRPC.TL_inputPhotoFileLocation) arg).id;
671+
}
672+
if (arg instanceof TLRPC.TL_inputPeerPhotoFileLocation) {
673+
return ((TLRPC.TL_inputPeerPhotoFileLocation) arg).photo_id;
674+
}
675+
return 0;
676+
}
677+
655678
private boolean isSameReference(byte[] oldRef, byte[] newRef) {
656679
return Arrays.equals(oldRef, newRef);
657680
}

TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17228,12 +17228,12 @@ private void setIndexToImage(ImageReceiver imageReceiver, int index, CropTransfo
1722817228
}
1722917229
} else if (avatarsDialogId != 0) {
1723017230
if (avatarsDialogId > 0) {
17231-
parentObject = MessagesController.getInstance(currentAccount).getUser(avatarsDialogId);
17231+
parentObject = "avatar_" + avatarsDialogId;
1723217232
} else {
1723317233
parentObject = MessagesController.getInstance(currentAccount).getChat(-avatarsDialogId);
17234-
}
17235-
if (photoObject != null) {
17236-
parentObject = photoObject;
17234+
if (photoObject != null) {
17235+
parentObject = photoObject;
17236+
}
1723717237
}
1723817238
if (placeHolder == null && thumbLocation instanceof TLRPC.TL_photoStrippedSize) {
1723917239
placeHolder = new ImageReceiver.BitmapHolder(ImageLoader.getStrippedPhotoBitmap(thumbLocation.bytes, "b"));

0 commit comments

Comments
 (0)