context menu for muc participants + refactor trueCounterpart to use Jid class

This commit is contained in:
iNPUTmice 2014-11-17 20:02:46 +01:00
parent 283d5058e5
commit f41c3eee04
8 changed files with 106 additions and 39 deletions

View File

@ -49,7 +49,7 @@ public class Message extends AbstractEntity {
public boolean markable = false; public boolean markable = false;
protected String conversationUuid; protected String conversationUuid;
protected Jid counterpart; protected Jid counterpart;
protected String trueCounterpart; protected Jid trueCounterpart;
protected String body; protected String body;
protected String encryptedBody; protected String encryptedBody;
protected long timeSent; protected long timeSent;
@ -81,7 +81,7 @@ public class Message extends AbstractEntity {
} }
public Message(final String uuid, final String conversationUUid, final Jid counterpart, public Message(final String uuid, final String conversationUUid, final Jid counterpart,
final String trueCounterpart, final String body, final long timeSent, final Jid trueCounterpart, final String body, final long timeSent,
final int encryption, final int status, final int type, final String remoteMsgId, final String relativeFilePath) { final int encryption, final int status, final int type, final String remoteMsgId, final String relativeFilePath) {
this.uuid = uuid; this.uuid = uuid;
this.conversationUuid = conversationUUid; this.conversationUuid = conversationUUid;
@ -108,10 +108,21 @@ public class Message extends AbstractEntity {
} catch (InvalidJidException e) { } catch (InvalidJidException e) {
jid = null; jid = null;
} }
Jid trueCounterpart;
try {
String value = cursor.getString(cursor.getColumnIndex(TRUE_COUNTERPART));
if (value!=null) {
trueCounterpart = Jid.fromString(value);
} else {
trueCounterpart = null;
}
} catch (InvalidJidException e) {
trueCounterpart = null;
}
return new Message(cursor.getString(cursor.getColumnIndex(UUID)), return new Message(cursor.getString(cursor.getColumnIndex(UUID)),
cursor.getString(cursor.getColumnIndex(CONVERSATION)), cursor.getString(cursor.getColumnIndex(CONVERSATION)),
jid, jid,
cursor.getString(cursor.getColumnIndex(TRUE_COUNTERPART)), trueCounterpart,
cursor.getString(cursor.getColumnIndex(BODY)), cursor.getString(cursor.getColumnIndex(BODY)),
cursor.getLong(cursor.getColumnIndex(TIME_SENT)), cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
cursor.getInt(cursor.getColumnIndex(ENCRYPTION)), cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
@ -138,7 +149,11 @@ public class Message extends AbstractEntity {
} else { } else {
values.put(COUNTERPART, counterpart.toString()); values.put(COUNTERPART, counterpart.toString());
} }
values.put(TRUE_COUNTERPART, trueCounterpart); if (trueCounterpart == null ) {
values.putNull(TRUE_COUNTERPART);
} else {
values.put(TRUE_COUNTERPART, trueCounterpart.toString());
}
values.put(BODY, body); values.put(BODY, body);
values.put(TIME_SENT, timeSent); values.put(TIME_SENT, timeSent);
values.put(ENCRYPTION, encryption); values.put(ENCRYPTION, encryption);
@ -258,7 +273,7 @@ public class Message extends AbstractEntity {
this.type = type; this.type = type;
} }
public void setTrueCounterpart(String trueCounterpart) { public void setTrueCounterpart(Jid trueCounterpart) {
this.trueCounterpart = trueCounterpart; this.trueCounterpart = trueCounterpart;
} }

View File

@ -43,7 +43,7 @@ public class MucOptions {
private int role; private int role;
private int affiliation; private int affiliation;
private String name; private String name;
private String jid; private Jid jid;
private long pgpKeyId = 0; private long pgpKeyId = 0;
public String getName() { public String getName() {
@ -54,11 +54,11 @@ public class MucOptions {
this.name = user; this.name = user;
} }
public void setJid(String jid) { public void setJid(Jid jid) {
this.jid = jid; this.jid = jid;
} }
public String getJid() { public Jid getJid() {
return this.jid; return this.jid;
} }
@ -165,7 +165,7 @@ public class MucOptions {
user.setName(name); user.setName(name);
user.setAffiliation(item.getAttribute("affiliation")); user.setAffiliation(item.getAttribute("affiliation"));
user.setRole(item.getAttribute("role")); user.setRole(item.getAttribute("role"));
user.setJid(item.getAttribute("jid")); user.setJid(item.getAttributeAsJid("jid"));
user.setName(name); user.setName(name);
if (name.equals(this.joinnick)) { if (name.equals(this.joinnick)) {
this.isOnline = true; this.isOnline = true;
@ -346,7 +346,7 @@ public class MucOptions {
} }
} }
public String getTrueCounterpart(String counterpart) { public Jid getTrueCounterpart(String counterpart) {
for (User user : this.getUsers()) { for (User user : this.getUsers()) {
if (user.getName().equals(counterpart)) { if (user.getName().equals(counterpart)) {
return user.getJid(); return user.getJid();

View File

@ -15,12 +15,11 @@ public class Roster {
this.account = account; this.account = account;
} }
public Contact getContactFromRoster(String jid) { public Contact getContactFromRoster(Jid jid) {
if (jid == null) { if (jid == null) {
return null; return null;
} }
String cleanJid = jid.split("/", 2)[0]; Contact contact = contacts.get(jid.toBareJid().toString());
Contact contact = contacts.get(cleanJid);
if (contact != null && contact.showInRoster()) { if (contact != null && contact.showInRoster()) {
return contact; return contact;
} else { } else {

View File

@ -1971,7 +1971,7 @@ public class XmppConnectionService extends Service {
return this.mJingleConnectionManager; return this.mJingleConnectionManager;
} }
public List<Contact> findContacts(String jid) { public List<Contact> findContacts(Jid jid) {
ArrayList<Contact> contacts = new ArrayList<>(); ArrayList<Contact> contacts = new ArrayList<>();
for (Account account : getAccounts()) { for (Account account : getAccounts()) {
if (!account.isOptionSet(Account.OPTION_DISABLED)) { if (!account.isOptionSet(Account.OPTION_DISABLED)) {

View File

@ -7,6 +7,7 @@ import android.content.IntentSender.SendIntentException;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.ContextMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -35,12 +36,12 @@ import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnRenameListener { public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnRenameListener {
public static final String ACTION_VIEW_MUC = "view_muc"; public static final String ACTION_VIEW_MUC = "view_muc";
private Conversation conversation; private Conversation mConversation;
private OnClickListener inviteListener = new OnClickListener() { private OnClickListener inviteListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
inviteToConversation(conversation); inviteToConversation(mConversation);
} }
}; };
private TextView mYourNick; private TextView mYourNick;
@ -54,6 +55,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
private Button mInviteButton; private Button mInviteButton;
private String uuid = null; private String uuid = null;
private List<User> users = new ArrayList<>(); private List<User> users = new ArrayList<>();
private User mSelectedUser = null;
@Override @Override
public void onRename(final boolean success) { public void onRename(final boolean success) {
@ -107,12 +109,12 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
@Override @Override
public void onClick(View v) { public void onClick(View v) {
quickEdit(conversation.getMucOptions().getActualNick(), quickEdit(mConversation.getMucOptions().getActualNick(),
new OnValueEdited() { new OnValueEdited() {
@Override @Override
public void onValueEdited(String value) { public void onValueEdited(String value) {
xmppConnectionService.renameInMuc(conversation, xmppConnectionService.renameInMuc(mConversation,
value); value);
} }
}); });
@ -127,16 +129,16 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
finish(); finish();
break; break;
case R.id.action_edit_subject: case R.id.action_edit_subject:
if (conversation != null) { if (mConversation != null) {
quickEdit(conversation.getName(), new OnValueEdited() { quickEdit(mConversation.getName(), new OnValueEdited() {
@Override @Override
public void onValueEdited(String value) { public void onValueEdited(String value) {
MessagePacket packet = xmppConnectionService MessagePacket packet = xmppConnectionService
.getMessageGenerator().conferenceSubject( .getMessageGenerator().conferenceSubject(
conversation, value); mConversation, value);
xmppConnectionService.sendMessagePacket( xmppConnectionService.sendMessagePacket(
conversation.getAccount(), packet); mConversation.getAccount(), packet);
} }
}); });
} }
@ -160,8 +162,8 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
@Override @Override
protected String getShareableUri() { protected String getShareableUri() {
if (conversation != null) { if (mConversation != null) {
return "xmpp:" + conversation.getContactJid().toBareJid().toString() + "?join"; return "xmpp:" + mConversation.getContactJid().toBareJid().toString() + "?join";
} else { } else {
return ""; return "";
} }
@ -173,32 +175,75 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
return true; return true;
} }
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
Object tag = v.getTag();
if (tag instanceof User) {
getMenuInflater().inflate(R.menu.muc_details_context,menu);
final User user = (User) tag;
this.mSelectedUser = user;
String name;
final Contact contact = user.getContact();
if (contact != null) {
name = contact.getDisplayName();
} else if (user.getJid() != null) {
name = user.getJid().toBareJid().toString();
} else {
name = user.getName();
}
menu.setHeaderTitle(name);
MenuItem startConversation = menu.findItem(R.id.start_conversation);
if (user.getJid() == null) {
startConversation.setVisible(false);
}
}
super.onCreateContextMenu(menu,v,menuInfo);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.start_conversation:
startConversation(mSelectedUser);
return true;
default:
return super.onContextItemSelected(item);
}
}
protected void startConversation(User user) {
if (user.getJid() != null) {
Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(),user.getJid(),false);
switchToConversation(conversation);
}
}
@Override @Override
void onBackendConnected() { void onBackendConnected() {
if (getIntent().getAction().equals(ACTION_VIEW_MUC)) { if (getIntent().getAction().equals(ACTION_VIEW_MUC)) {
this.uuid = getIntent().getExtras().getString("uuid"); this.uuid = getIntent().getExtras().getString("uuid");
} }
if (uuid != null) { if (uuid != null) {
this.conversation = xmppConnectionService this.mConversation = xmppConnectionService
.findConversationByUuid(uuid); .findConversationByUuid(uuid);
if (this.conversation != null) { if (this.mConversation != null) {
populateView(); populateView();
} }
} }
} }
private void populateView() { private void populateView() {
mAccountJid.setText(getString(R.string.using_account, conversation mAccountJid.setText(getString(R.string.using_account, mConversation
.getAccount().getJid().toBareJid())); .getAccount().getJid().toBareJid()));
mYourPhoto.setImageBitmap(avatarService().get( mYourPhoto.setImageBitmap(avatarService().get(
conversation.getAccount(), getPixel(48))); mConversation.getAccount(), getPixel(48)));
setTitle(conversation.getName()); setTitle(mConversation.getName());
mFullJid.setText(conversation.getContactJid().toBareJid().toString()); mFullJid.setText(mConversation.getContactJid().toBareJid().toString());
mYourNick.setText(conversation.getMucOptions().getActualNick()); mYourNick.setText(mConversation.getMucOptions().getActualNick());
mRoleAffiliaton = (TextView) findViewById(R.id.muc_role); mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
if (conversation.getMucOptions().online()) { if (mConversation.getMucOptions().online()) {
mMoreDetails.setVisibility(View.VISIBLE); mMoreDetails.setVisibility(View.VISIBLE);
User self = conversation.getMucOptions().getSelf(); User self = mConversation.getMucOptions().getSelf();
switch (self.getAffiliation()) { switch (self.getAffiliation()) {
case User.AFFILIATION_ADMIN: case User.AFFILIATION_ADMIN:
mRoleAffiliaton.setText(getReadableRole(self.getRole()) + " (" mRoleAffiliaton.setText(getReadableRole(self.getRole()) + " ("
@ -214,19 +259,21 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
} }
} }
this.users.clear(); this.users.clear();
this.users.addAll(conversation.getMucOptions().getUsers()); this.users.addAll(mConversation.getMucOptions().getUsers());
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
membersView.removeAllViews(); membersView.removeAllViews();
for (final User user : conversation.getMucOptions().getUsers()) { for (final User user : mConversation.getMucOptions().getUsers()) {
View view = inflater.inflate(R.layout.contact, membersView, View view = inflater.inflate(R.layout.contact, membersView,
false); false);
this.setListItemBackgroundOnView(view); this.setListItemBackgroundOnView(view);
view.setOnClickListener(new OnClickListener() { view.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
highlightInMuc(conversation, user.getName()); highlightInMuc(mConversation, user.getName());
} }
}); });
registerForContextMenu(view);
view.setTag(user);
TextView name = (TextView) view TextView name = (TextView) view
.findViewById(R.id.contact_display_name); .findViewById(R.id.contact_display_name);
TextView key = (TextView) view.findViewById(R.id.key); TextView key = (TextView) view.findViewById(R.id.key);
@ -274,7 +321,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
PgpEngine pgp = xmppConnectionService.getPgpEngine(); PgpEngine pgp = xmppConnectionService.getPgpEngine();
if (pgp != null) { if (pgp != null) {
PendingIntent intent = pgp.getIntentForKey( PendingIntent intent = pgp.getIntentForKey(
conversation.getAccount(), user.getPgpKeyId()); mConversation.getAccount(), user.getPgpKeyId());
if (intent != null) { if (intent != null) {
try { try {
startIntentSenderForResult(intent.getIntentSender(), 0, startIntentSenderForResult(intent.getIntentSender(), 0,

View File

@ -494,6 +494,9 @@ public class ConversationFragment extends Fragment {
} }
public void reInit(Conversation conversation) { public void reInit(Conversation conversation) {
if (conversation == null) {
return;
}
if (this.conversation != null) { if (this.conversation != null) {
this.conversation.setNextMessage(mEditMessage.getText().toString()); this.conversation.setNextMessage(mEditMessage.getText().toString());
} }

View File

@ -622,7 +622,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
private boolean handleJid(Invite invite) { private boolean handleJid(Invite invite) {
List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid().toString()); List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid());
if (contacts.size() == 0) { if (contacts.size() == 0) {
showCreateContactDialog(invite.getJid().toString(),invite.getFingerprint()); showCreateContactDialog(invite.getJid().toString(),invite.getFingerprint());
return false; return false;

View File

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/start_conversation"
android:title="@string/start_conversation"
/>
</menu> </menu>