aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/entities
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-01-16 21:01:58 +0100
committerChristian Schneppe <christian@pix-art.de>2017-01-16 21:01:58 +0100
commit6611f60cdfbf5b6be453d84cffd298fafbcc0a03 (patch)
tree554e145c6d4afac7a0fd3355e1dbe10e6b3d8e26 /src/main/java/de/pixart/messenger/entities
parent8c251fc0ddaf88c1ca79fe0d09abc0fc88da33d0 (diff)
fixed behaviour with non-default encryption masks
Diffstat (limited to 'src/main/java/de/pixart/messenger/entities')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java53
1 files changed, 35 insertions, 18 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java
index 63ff27ebf..0928c2ebf 100644
--- a/src/main/java/de/pixart/messenger/entities/Conversation.java
+++ b/src/main/java/de/pixart/messenger/entities/Conversation.java
@@ -24,6 +24,7 @@ import java.util.Locale;
import de.pixart.messenger.Config;
import de.pixart.messenger.crypto.PgpDecryptionService;
+import de.pixart.messenger.crypto.axolotl.AxolotlService;
import de.pixart.messenger.xmpp.chatstate.ChatState;
import de.pixart.messenger.xmpp.jid.InvalidJidException;
import de.pixart.messenger.xmpp.jid.Jid;
@@ -692,25 +693,41 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
return this.nextCounterpart;
}
- private int getMostRecentlyUsedIncomingEncryption() {
- synchronized (this.messages) {
- for (int i = this.messages.size() - 1; i >= 0; --i) {
- final Message m = this.messages.get(i);
- if (m.getStatus() == Message.STATUS_RECEIVED) {
- final int e = m.getEncryption();
- if (e == Message.ENCRYPTION_DECRYPTED || e == Message.ENCRYPTION_DECRYPTION_FAILED) {
- return Message.ENCRYPTION_PGP;
- } else {
- return e;
- }
- }
- }
- }
- return Message.ENCRYPTION_NONE;
- }
-
public int getNextEncryption() {
- return Math.max(this.getIntAttribute(ATTRIBUTE_NEXT_ENCRYPTION, Message.ENCRYPTION_NONE), Message.ENCRYPTION_NONE);
+ return fixAvailableEncryption(this.getIntAttribute(ATTRIBUTE_NEXT_ENCRYPTION, getDefaultEncryption()));
+ }
+
+ private int fixAvailableEncryption(int selectedEncryption) {
+ switch (selectedEncryption) {
+ case Message.ENCRYPTION_NONE:
+ return Config.supportUnencrypted() ? selectedEncryption : getDefaultEncryption();
+ case Message.ENCRYPTION_AXOLOTL:
+ return Config.supportOmemo() ? selectedEncryption : getDefaultEncryption();
+ case Message.ENCRYPTION_OTR:
+ return Config.supportOtr() ? selectedEncryption : getDefaultEncryption();
+ case Message.ENCRYPTION_PGP:
+ case Message.ENCRYPTION_DECRYPTED:
+ case Message.ENCRYPTION_DECRYPTION_FAILED:
+ return Config.supportOpenPgp() ? Message.ENCRYPTION_PGP : getDefaultEncryption();
+ default:
+ return getDefaultEncryption();
+ }
+ }
+
+ private int getDefaultEncryption() {
+ AxolotlService axolotlService = account.getAxolotlService();
+ if (Config.supportUnencrypted()) {
+ return Message.ENCRYPTION_NONE;
+ } else if (Config.supportOmemo()
+ && (axolotlService != null && axolotlService.isConversationAxolotlCapable(this) || !Config.multipleEncryptionChoices())) {
+ return Message.ENCRYPTION_AXOLOTL;
+ } else if (Config.supportOtr() && mode == MODE_SINGLE) {
+ return Message.ENCRYPTION_OTR;
+ } else if (Config.supportOpenPgp()) {
+ return Message.ENCRYPTION_PGP;
+ } else {
+ return Message.ENCRYPTION_NONE;
+ }
}
public void setNextEncryption(int encryption) {