diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-06-15 12:44:29 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-06-19 20:02:11 +0200 |
commit | 0435f9278047dae73f1502e30c9978ce91ef9e96 (patch) | |
tree | dca655fd0e38c5f9c520a9f22e167e9cc5a256b1 /src/main/java/eu/siacs/conversations/crypto | |
parent | d12a57cbb362d6158c7b4c5f70074b3c829308ea (diff) |
delay notification until after pgp decryption
Diffstat (limited to 'src/main/java/eu/siacs/conversations/crypto')
-rw-r--r-- | src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java b/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java index 13985cca7..45dfd7d92 100644 --- a/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java +++ b/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java @@ -14,6 +14,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URL; import java.util.ArrayDeque; +import java.util.HashSet; import java.util.List; import java.util.Collections; import java.util.LinkedList; @@ -35,6 +36,7 @@ public class PgpDecryptionService { private OpenPgpApi openPgpApi = null; protected final ArrayDeque<Message> messages = new ArrayDeque(); + protected final HashSet<Message> pendingNotifications = new HashSet<>(); Message currentMessage; private PendingIntent pendingIntent; @@ -43,9 +45,16 @@ public class PgpDecryptionService { this.mXmppConnectionService = service; } - public synchronized void decrypt(final Message message) { + public synchronized boolean decrypt(final Message message, boolean notify) { messages.add(message); - continueDecryption(); + if (notify && pendingIntent == null) { + pendingNotifications.add(message); + continueDecryption(); + return false; + } else { + continueDecryption(); + return notify; + } } public synchronized void decrypt(final List<Message> list) { @@ -59,6 +68,7 @@ public class PgpDecryptionService { public synchronized void discard(List<Message> discards) { this.messages.removeAll(discards); + this.pendingNotifications.removeAll(discards); } protected synchronized void decryptNext() { @@ -120,9 +130,11 @@ public class PgpDecryptionService { mXmppConnectionService.updateMessage(message); break; case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: - messages.addFirst(message); - currentMessage = null; - storePendingIntent((PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT)); + synchronized (PgpDecryptionService.this) { + messages.addFirst(message); + currentMessage = null; + storePendingIntent((PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT)); + } break; case OpenPgpApi.RESULT_CODE_ERROR: message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED); @@ -148,9 +160,11 @@ public class PgpDecryptionService { mXmppConnectionService.updateMessage(message); break; case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: - messages.addFirst(message); - currentMessage = null; - storePendingIntent((PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT)); + synchronized (PgpDecryptionService.this) { + messages.addFirst(message); + currentMessage = null; + storePendingIntent((PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT)); + } break; case OpenPgpApi.RESULT_CODE_ERROR: message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED); @@ -162,6 +176,13 @@ public class PgpDecryptionService { mXmppConnectionService.updateMessage(message); } } + notifyIfPending(message); + } + + private synchronized void notifyIfPending(Message message) { + if (pendingNotifications.remove(message)) { + mXmppConnectionService.getNotificationService().push(message); + } } private void storePendingIntent(PendingIntent pendingIntent) { |