From e9bf2b464cb52d8a5f1db3d029b08e7e87be2435 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 12 Jan 2019 09:01:32 +0100 Subject: [PATCH] explicitly set type=images for all media with an image mime type this is in preperation to be able to query the database for all images --- .../crypto/PgpDecryptionService.java | 2 +- .../conversations/entities/Conversation.java | 2 +- .../conversations/persistance/FileBackend.java | 16 ++++------------ .../conversations/ui/adapter/MessageAdapter.java | 2 +- .../xmpp/jingle/JingleConnection.java | 2 +- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java b/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java index 8d6d3d682..2989f356a 100644 --- a/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java +++ b/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java @@ -177,7 +177,7 @@ public class PgpDecryptionService { mXmppConnectionService.updateMessage(message); break; } - } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) { + } else if (message.isFileOrImage()) { try { final DownloadableFile inputFile = mXmppConnectionService.getFileBackend().getFile(message, false); final DownloadableFile outputFile = mXmppConnectionService.getFileBackend().getFile(message, true); diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index bffba3d87..d9db92934 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -184,7 +184,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl for (final Message message : this.messages) { if (message.getUuid().equals(uuid) && message.getEncryption() != Message.ENCRYPTION_PGP - && (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.treatAsDownloadable())) { + && (message.isFileOrImage() || message.treatAsDownloadable())) { return message; } } diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 459cb88ba..eb84fb64a 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -1169,9 +1169,9 @@ public class FileBackend { public void updateFileParams(Message message, URL url) { DownloadableFile file = getFile(message); final String mime = file.getMimeType(); - boolean image = message.getType() == Message.TYPE_IMAGE || (mime != null && mime.startsWith("image/")); - boolean video = mime != null && mime.startsWith("video/"); - boolean audio = mime != null && mime.startsWith("audio/"); + final boolean image = message.getType() == Message.TYPE_IMAGE || (mime != null && mime.startsWith("image/")); + final boolean video = mime != null && mime.startsWith("video/"); + final boolean audio = mime != null && mime.startsWith("audio/"); final StringBuilder body = new StringBuilder(); if (url != null) { body.append(url.toString()); @@ -1192,17 +1192,9 @@ public class FileBackend { } message.setBody(body.toString()); message.setDeleted(false); + message.setType(image ? Message.TYPE_IMAGE : Message.TYPE_FILE); } - public int getMediaRuntime(Uri uri) { - try { - MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever(); - mediaMetadataRetriever.setDataSource(mXmppConnectionService, uri); - return Integer.parseInt(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)); - } catch (RuntimeException e) { - return 0; - } - } private int getMediaRuntime(File file) { try { diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 27ed7cb34..800b9c984 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -217,7 +217,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie final Transferable transferable = message.getTransferable(); boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI && message.getMergedStatus() <= Message.STATUS_RECEIVED; - if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || transferable != null) { + if (message.isFileOrImage() || transferable != null) { FileParams params = message.getFileParams(); if (params.size > (1.5 * 1024 * 1024)) { filesize = Math.round(params.size * 1f / (1024 * 1024)) + " MiB"; diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index da01ab086..9e70f3e5f 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -469,7 +469,7 @@ public class JingleConnection implements Transferable { private void sendInitRequest() { JinglePacket packet = this.bootstrapPacket("session-initiate"); Content content = new Content(this.contentCreator, this.contentName); - if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) { + if (message.isFileOrImage()) { content.setTransportId(this.transportId); this.file = this.mXmppConnectionService.getFileBackend().getFile(message, false); if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {