diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities/Message.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/entities/Message.java | 62 |
1 files changed, 5 insertions, 57 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index 5abba478..f524fc58 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -9,6 +9,7 @@ import java.net.URL; import de.thedevstack.conversationsplus.entities.FileParams; import de.thedevstack.conversationsplus.enums.FileStatus; +import de.thedevstack.conversationsplus.utils.MessageUtil; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession; import eu.siacs.conversations.utils.FileUtils; import eu.siacs.conversations.utils.MimeUtils; @@ -339,7 +340,7 @@ public class Message extends AbstractEntity { public void setType(int type) { this.type = type; - if (null != this.fileParams && (type == Message.TYPE_FILE || type == Message.TYPE_IMAGE)) { + if (null == this.fileParams && (type == Message.TYPE_FILE || type == Message.TYPE_IMAGE)) { this.setFileParams(new FileParams()); } } @@ -482,18 +483,6 @@ public class Message extends AbstractEntity { NOT_DECIDED, } - private String extractRelevantExtension(URL url) { - if (url == null) { - return null; - } - String path = url.getPath(); - return extractRelevantExtension(path); - } - - private String extractRelevantExtension(String path) { - return FileUtils.getRelevantExtension(path); - } - public String getMimeType() { // TODO: Move to fileparams if (relativeFilePath != null) { int start = relativeFilePath.lastIndexOf('.') + 1; @@ -504,7 +493,7 @@ public class Message extends AbstractEntity { } } else { try { - return MimeUtils.guessMimeTypeFromExtension(extractRelevantExtension(new URL(this.getBody()))); + return MimeUtils.guessMimeTypeFromExtension(FileUtils.getRelevantExtension(new URL(this.getBody()))); } catch (MalformedURLException e) { return null; } @@ -527,50 +516,9 @@ public class Message extends AbstractEntity { if (mTreatAsDownloadAble != Decision.NOT_DECIDED) { return mTreatAsDownloadAble; } - /** - * there are a few cases where spaces result in an unwanted behavior, e.g. - * "http://example.com/image.jpg" text that will not be shown /abc.png" - * or more than one image link in one message. - */ - if (getBody().contains(" ")) { - mTreatAsDownloadAble = Decision.NEVER; - return mTreatAsDownloadAble; - } - try { - URL url = new URL(body); - if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) { - mTreatAsDownloadAble = Decision.NEVER; - return mTreatAsDownloadAble; - } - String extension = extractRelevantExtension(url); - if (extension == null) { - mTreatAsDownloadAble = Decision.NEVER; - return mTreatAsDownloadAble; - } - String ref = url.getRef(); - boolean encrypted = ref != null && ref.matches("([A-Fa-f0-9]{2}){48}"); - - if (encrypted) { - if (MimeUtils.guessMimeTypeFromExtension(extension) != null) { - mTreatAsDownloadAble = Decision.MUST; - return mTreatAsDownloadAble; - } else { - mTreatAsDownloadAble = Decision.NEVER; - return mTreatAsDownloadAble; - } - } else if (Transferable.VALID_IMAGE_EXTENSIONS.contains(extension) - || Transferable.WELL_KNOWN_EXTENSIONS.contains(extension)) { - mTreatAsDownloadAble = Decision.SHOULD; - return mTreatAsDownloadAble; - } else { - mTreatAsDownloadAble = Decision.NEVER; - return mTreatAsDownloadAble; - } - } catch (MalformedURLException e) { - mTreatAsDownloadAble = Decision.NEVER; - return mTreatAsDownloadAble; - } + MessageUtil.extractFileParamsFromBody(this); + return this.mTreatAsDownloadAble; } public void untie() { |