From 655565ecccc722ad72e2dbad247d67dbc1b2a911 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 22 May 2014 20:54:54 +0200 Subject: [PATCH] display pgp key id in muc details and use keys to encrypt groupchat --- src/eu/siacs/conversations/crypto/PgpEngine.java | 10 ++++++++-- .../siacs/conversations/entities/MucOptions.java | 14 ++++++++++++++ .../siacs/conversations/ui/MucDetailsActivity.java | 9 +++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/eu/siacs/conversations/crypto/PgpEngine.java b/src/eu/siacs/conversations/crypto/PgpEngine.java index 0f2aeff41..b10275f65 100644 --- a/src/eu/siacs/conversations/crypto/PgpEngine.java +++ b/src/eu/siacs/conversations/crypto/PgpEngine.java @@ -17,6 +17,7 @@ import org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; +import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.ui.UiCallback; @@ -114,10 +115,15 @@ public class PgpEngine { } public void encrypt(final Message message,final UiCallback callback) { - long[] keys = { message.getConversation().getContact().getPgpKeyId() }; + Intent params = new Intent(); params.setAction(OpenPgpApi.ACTION_ENCRYPT); - params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, keys); + if (message.getConversation().getMode() == Conversation.MODE_SINGLE) { + long[] keys = { message.getConversation().getContact().getPgpKeyId() }; + params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, keys); + } else { + params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, message.getConversation().getMucOptions().getPgpKeyIds()); + } params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, message.getConversation().getAccount().getJid()); if (message.getType() == Message.TYPE_TEXT) { diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java index ba2b9bbf2..c1750334b 100644 --- a/src/eu/siacs/conversations/entities/MucOptions.java +++ b/src/eu/siacs/conversations/entities/MucOptions.java @@ -236,4 +236,18 @@ public class MucOptions { public void flagAboutToRename() { this.aboutToRename = true; } + + public long[] getPgpKeyIds() { + List ids = new ArrayList(); + for(User user : getUsers()) { + if(user.getPgpKeyId()!=0) { + ids.add(user.getPgpKeyId()); + } + } + long[] primitivLongArray = new long[ids.size()]; + for(int i = 0; i < ids.size(); ++i) { + primitivLongArray[i] = ids.get(i); + } + return primitivLongArray; + } } \ No newline at end of file diff --git a/src/eu/siacs/conversations/ui/MucDetailsActivity.java b/src/eu/siacs/conversations/ui/MucDetailsActivity.java index bee7789f9..48cf6e81e 100644 --- a/src/eu/siacs/conversations/ui/MucDetailsActivity.java +++ b/src/eu/siacs/conversations/ui/MucDetailsActivity.java @@ -3,6 +3,8 @@ package eu.siacs.conversations.ui; import java.util.ArrayList; import java.util.List; +import org.openintents.openpgp.util.OpenPgpUtils; + import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.MucOptions; @@ -176,12 +178,15 @@ public class MucDetailsActivity extends XmppActivity { ((TextView) view.findViewById(R.id.contact_display_name)) .setText(contact.getName()); TextView role = (TextView) view.findViewById(R.id.contact_jid); - role.setText(getReadableRole(contact.getRole())); + if (contact.getPgpKeyId()==0) { + role.setText(getReadableRole(contact.getRole())); + } else { + role.setText(getReadableRole(contact.getRole())+" \u00B7 "+OpenPgpUtils.convertKeyIdToHex(contact.getPgpKeyId())); + } ImageView imageView = (ImageView) view .findViewById(R.id.contact_photo); imageView.setImageBitmap(UIHelper.getContactPicture(contact.getName(), 48,this.getApplicationContext(), false)); membersView.addView(view); - Log.d(LOGTAG,contact.getName()+" pgp id: "+contact.getPgpKeyId()); } } } else {