aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-10-15 02:09:20 +0200
committeriNPUTmice <daniel@gultsch.de>2014-10-15 02:09:20 +0200
commitd09739d1660efb6da17b47e94ca7cc667a4a1ba5 (patch)
treed5f95923a2efe00aeb17f030e00e3225adbfa9a8
parent3c557a1bb409649bfa5b07cbb4f549d92e312c32 (diff)
changed pgp decoding mechanism
Diffstat (limited to '')
-rw-r--r--src/eu/siacs/conversations/crypto/PgpEngine.java2
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java6
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java75
3 files changed, 47 insertions, 36 deletions
diff --git a/src/eu/siacs/conversations/crypto/PgpEngine.java b/src/eu/siacs/conversations/crypto/PgpEngine.java
index c70f0907..07e8e472 100644
--- a/src/eu/siacs/conversations/crypto/PgpEngine.java
+++ b/src/eu/siacs/conversations/crypto/PgpEngine.java
@@ -76,7 +76,7 @@ public class PgpEngine {
case OpenPgpApi.RESULT_CODE_ERROR:
OpenPgpError error = result
.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
- Log.d(Config.LOGTAG, error.getMessage());
+ Log.d(Config.LOGTAG,"openpgp error: "+error.getMessage());
callback.error(R.string.openpgp_error, message);
return;
default:
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 984bf7c9..40739387 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -1,17 +1,12 @@
package eu.siacs.conversations.ui;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
-import eu.siacs.conversations.entities.Downloadable;
import eu.siacs.conversations.entities.Message;
-import eu.siacs.conversations.entities.Message.ImageParams;
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
@@ -756,6 +751,7 @@ public class ConversationActivity extends XmppActivity implements
.findFragmentByTag("conversation");
if (selectedFragment != null) {
selectedFragment.hideSnackbar();
+ selectedFragment.updateMessages();
}
} else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) {
pendingImageUri = data.getData();
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index cdaa7152..75f1dac8 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -3,6 +3,7 @@ package eu.siacs.conversations.ui;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
import net.java.otr4j.session.SessionStatus;
import eu.siacs.conversations.R;
@@ -71,6 +72,10 @@ public class ConversationFragment extends Fragment {
private boolean messagesLoaded = false;
private IntentSender askForPassphraseIntent = null;
+
+
+ private ConcurrentLinkedQueue<Message> mEncryptedMessages = new ConcurrentLinkedQueue<Message>();
+ private boolean mDecryptJobRunning = false;
private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {
@@ -356,6 +361,7 @@ public class ConversationFragment extends Fragment {
@Override
public void onStop() {
+ mDecryptJobRunning = false;
super.onStop();
if (this.conversation != null) {
this.conversation.setNextMessage(mEditMessage.getText().toString());
@@ -395,34 +401,6 @@ public class ConversationFragment extends Fragment {
updateMessages();
}
- private void decryptMessage(Message message) {
- PgpEngine engine = activity.xmppConnectionService.getPgpEngine();
- if (engine != null) {
- engine.decrypt(message, new UiCallback<Message>() {
-
- @Override
- public void userInputRequried(PendingIntent pi, Message message) {
- askForPassphraseIntent = pi.getIntentSender();
- showSnackbar(R.string.openpgp_messages_found,
- R.string.decrypt, clickToDecryptListener);
- }
-
- @Override
- public void success(Message message) {
- activity.xmppConnectionService.databaseBackend
- .updateMessage(message);
- updateMessages();
- }
-
- @Override
- public void error(int error, Message message) {
- message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
- // updateMessages();
- }
- });
- }
- }
-
public void updateMessages() {
if (getView() == null) {
return;
@@ -461,10 +439,12 @@ public class ConversationFragment extends Fragment {
if ((message.getEncryption() == Message.ENCRYPTION_PGP)
&& ((message.getStatus() == Message.STATUS_RECEIVED) || (message
.getStatus() == Message.STATUS_SEND))) {
- decryptMessage(message);
- break;
+ if (!mEncryptedMessages.contains(message)) {
+ mEncryptedMessages.add(message);
+ }
}
}
+ decryptNext();
this.messageList.clear();
if (this.conversation.getMessages().size() == 0) {
messagesLoaded = false;
@@ -522,6 +502,41 @@ public class ConversationFragment extends Fragment {
}
}
+ private void decryptNext() {
+ Message next = this.mEncryptedMessages.peek();
+ PgpEngine engine = activity.xmppConnectionService.getPgpEngine();
+
+ if (next!=null && engine != null && !mDecryptJobRunning) {
+ mDecryptJobRunning = true;
+ engine.decrypt(next, new UiCallback<Message>() {
+
+ @Override
+ public void userInputRequried(PendingIntent pi, Message message) {
+ mDecryptJobRunning = false;
+ askForPassphraseIntent = pi.getIntentSender();
+ showSnackbar(R.string.openpgp_messages_found,
+ R.string.decrypt, clickToDecryptListener);
+ }
+
+ @Override
+ public void success(Message message) {
+ mDecryptJobRunning = false;
+ mEncryptedMessages.remove();
+ activity.xmppConnectionService.updateMessage(message);
+ }
+
+ @Override
+ public void error(int error, Message message) {
+ message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
+ mDecryptJobRunning = false;
+ mEncryptedMessages.remove();
+ activity.updateConversationList();
+ activity.xmppConnectionService.updateConversationUi();
+ }
+ });
+ }
+ }
+
private void messageSent() {
int size = this.messageList.size();
messagesView.setSelection(size - 1);