changed pgp decoding mechanism
This commit is contained in:
parent
3c557a1bb4
commit
d09739d166
|
@ -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:
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue