diff options
author | lookshe <github@lookshe.org> | 2016-03-12 15:51:17 +0100 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2016-03-12 15:51:17 +0100 |
commit | 14c2c72bc1a00c8b9839047cdc73116e561ecd62 (patch) | |
tree | fe0828e9357d1876a0e3aa72ae13a2dad19718c4 /src/main/java/de/thedevstack/conversationsplus/entities/Message.java | |
parent | 2a486c667a0c81772fcf125c5c3c9b49c78250e3 (diff) | |
parent | dc26c95b40c3d0f48ed539f91e53c1bff1dceec6 (diff) |
Merge branch 'trz/rebase' into trz/rename
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/entities/Message.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/entities/Message.java | 29 |
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; |