From 1a4b1f8a2fdac08e3f81123cc117ed10a1bdfbfe Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sun, 1 Jun 2014 11:24:35 +0200 Subject: [PATCH] show dialog when no contact in a muc has pgp support --- res/values/strings.xml | 2 ++ .../conversations/entities/MucOptions.java | 18 ++++++++++++ .../ui/ConversationActivity.java | 2 +- .../ui/ConversationFragment.java | 28 +++++++++++++++---- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index fef874b0..46b0cce1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -115,6 +115,8 @@ offering… No OpenPGP Key found Conversations is unable to encrypt your messages because your contact is not announcing his or hers public key.\n\nPlease ask your contact to setup OpenPGP. + No OpenPGP Keys found + Conversations is unable to encrypt your messages because your contacts are not announcing their public key.\n\nPlease ask your contacts to setup OpenPGP. Encrypted message received. Touch to view and decrypt. Encrypted image received. Touch to view and decrypt. Image received. Touch to view diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java index c1750334..0f8e3565 100644 --- a/src/eu/siacs/conversations/entities/MucOptions.java +++ b/src/eu/siacs/conversations/entities/MucOptions.java @@ -250,4 +250,22 @@ public class MucOptions { } return primitivLongArray; } + + public boolean pgpKeysInUse() { + for(User user : getUsers()) { + if (user.getPgpKeyId()!=0) { + return true; + } + } + return false; + } + + public boolean everybodyHasKeys() { + for(User user : getUsers()) { + if (user.getPgpKeyId()==0) { + return false; + } + } + return true; + } } \ No newline at end of file diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 232d46f8..fbb08e71 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -396,7 +396,7 @@ public class ConversationActivity extends XmppActivity { final ConversationFragment fragment = (ConversationFragment) getFragmentManager() .findFragmentByTag("conversation"); if (fragment != null) { - fragment.showNoPGPKeyDialog(new OnClickListener() { + fragment.showNoPGPKeyDialog(false,new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index 3e1909d8..a2b272a1 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -701,7 +701,7 @@ public class ConversationFragment extends Fragment { }); } else { - showNoPGPKeyDialog(new DialogInterface.OnClickListener() { + showNoPGPKeyDialog(false,new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -713,16 +713,34 @@ public class ConversationFragment extends Fragment { }); } } else { - activity.encryptTextMessage(); + if (conversation.getMucOptions().pgpKeysInUse()) { + activity.encryptTextMessage(); + } else { + showNoPGPKeyDialog(true,new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + conversation.setNextEncryption(Message.ENCRYPTION_NONE); + message.setEncryption(Message.ENCRYPTION_NONE); + xmppService.sendMessage(message, null); + chatMsg.setText(""); + } + }); + } } } } - public void showNoPGPKeyDialog(DialogInterface.OnClickListener listener) { + public void showNoPGPKeyDialog(boolean plural, DialogInterface.OnClickListener listener) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setTitle(getString(R.string.no_pgp_key)); builder.setIconAttribute(android.R.attr.alertDialogIcon); - builder.setMessage(getText(R.string.contact_has_no_pgp_key)); + if (plural) { + builder.setTitle(getString(R.string.no_pgp_keys)); + builder.setMessage(getText(R.string.contacts_have_no_pgp_keys)); + } else { + builder.setTitle(getString(R.string.no_pgp_key)); + builder.setMessage(getText(R.string.contact_has_no_pgp_key)); + } builder.setNegativeButton(getString(R.string.cancel), null); builder.setPositiveButton(getString(R.string.send_unencrypted), listener);