From 77920c7aa608bd92391ade653eb8971b977eb7d5 Mon Sep 17 00:00:00 2001 From: Andreas Straub Date: Wed, 29 Jul 2015 02:49:14 +0200 Subject: [PATCH] Color plaintext messages in encrypted sessions red Plaintext messages that were received while in an encrypted session are now colored red. We define "in an encrypted session" if a) the last message sent by our own device before the message under consideration (or any message received between then and now) was encrypted AND b) the next message will be sent encrypted or the next message sent after the one under consideration was sent encrypted --- .../ui/adapter/MessageAdapter.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) 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 f55094af6..c44796bac 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -560,6 +560,36 @@ public class MessageAdapter extends ArrayAdapter { } } + if (type == RECEIVED) { + boolean wasEncrypted = false; + for (Message iterator = message.prev(); iterator != null; iterator = iterator.prev()){ + if (iterator.getEncryption() != Message.ENCRYPTION_NONE) { + wasEncrypted = true; + break; + } + if (iterator.getRemoteMsgId() == null && iterator.getType() == SENT) { + break; + } + } + boolean willBeEncrypted = conversation.getNextEncryption(false) != Message.ENCRYPTION_NONE; + for (Message iterator = message.next(); iterator != null; iterator = iterator.next()){ + if (iterator.getEncryption() != Message.ENCRYPTION_NONE) { + willBeEncrypted = true; + break; + } + if (iterator.getRemoteMsgId() == null && iterator.getType() == SENT) { + break; + } + } + + if ( willBeEncrypted && wasEncrypted + && message.getEncryption() == Message.ENCRYPTION_NONE) { + viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received_warning); + } else { + viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received); + } + } + displayStatus(viewHolder, message); return view;