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.java29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
index 9fbfce54..bb3140c3 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
@@ -7,6 +7,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession;
+import de.thedevstack.conversationsplus.utils.FileUtils;
import de.thedevstack.conversationsplus.utils.MimeUtils;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
@@ -417,6 +418,14 @@ public class Message extends AbstractEntity {
return getBody().startsWith(ME_COMMAND);
}
+ public String getBodyReplacedMeCommand(String replaceString) {
+ try {
+ return getBody().replaceAll("^" + Message.ME_COMMAND, replaceString + " ");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ return getBody();
+ }
+ }
+
public boolean trusted() {
Contact contact = this.getContact();
return (status > STATUS_RECEIVED || (contact != null && contact.trusted()));
@@ -460,26 +469,30 @@ public class Message extends AbstractEntity {
NEVER,
}
- private static String extractRelevantExtension(URL url) {
+ private String extractRelevantExtension(URL url) {
+ if (url == null) {
+ return null;
+ }
String path = url.getPath();
return extractRelevantExtension(path);
}
- private static String extractRelevantExtension(String path) {
+ private String extractRelevantExtension(String path) {
if (path == null || path.isEmpty()) {
return null;
}
String filename = path.substring(path.lastIndexOf('/') + 1).toLowerCase();
- int dotPosition = filename.lastIndexOf(".");
- if (dotPosition != -1) {
- String extension = filename.substring(dotPosition + 1);
+ final String lastPart = FileUtils.getLastExtension(filename);
+
+ if (!lastPart.isEmpty()) {
// we want the real file extension, not the crypto one
- if (Transferable.VALID_CRYPTO_EXTENSIONS.contains(extension)) {
- return extractRelevantExtension(filename.substring(0,dotPosition));
+ final String secondToLastPart = FileUtils.getSecondToLastExtension(filename);
+ if (!secondToLastPart.isEmpty() && Transferable.VALID_CRYPTO_EXTENSIONS.contains(lastPart)) {
+ return secondToLastPart;
} else {
- return extension;
+ return lastPart;
}
}
return null;