diff options
author | lookshe <github@lookshe.org> | 2016-03-12 02:28:22 +0100 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2016-03-12 02:28:22 +0100 |
commit | bf49abe865ca746fad452a759f3792ca322e1fce (patch) | |
tree | 89c57470ffb1bd4cf12364ccab8814156e0fa3f8 /src/main/java/eu/siacs/conversations/entities/Message.java | |
parent | 3041cc74cefb4a25f4d1af7109fcb141ec3293d8 (diff) |
Added method to get body from message if hasMeCommand and harmonized extraction of fileextension (FS#38)
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/entities/Message.java | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index f463da54..c377ed4a 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -62,7 +62,7 @@ public class Message extends AbstractEntity { protected String conversationUuid; protected Jid counterpart; protected Jid trueCounterpart; - protected String body; + private String body; protected String encryptedBody; protected long timeSent; protected int encryption; @@ -417,6 +417,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 +468,31 @@ public class Message extends AbstractEntity { NEVER, } - private static String extractRelevantExtension(URL url) { + private String extractRelevantExtension(URL url) { 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 int lastDotPosition = filename.lastIndexOf('.'); + final int secondToLastDotPosition = filename.lastIndexOf('.', lastDotPosition - 1); + final String lastPart = lastDotPosition != -1 ? + filename.substring(lastDotPosition + 1) : ""; + final String secondToLastPart = secondToLastDotPosition != -1 ? + filename.substring(secondToLastDotPosition + 1, lastDotPosition - 1) : ""; + + if (lastDotPosition != -1) { // we want the real file extension, not the crypto one - if (Transferable.VALID_CRYPTO_EXTENSIONS.contains(extension)) { - return extractRelevantExtension(filename.substring(0,dotPosition)); + if (secondToLastDotPosition != -1 && Transferable.VALID_CRYPTO_EXTENSIONS.contains(lastPart)) { + return secondToLastPart; } else { - return extension; + return lastPart; } } return null; |