Skip to content

Commit

Permalink
fix: scale photo size in secret chat
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Jun 24, 2024
1 parent ee66868 commit 000c6e4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2628,6 +2628,10 @@ public static int getPhotoSize() {
return photoSize;
}

public static int getPhotoSizeOld() {
return 1280;
}

/*public static void clearCursorDrawable(EditText editText) {
if (editText == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6747,6 +6747,19 @@ public void prepareImportStickers(String title, String shortName, String sofrwar
}).start();
}

public void removeBigPhotoSizes(TLRPC.TL_photo photo, Boolean isEncrypted) {
if (!isEncrypted || photo == null) {
return;
}
ArrayList<TLRPC.PhotoSize> sizes = new ArrayList<>();
for (TLRPC.PhotoSize size: photo.sizes) {
if (size != null && size.w <= AndroidUtilities.getPhotoSizeOld() && size.h <= AndroidUtilities.getPhotoSizeOld()) {
sizes.add(size);
}
}
photo.sizes = sizes;
}

public TLRPC.TL_photo generatePhotoSizes(String path, Uri imageUri) {
return generatePhotoSizes(null, path, imageUri);
}
Expand All @@ -6761,6 +6774,14 @@ public TLRPC.TL_photo generatePhotoSizes(TLRPC.TL_photo photo, String path, Uri
if (size != null) {
sizes.add(size);
}

// ===== Nagram Hook start =====
size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.getPhotoSizeOld(), AndroidUtilities.getPhotoSizeOld(), true, 80, false, 101, 101);
if (size != null) {
sizes.add(size);
}
// ===== Nagram Hook end =====

size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), true, 80, false, 101, 101);
if (size != null) {
sizes.add(size);
Expand Down Expand Up @@ -8002,6 +8023,11 @@ public static void prepareSendingMedia(AccountInstance accountInstance, ArrayLis
worker.sync = new CountDownLatch(1);
mediaSendThreadPool.execute(() -> {
worker.photo = accountInstance.getSendMessagesHelper().generatePhotoSizes(info.path, info.uri);

// ===== Nagram Hook start =====
accountInstance.getSendMessagesHelper().removeBigPhotoSizes(worker.photo, isEncrypted);
// ===== Nagram Hook end =====

if (isEncrypted && info.canDeleteAfter) {
new File(info.path).delete();
}
Expand Down Expand Up @@ -8561,6 +8587,11 @@ public static void prepareSendingMedia(AccountInstance accountInstance, ArrayLis
}
if (photo == null) {
photo = accountInstance.getSendMessagesHelper().generatePhotoSizes(info.path, info.uri);

// ===== Nagram Hook start =====
accountInstance.getSendMessagesHelper().removeBigPhotoSizes(photo, isEncrypted);
// ===== Nagram Hook end =====

if (isEncrypted && info.canDeleteAfter) {
new File(info.path).delete();
}
Expand Down

0 comments on commit 000c6e4

Please sign in to comment.