From 2506ef82df6369fef71e00e891b2a2c69330ff94 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 3 Apr 2014 17:39:57 +0200 Subject: be compatible with openkeychain api v3 --- .../conversations/ui/ConversationFragment.java | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/eu/siacs/conversations/ui') diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index 7bbef42fc..51caafbd5 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -12,6 +12,7 @@ import net.java.otr4j.session.SessionStatus; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.PgpEngine.OpenPgpException; import eu.siacs.conversations.crypto.PgpEngine.UserInputRequiredException; +import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; @@ -481,10 +482,24 @@ public class ConversationFragment extends Fragment { ConversationActivity activity = (ConversationActivity) getActivity(); final XmppConnectionService xmppService = activity.xmppConnectionService; Contact contact = message.getConversation().getContact(); + Account account = message.getConversation().getAccount(); if (activity.hasPgp()) { if (contact.getPgpKeyId() != 0) { - xmppService.sendMessage(message, null); - chatMsg.setText(""); + try { + message.setEncryptedBody(xmppService.getPgpEngine().encrypt(account, contact.getPgpKeyId(), message.getBody())); + xmppService.sendMessage(message, null); + chatMsg.setText(""); + } catch (UserInputRequiredException e) { + try { + getActivity().startIntentSenderForResult(e.getPendingIntent().getIntentSender(), + ConversationActivity.REQUEST_SEND_MESSAGE, null, 0, + 0, 0); + } catch (SendIntentException e1) { + Log.d("xmppService","failed to start intent to send message"); + } + } catch (OpenPgpException e) { + Log.d("xmppService","error encrypting with pgp: "+e.getOpenPgpError().getMessage()); + } } else { AlertDialog.Builder builder = new AlertDialog.Builder( getActivity()); @@ -616,7 +631,7 @@ public class ConversationFragment extends Fragment { } try { decrypted = activity.xmppConnectionService - .getPgpEngine().decrypt(body); + .getPgpEngine().decrypt(conversation.getAccount(),body); } catch (UserInputRequiredException e) { askForPassphraseIntent = e.getPendingIntent() .getIntentSender(); -- cgit v1.2.3