diff options
author | lookshe <github@lookshe.org> | 2016-03-17 22:14:49 +0100 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2016-03-17 22:14:49 +0100 |
commit | cb55d2af52c1007b577b1bb1f94a4206aec58ef0 (patch) | |
tree | 1fb23a1937d38100876d1eb69c4d5566f394ec1a /src/main/java/de/thedevstack/conversationsplus/entities | |
parent | 0de9c2aa23990749360ee0e9f509e13a54b14137 (diff) |
completely implements FS#161
save state of treatAsDownloadable() and set on error to specified value
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/entities')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/entities/Message.java | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java index bb3140c3..8dbb0535 100644 --- a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java +++ b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java @@ -81,6 +81,7 @@ public class Message extends AbstractEntity { private Message mNextMessage = null; private Message mPreviousMessage = null; private String axolotlFingerprint = null; + private Decision mTreatAsDownloadAble = Decision.NOT_DECIDED; private Message() { @@ -467,6 +468,7 @@ public class Message extends AbstractEntity { MUST, SHOULD, NEVER, + NOT_DECIDED, } private String extractRelevantExtension(URL url) { @@ -515,44 +517,64 @@ public class Message extends AbstractEntity { } } + /** + * in case of later found error with decision, set it to a value which does not affect anything, hopefully + */ + public void setNoDownloadable() { + mTreatAsDownloadAble = Decision.NEVER; + } + public Decision treatAsDownloadable() { + // only test this ones, body will not change + 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(" ")) { - return Decision.NEVER; + mTreatAsDownloadAble = Decision.NEVER; + return mTreatAsDownloadAble; } try { URL url = new URL(body); if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) { - return Decision.NEVER; + mTreatAsDownloadAble = Decision.NEVER; + return mTreatAsDownloadAble; } else if (oob) { - return Decision.MUST; + mTreatAsDownloadAble = Decision.MUST; + return mTreatAsDownloadAble; } String extension = extractRelevantExtension(url); if (extension == null) { - return Decision.NEVER; + 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) { - return Decision.MUST; + mTreatAsDownloadAble = Decision.MUST; + return mTreatAsDownloadAble; } else { - return Decision.NEVER; + mTreatAsDownloadAble = Decision.NEVER; + return mTreatAsDownloadAble; } } else if (Transferable.VALID_IMAGE_EXTENSIONS.contains(extension) || Transferable.WELL_KNOWN_EXTENSIONS.contains(extension)) { - return Decision.SHOULD; + mTreatAsDownloadAble = Decision.SHOULD; + return mTreatAsDownloadAble; } else { - return Decision.NEVER; + mTreatAsDownloadAble = Decision.NEVER; + return mTreatAsDownloadAble; } } catch (MalformedURLException e) { - return Decision.NEVER; + mTreatAsDownloadAble = Decision.NEVER; + return mTreatAsDownloadAble; } } |