diff options
author | Daniel Gultsch <inputmice@siacs.eu> | 2015-01-11 15:19:36 +0100 |
---|---|---|
committer | Daniel Gultsch <inputmice@siacs.eu> | 2015-01-11 15:19:36 +0100 |
commit | b07b7519a6bf382be809b8d33b801080a1616c8f (patch) | |
tree | 98a14abedbb965f7b06f56c9f54705f032183d24 /src/main/java/eu/siacs/conversations/persistance | |
parent | 12d63f2612377fbbb01e885145e2366bf0835f47 (diff) |
keep proper image file extension
Diffstat (limited to 'src/main/java/eu/siacs/conversations/persistance')
-rw-r--r-- | src/main/java/eu/siacs/conversations/persistance/FileBackend.java | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index f7defcdf..62987aaa 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -57,28 +57,33 @@ public class FileBackend { public DownloadableFile getFile(Message message, boolean decrypted) { String path = message.getRelativeFilePath(); - if (!decrypted && (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED)) { - String extension; - if (path != null && !path.isEmpty()) { - String[] parts = path.split("\\."); - extension = "."+parts[parts.length - 1]; - } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_TEXT) { + String extension; + if (path != null && !path.isEmpty()) { + String[] parts = path.split("\\."); + extension = "."+parts[parts.length - 1]; + } else { + if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_TEXT) { extension = ".webp"; } else { extension = ""; } + path = message.getUuid()+extension; + } + final boolean encrypted = !decrypted + && (message.getEncryption() == Message.ENCRYPTION_PGP + || message.getEncryption() == Message.ENCRYPTION_DECRYPTED); + if (encrypted) { return new DownloadableFile(getConversationsFileDirectory()+message.getUuid()+extension+".pgp"); - } else if (path != null && !path.isEmpty()) { + } else { if (path.startsWith("/")) { return new DownloadableFile(path); } else { - return new DownloadableFile(getConversationsFileDirectory()+path); + if (message.getType() == Message.TYPE_FILE) { + return new DownloadableFile(getConversationsFileDirectory() + path); + } else { + return new DownloadableFile(getConversationsImageDirectory()+path); + } } - } else { - StringBuilder filename = new StringBuilder(); - filename.append(getConversationsImageDirectory()); - filename.append(message.getUuid()+".webp"); - return new DownloadableFile(filename.toString()); } } |