display pgp key id in muc details and use keys to encrypt groupchat

This commit is contained in:
Daniel Gultsch 2014-05-22 20:54:54 +02:00
parent b605577cd9
commit 655565eccc
3 changed files with 29 additions and 4 deletions

View File

@ -17,6 +17,7 @@ import org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.ui.UiCallback; import eu.siacs.conversations.ui.UiCallback;
@ -114,10 +115,15 @@ public class PgpEngine {
} }
public void encrypt(final Message message,final UiCallback callback) { public void encrypt(final Message message,final UiCallback callback) {
long[] keys = { message.getConversation().getContact().getPgpKeyId() };
Intent params = new Intent(); Intent params = new Intent();
params.setAction(OpenPgpApi.ACTION_ENCRYPT); params.setAction(OpenPgpApi.ACTION_ENCRYPT);
if (message.getConversation().getMode() == Conversation.MODE_SINGLE) {
long[] keys = { message.getConversation().getContact().getPgpKeyId() };
params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, keys); 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()); params.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, message.getConversation().getAccount().getJid());
if (message.getType() == Message.TYPE_TEXT) { if (message.getType() == Message.TYPE_TEXT) {

View File

@ -236,4 +236,18 @@ public class MucOptions {
public void flagAboutToRename() { public void flagAboutToRename() {
this.aboutToRename = true; this.aboutToRename = true;
} }
public long[] getPgpKeyIds() {
List<Long> ids = new ArrayList<Long>();
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;
}
} }

View File

@ -3,6 +3,8 @@ package eu.siacs.conversations.ui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.openintents.openpgp.util.OpenPgpUtils;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.MucOptions;
@ -176,12 +178,15 @@ public class MucDetailsActivity extends XmppActivity {
((TextView) view.findViewById(R.id.contact_display_name)) ((TextView) view.findViewById(R.id.contact_display_name))
.setText(contact.getName()); .setText(contact.getName());
TextView role = (TextView) view.findViewById(R.id.contact_jid); TextView role = (TextView) view.findViewById(R.id.contact_jid);
if (contact.getPgpKeyId()==0) {
role.setText(getReadableRole(contact.getRole())); role.setText(getReadableRole(contact.getRole()));
} else {
role.setText(getReadableRole(contact.getRole())+" \u00B7 "+OpenPgpUtils.convertKeyIdToHex(contact.getPgpKeyId()));
}
ImageView imageView = (ImageView) view ImageView imageView = (ImageView) view
.findViewById(R.id.contact_photo); .findViewById(R.id.contact_photo);
imageView.setImageBitmap(UIHelper.getContactPicture(contact.getName(), 48,this.getApplicationContext(), false)); imageView.setImageBitmap(UIHelper.getContactPicture(contact.getName(), 48,this.getApplicationContext(), false));
membersView.addView(view); membersView.addView(view);
Log.d(LOGTAG,contact.getName()+" pgp id: "+contact.getPgpKeyId());
} }
} }
} else { } else {