allow for private messages being started from muc details in anonymous mucs

This commit is contained in:
Daniel Gultsch 2015-07-21 13:15:59 +02:00
parent 40499be9b6
commit 1aeb5874b0
5 changed files with 47 additions and 15 deletions

View file

@ -265,14 +265,16 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
final User self = mConversation.getMucOptions().getSelf(); final User self = mConversation.getMucOptions().getSelf();
this.mSelectedUser = user; this.mSelectedUser = user;
String name; String name;
if (user.getJid() != null) {
final Contact contact = user.getContact(); final Contact contact = user.getContact();
if (contact != null) { if (contact != null) {
name = contact.getDisplayName(); name = contact.getDisplayName();
} else { } else if (user.getJid() != null){
name = user.getJid().toBareJid().toString(); name = user.getJid().toBareJid().toString();
} else {
name = user.getName();
} }
menu.setHeaderTitle(name); menu.setHeaderTitle(name);
if (user.getJid() != null) {
MenuItem showContactDetails = menu.findItem(R.id.action_contact_details); MenuItem showContactDetails = menu.findItem(R.id.action_contact_details);
MenuItem startConversation = menu.findItem(R.id.start_conversation); MenuItem startConversation = menu.findItem(R.id.start_conversation);
MenuItem giveMembership = menu.findItem(R.id.give_membership); MenuItem giveMembership = menu.findItem(R.id.give_membership);
@ -303,6 +305,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
removeAdminPrivileges.setVisible(true); removeAdminPrivileges.setVisible(true);
} }
} }
} else {
MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
sendPrivateMessage.setVisible(true);
} }
} }
@ -340,6 +345,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.OUTCAST,this); xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.OUTCAST,this);
xmppConnectionService.changeRoleInConference(mConversation,mSelectedUser.getName(), MucOptions.Role.NONE,this); xmppConnectionService.changeRoleInConference(mConversation,mSelectedUser.getName(), MucOptions.Role.NONE,this);
return true; return true;
case R.id.send_private_message:
privateMsgInMuc(mConversation,mSelectedUser.getName());
return true;
default: default:
return super.onContextItemSelected(item); return super.onContextItemSelected(item);
} }

View file

@ -51,6 +51,8 @@ import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.ui.adapter.ConversationAdapter; import eu.siacs.conversations.ui.adapter.ConversationAdapter;
import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.xmpp.OnUpdateBlocklist; import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
public class ConversationActivity extends XmppActivity public class ConversationActivity extends XmppActivity
implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast { implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
@ -62,6 +64,7 @@ public class ConversationActivity extends XmppActivity
public static final String MESSAGE = "messageUuid"; public static final String MESSAGE = "messageUuid";
public static final String TEXT = "text"; public static final String TEXT = "text";
public static final String NICK = "nick"; public static final String NICK = "nick";
public static final String PRIVATE_MESSAGE = "pm";
public static final int REQUEST_SEND_MESSAGE = 0x0201; public static final int REQUEST_SEND_MESSAGE = 0x0201;
public static final int REQUEST_DECRYPT_PGP = 0x0202; public static final int REQUEST_DECRYPT_PGP = 0x0202;
@ -464,7 +467,7 @@ public class ConversationActivity extends XmppActivity
conversation.setNextCounterpart(null); conversation.setNextCounterpart(null);
callback.onPresenceSelected(); callback.onPresenceSelected();
} else { } else {
selectPresence(conversation,callback); selectPresence(conversation, callback);
} }
} }
@ -474,7 +477,7 @@ public class ConversationActivity extends XmppActivity
if (intent.resolveActivity(getPackageManager()) != null) { if (intent.resolveActivity(getPackageManager()) != null) {
return intent; return intent;
} else { } else {
intent.setData(Uri.parse("http://play.google.com/store/apps/details?id="+packageId)); intent.setData(Uri.parse("http://play.google.com/store/apps/details?id=" + packageId));
return intent; return intent;
} }
} }
@ -995,10 +998,21 @@ public class ConversationActivity extends XmppActivity
final String downloadUuid = intent.getStringExtra(MESSAGE); final String downloadUuid = intent.getStringExtra(MESSAGE);
final String text = intent.getStringExtra(TEXT); final String text = intent.getStringExtra(TEXT);
final String nick = intent.getStringExtra(NICK); final String nick = intent.getStringExtra(NICK);
final boolean pm = intent.getBooleanExtra(PRIVATE_MESSAGE,false);
if (selectConversationByUuid(uuid)) { if (selectConversationByUuid(uuid)) {
this.mConversationFragment.reInit(getSelectedConversation()); this.mConversationFragment.reInit(getSelectedConversation());
if (nick != null) { if (nick != null) {
if (pm) {
Jid jid = getSelectedConversation().getJid();
try {
Jid next = Jid.fromParts(jid.getLocalpart(),jid.getDomainpart(),nick);
this.mConversationFragment.privateMessageWith(next);
} catch (final InvalidJidException ignored) {
//do nothing
}
} else {
this.mConversationFragment.highlightInConference(nick); this.mConversationFragment.highlightInConference(nick);
}
} else { } else {
this.mConversationFragment.appendText(text); this.mConversationFragment.appendText(text);
} }

View file

@ -384,14 +384,18 @@ public abstract class XmppActivity extends Activity {
public void switchToConversation(Conversation conversation, String text, public void switchToConversation(Conversation conversation, String text,
boolean newTask) { boolean newTask) {
switchToConversation(conversation,text,null,newTask); switchToConversation(conversation,text,null,false,newTask);
} }
public void highlightInMuc(Conversation conversation, String nick) { public void highlightInMuc(Conversation conversation, String nick) {
switchToConversation(conversation, null, nick, false); switchToConversation(conversation, null, nick, false, false);
} }
private void switchToConversation(Conversation conversation, String text, String nick, boolean newTask) { public void privateMsgInMuc(Conversation conversation, String nick) {
switchToConversation(conversation, null, nick, true, false);
}
private void switchToConversation(Conversation conversation, String text, String nick, boolean pm, boolean newTask) {
Intent viewConversationIntent = new Intent(this, Intent viewConversationIntent = new Intent(this,
ConversationActivity.class); ConversationActivity.class);
viewConversationIntent.setAction(Intent.ACTION_VIEW); viewConversationIntent.setAction(Intent.ACTION_VIEW);
@ -402,6 +406,7 @@ public abstract class XmppActivity extends Activity {
} }
if (nick != null) { if (nick != null) {
viewConversationIntent.putExtra(ConversationActivity.NICK, nick); viewConversationIntent.putExtra(ConversationActivity.NICK, nick);
viewConversationIntent.putExtra(ConversationActivity.PRIVATE_MESSAGE,pm);
} }
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION); viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
if (newTask) { if (newTask) {

View file

@ -8,6 +8,10 @@
android:id="@+id/action_contact_details" android:id="@+id/action_contact_details"
android:title="@string/action_contact_details" android:title="@string/action_contact_details"
android:visible="false"/> android:visible="false"/>
<item
android:id="@+id/send_private_message"
android:title="@string/send_private_message"
android:visible="false"/>
<item <item
android:id="@+id/give_membership" android:id="@+id/give_membership"
android:title="@string/grant_membership" android:title="@string/grant_membership"

View file

@ -497,4 +497,5 @@
<string name="choose_quick_action">Choose quick action</string> <string name="choose_quick_action">Choose quick action</string>
<string name="file_not_found_on_remote_host">File not found on remote server</string> <string name="file_not_found_on_remote_host">File not found on remote server</string>
<string name="search_for_contacts_or_groups">Search for contacts or groups</string> <string name="search_for_contacts_or_groups">Search for contacts or groups</string>
<string name="send_private_message">Send private message</string>
</resources> </resources>