From 3bd6fa825771b577119411c7800a5cd3c6b3e43e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 26 Oct 2020 06:35:11 +0000 Subject: [PATCH] Fix gif loading --- .../org/telegram/messenger/FileLoader.java | 34 ++++++++++++------- .../org/telegram/messenger/ImageLoader.java | 4 ++- .../java/org/telegram/ui/ProfileActivity.java | 2 ++ bin/update_libs.sh | 2 +- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java index 667afeef3..2d43674f3 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java @@ -29,10 +29,15 @@ public class FileLoader extends BaseController { public interface FileLoaderDelegate { void fileUploadProgressChanged(String location, long uploadedSize, long totalSize, boolean isEncrypted); + void fileDidUploaded(String location, TLRPC.InputFile inputFile, TLRPC.InputEncryptedFile inputEncryptedFile, byte[] key, byte[] iv, long totalFileSize); + void fileDidFailedUpload(String location, boolean isEncrypted); + void fileDidLoaded(String location, File finalFile, int type); + void fileDidFailedLoad(String location, int state); + void fileLoadProgressChanged(String location, long uploadedSize, long totalSize); } @@ -86,6 +91,7 @@ public class FileLoader extends BaseController { private ConcurrentHashMap parentObjectReferences = new ConcurrentHashMap<>(); private static volatile FileLoader[] Instance = new FileLoader[UserConfig.MAX_ACCOUNT_COUNT]; + public static FileLoader getInstance(int num) { FileLoader localInstance = Instance[num]; if (localInstance == null) { @@ -411,15 +417,15 @@ public class FileLoader extends BaseController { int index = downloadQueue.indexOf(operation); if (index >= 0) { downloadQueue.remove(index); - if (operation.start()) { - count.put(datacenterId, count.get(datacenterId) + 1); - } - if (queueType == QUEUE_TYPE_FILE) { - if (operation.wasStarted() && !activeFileLoadOperation.contains(operation)) { - pauseCurrentFileLoadOperations(operation); - activeFileLoadOperation.add(operation); - } + if (operation.start()) { + count.put(datacenterId, count.get(datacenterId) + 1); + } + if (queueType == QUEUE_TYPE_FILE) { + if (operation.wasStarted() && !activeFileLoadOperation.contains(operation)) { + pauseCurrentFileLoadOperations(operation); + activeFileLoadOperation.add(operation); } + } } else { pauseCurrentFileLoadOperations(operation); operation.start(); @@ -787,7 +793,7 @@ public class FileLoader extends BaseController { final CountDownLatch semaphore = new CountDownLatch(1); final FileLoadOperation[] result = new FileLoadOperation[1]; fileLoaderQueue.postRunnable(() -> { - result[0] = loadFileInternal(document, null, null, document == null && location != null ? location.location : null, location, parentObject, document == null && location != null ? "mp4" : null, document == null && location != null ? location.currentSize : 0, 1, stream, offset, priority, document == null ? 1 : 0); + result[0] = loadFileInternal(document, null, null, document == null && location != null ? location.location : null, location, parentObject, document == null && location != null ? "mp4" : null, document == null && location != null ? location.currentSize : 0, 1, stream, offset, priority, document == null ? 1 : 0); semaphore.countDown(); }); try { @@ -960,8 +966,10 @@ public class FileLoader extends BaseController { } else { if (MessageObject.isVoiceDocument(document)) { dir = getDirectory(MEDIA_DIR_AUDIO); - } else if (MessageObject.isVideoDocument(document)) { + } else if (MessageObject.isVideoDocument(document) || MessageObject.isGifDocument(document)) { dir = getDirectory(MEDIA_DIR_VIDEO); + } else if (MessageObject.isStickerDocument(document)) { + dir = getDirectory(MEDIA_DIR_CACHE); } else { dir = getDirectory(MEDIA_DIR_DOCUMENT); } @@ -1131,9 +1139,9 @@ public class FileLoader extends BaseController { TLRPC.Document document = (TLRPC.Document) attach; if (document.mime_type != null && ( document.mime_type.startsWith("application/x") || - document.mime_type.startsWith("audio/") || - document.mime_type.startsWith("video/") || - document.mime_type.startsWith("image/"))) { + document.mime_type.startsWith("audio/") || + document.mime_type.startsWith("video/") || + document.mime_type.startsWith("image/"))) { String docExt = getDocumentFileName(document); int idx; if (docExt == null || (idx = docExt.lastIndexOf('.')) == -1) { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java index 2da102e43..5ac0319b3 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java @@ -2347,8 +2347,10 @@ public class ImageLoader { TLRPC.Document document = imageLocation.document; if (document instanceof TLRPC.TL_documentEncrypted) { cacheFile = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), url); - } else if (MessageObject.isVideoDocument(document)) { + } else if (MessageObject.isVideoDocument(document) || MessageObject.isGifDocument(document)) { cacheFile = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_VIDEO), url); + } else if (MessageObject.isStickerDocument(document)) { + cacheFile = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), url); } else { cacheFile = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_DOCUMENT), url); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index d8e7aa5e4..f7be9a32f 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -5318,6 +5318,8 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. if (user.photo != null && user.photo.dc_id != 0) { idTextView.setText("ID: " + user_id + ", DC: " + user.photo.dc_id); + } else if (UserObject.isUserSelf(user) && getMessagesController().thisDc > 0) { + idTextView.setText("ID: " + user.id + ", DC: " + getMessagesController().thisDc); } else { idTextView.setText("ID: " + user_id); } diff --git a/bin/update_libs.sh b/bin/update_libs.sh index 441025a5d..414aa2417 100755 --- a/bin/update_libs.sh +++ b/bin/update_libs.sh @@ -1,6 +1,6 @@ #!/bin/bash -V2RAY_CORE_VERSION="4.31.2" +V2RAY_CORE_VERSION="4.31.3" if [ ! -x "$(command -v go)" ]; then