changed pgp decoding mechanism

This commit is contained in:
iNPUTmice 2014-10-15 02:09:20 +02:00
parent 3c557a1bb4
commit d09739d166
3 changed files with 47 additions and 36 deletions

View File

@ -76,7 +76,7 @@ public class PgpEngine {
case OpenPgpApi.RESULT_CODE_ERROR: case OpenPgpApi.RESULT_CODE_ERROR:
OpenPgpError error = result OpenPgpError error = result
.getParcelableExtra(OpenPgpApi.RESULT_ERROR); .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); callback.error(R.string.openpgp_error, message);
return; return;
default: default:

View File

@ -1,17 +1,12 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Downloadable;
import eu.siacs.conversations.entities.Message; 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.OnAccountUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
@ -756,6 +751,7 @@ public class ConversationActivity extends XmppActivity implements
.findFragmentByTag("conversation"); .findFragmentByTag("conversation");
if (selectedFragment != null) { if (selectedFragment != null) {
selectedFragment.hideSnackbar(); selectedFragment.hideSnackbar();
selectedFragment.updateMessages();
} }
} else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) { } else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) {
pendingImageUri = data.getData(); pendingImageUri = data.getData();

View File

@ -3,6 +3,7 @@ package eu.siacs.conversations.ui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import net.java.otr4j.session.SessionStatus; import net.java.otr4j.session.SessionStatus;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
@ -71,6 +72,10 @@ public class ConversationFragment extends Fragment {
private boolean messagesLoaded = false; private boolean messagesLoaded = false;
private IntentSender askForPassphraseIntent = null; private IntentSender askForPassphraseIntent = null;
private ConcurrentLinkedQueue<Message> mEncryptedMessages = new ConcurrentLinkedQueue<Message>();
private boolean mDecryptJobRunning = false;
private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() { private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {
@ -356,6 +361,7 @@ public class ConversationFragment extends Fragment {
@Override @Override
public void onStop() { public void onStop() {
mDecryptJobRunning = false;
super.onStop(); super.onStop();
if (this.conversation != null) { if (this.conversation != null) {
this.conversation.setNextMessage(mEditMessage.getText().toString()); this.conversation.setNextMessage(mEditMessage.getText().toString());
@ -395,34 +401,6 @@ public class ConversationFragment extends Fragment {
updateMessages(); 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() { public void updateMessages() {
if (getView() == null) { if (getView() == null) {
return; return;
@ -461,10 +439,12 @@ public class ConversationFragment extends Fragment {
if ((message.getEncryption() == Message.ENCRYPTION_PGP) if ((message.getEncryption() == Message.ENCRYPTION_PGP)
&& ((message.getStatus() == Message.STATUS_RECEIVED) || (message && ((message.getStatus() == Message.STATUS_RECEIVED) || (message
.getStatus() == Message.STATUS_SEND))) { .getStatus() == Message.STATUS_SEND))) {
decryptMessage(message); if (!mEncryptedMessages.contains(message)) {
break; mEncryptedMessages.add(message);
}
} }
} }
decryptNext();
this.messageList.clear(); this.messageList.clear();
if (this.conversation.getMessages().size() == 0) { if (this.conversation.getMessages().size() == 0) {
messagesLoaded = false; 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() { private void messageSent() {
int size = this.messageList.size(); int size = this.messageList.size();
messagesView.setSelection(size - 1); messagesView.setSelection(size - 1);