From 84a2f8e41ac4d5a7ebc24f4eb5b99e9bc3029f1f Mon Sep 17 00:00:00 2001 From: steckbrief Date: Wed, 31 Jan 2018 19:52:50 +0100 Subject: properly handle downloadable links --- .../http/download/HttpDownloadFileTransferService.java | 3 ++- .../conversationsplus/ui/adapter/MessageAdapter.java | 2 +- .../de/thedevstack/conversationsplus/utils/MessageUtil.java | 12 ++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferService.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferService.java index c7fcc430..583b9d2b 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferService.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferService.java @@ -60,6 +60,7 @@ public class HttpDownloadFileTransferService extends AbstractFileTransferService @Override public boolean accept(Message message) { return MessageUtil.needsDownload(message) - && message.hasFileAttached() && (null == message.getFileParams() || message.getFileParams().isRemoteAvailable()); + && (message.hasFileAttached() || MessageUtil.hasDownloadableLink(message)) + && (null == message.getFileParams() || message.getFileParams().isRemoteAvailable()); } } diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java index 4c2917e3..0b544581 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java @@ -683,7 +683,7 @@ public class MessageAdapter extends ArrayAdapter { viewHolder.darkBackground = (type == RECEIVED && !isInValidSession); this.displayStatus(viewHolder, message, type); - if (null != message.getTransferable() || message.hasFileAttached()) { + if (null != message.getTransferable() || message.hasFileAttached() || MessageUtil.hasDownloadableLink(message)) { if (!(message.trusted() && MessageUtil.needsDownload(message) && ConversationsPlusPreferences.autoAcceptFileSize() > 0 diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java index 5e629485..fa403cc5 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java @@ -9,6 +9,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import de.thedevstack.conversationsplus.ConversationsPlusApplication; +import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.entities.Conversation; import de.thedevstack.conversationsplus.entities.DownloadableFile; import de.thedevstack.conversationsplus.entities.FileParams; @@ -172,11 +173,18 @@ public final class MessageUtil { public static boolean needsDownload(Message message) { FileStatus fileStatus = (null != message.getFileParams()) ? message.getFileParams().getFileStatus() : null; - return (null == fileStatus - || (null != fileStatus && (fileStatus == FileStatus.NEEDS_DOWNLOAD || fileStatus == FileStatus.UNDEFINED))) + return (message.hasFileAttached() || MessageUtil.hasDownloadableLink(message)) + &&(null == fileStatus + || (null != fileStatus && (fileStatus == FileStatus.NEEDS_DOWNLOAD || fileStatus == FileStatus.UNDEFINED))) && message.treatAsDownloadable() != Message.Decision.NEVER; } + public static boolean hasDownloadableLink(Message message) { + String url = (null != message.getFileParams()) ? message.getFileParams().getUrl() : null; + return ConversationsPlusPreferences.autoDownloadFileLink() + && null != url; + } + public static boolean isMessageSent(Message message) { switch (message.getStatus()) { case Message.STATUS_SEND: -- cgit v1.2.3