aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/entities/Message.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Message.java62
1 files changed, 5 insertions, 57 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
index a81ba404..a553a3e6 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
@@ -9,6 +9,7 @@ import java.net.URL;
import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession;
import de.thedevstack.conversationsplus.enums.FileStatus;
import de.thedevstack.conversationsplus.utils.FileUtils;
+import de.thedevstack.conversationsplus.utils.MessageUtil;
import de.thedevstack.conversationsplus.utils.MimeUtils;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
@@ -337,7 +338,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());
}
}
@@ -480,18 +481,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;
@@ -502,7 +491,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;
}
@@ -525,50 +514,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() {