start new conversations by long press on avatar
This commit is contained in:
parent
af724a6697
commit
3ecb7136c1
|
@ -559,6 +559,16 @@ public class MucOptions {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User findOrCreateUserByRealJid(Jid jid) {
|
||||||
|
User user = findUserByRealJid(jid);
|
||||||
|
if (user == null) {
|
||||||
|
user = new User(this, null);
|
||||||
|
user.setRealJid(jid);
|
||||||
|
user.setRole("visitor");
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
public User findUser(ReadByMarker readByMarker) {
|
public User findUser(ReadByMarker readByMarker) {
|
||||||
if (readByMarker.getRealJid() != null) {
|
if (readByMarker.getRealJid() != null) {
|
||||||
User user = findUserByRealJid(readByMarker.getRealJid().asBareJid());
|
User user = findUserByRealJid(readByMarker.getRealJid().asBareJid());
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -49,6 +50,7 @@ import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
|
import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate;
|
import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate;
|
||||||
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
|
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
|
||||||
|
import eu.siacs.conversations.ui.util.MucDetailsContextMenuHelper;
|
||||||
import eu.siacs.conversations.ui.util.MyLinkify;
|
import eu.siacs.conversations.ui.util.MyLinkify;
|
||||||
import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
|
import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
|
||||||
import eu.siacs.conversations.utils.EmojiWrapper;
|
import eu.siacs.conversations.utils.EmojiWrapper;
|
||||||
|
@ -216,6 +218,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConversationUpdate() {
|
public void onConversationUpdate() {
|
||||||
refreshUi();
|
refreshUi();
|
||||||
|
@ -427,129 +430,25 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
||||||
name = user.getName();
|
name = user.getName();
|
||||||
}
|
}
|
||||||
menu.setHeaderTitle(name);
|
menu.setHeaderTitle(name);
|
||||||
if (user.getRealJid() != null) {
|
MucDetailsContextMenuHelper.configureMucDetailsContextMenu(menu, mConversation, user, mAdvancedMode);
|
||||||
MenuItem showContactDetails = menu.findItem(R.id.action_contact_details);
|
|
||||||
MenuItem startConversation = menu.findItem(R.id.start_conversation);
|
|
||||||
MenuItem giveMembership = menu.findItem(R.id.give_membership);
|
|
||||||
MenuItem removeMembership = menu.findItem(R.id.remove_membership);
|
|
||||||
MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges);
|
|
||||||
MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges);
|
|
||||||
MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room);
|
|
||||||
MenuItem banFromConference = menu.findItem(R.id.ban_from_conference);
|
|
||||||
MenuItem invite = menu.findItem(R.id.invite);
|
|
||||||
startConversation.setVisible(true);
|
|
||||||
if (contact != null && contact.showInRoster()) {
|
|
||||||
showContactDetails.setVisible(!contact.isSelf());
|
|
||||||
}
|
|
||||||
if (user.getRole() == MucOptions.Role.NONE) {
|
|
||||||
invite.setVisible(true);
|
|
||||||
}
|
|
||||||
if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) &&
|
|
||||||
self.getAffiliation().outranks(user.getAffiliation())) {
|
|
||||||
if (mAdvancedMode) {
|
|
||||||
if (user.getAffiliation() == MucOptions.Affiliation.NONE) {
|
|
||||||
giveMembership.setVisible(true);
|
|
||||||
} else {
|
|
||||||
removeMembership.setVisible(true);
|
|
||||||
}
|
|
||||||
if (!Config.DISABLE_BAN) {
|
|
||||||
banFromConference.setVisible(true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!Config.DISABLE_BAN || mConversation.getMucOptions().membersOnly()) {
|
|
||||||
removeFromRoom.setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) {
|
|
||||||
giveAdminPrivileges.setVisible(true);
|
|
||||||
} else {
|
|
||||||
removeAdminPrivileges.setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
|
|
||||||
sendPrivateMessage.setVisible(user.getRole().ranks(MucOptions.Role.VISITOR));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
Jid jid = mSelectedUser.getRealJid();
|
if (!MucDetailsContextMenuHelper.onContextItemSelected(item, mSelectedUser, mConversation, this, this, this)) {
|
||||||
switch (item.getItemId()) {
|
|
||||||
case R.id.action_contact_details:
|
|
||||||
Contact contact = mSelectedUser.getContact();
|
|
||||||
if (contact != null) {
|
|
||||||
switchToContactDetails(contact);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case R.id.start_conversation:
|
|
||||||
startConversation(mSelectedUser);
|
|
||||||
return true;
|
|
||||||
case R.id.give_admin_privileges:
|
|
||||||
xmppConnectionService.changeAffiliationInConference(mConversation, jid, MucOptions.Affiliation.ADMIN, this);
|
|
||||||
return true;
|
|
||||||
case R.id.give_membership:
|
|
||||||
xmppConnectionService.changeAffiliationInConference(mConversation, jid, MucOptions.Affiliation.MEMBER, this);
|
|
||||||
return true;
|
|
||||||
case R.id.remove_membership:
|
|
||||||
xmppConnectionService.changeAffiliationInConference(mConversation, jid, MucOptions.Affiliation.NONE, this);
|
|
||||||
return true;
|
|
||||||
case R.id.remove_admin_privileges:
|
|
||||||
xmppConnectionService.changeAffiliationInConference(mConversation, jid, MucOptions.Affiliation.MEMBER, this);
|
|
||||||
return true;
|
|
||||||
case R.id.remove_from_room:
|
|
||||||
removeFromRoom(mSelectedUser);
|
|
||||||
return true;
|
|
||||||
case R.id.ban_from_conference:
|
|
||||||
xmppConnectionService.changeAffiliationInConference(mConversation, jid, MucOptions.Affiliation.OUTCAST, this);
|
|
||||||
if (mSelectedUser.getRole() != MucOptions.Role.NONE) {
|
|
||||||
xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, this);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case R.id.send_private_message:
|
|
||||||
if (mConversation.getMucOptions().allowPm()) {
|
|
||||||
privateMsgInMuc(mConversation, mSelectedUser.getName());
|
|
||||||
} else {
|
|
||||||
Toast.makeText(this, R.string.private_messages_are_disabled, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case R.id.invite:
|
|
||||||
xmppConnectionService.directInvite(mConversation, jid);
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return super.onContextItemSelected(item);
|
return super.onContextItemSelected(item);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeFromRoom(final User user) {
|
private void removeFromRoom(final User user) {
|
||||||
if (mConversation.getMucOptions().membersOnly()) {
|
MucDetailsContextMenuHelper.removeFromRoom(user, mConversation, this, this, this);
|
||||||
xmppConnectionService.changeAffiliationInConference(mConversation, user.getRealJid(), MucOptions.Affiliation.NONE, this);
|
|
||||||
if (user.getRole() != MucOptions.Role.NONE) {
|
|
||||||
xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, ConferenceDetailsActivity.this);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
||||||
builder.setTitle(R.string.ban_from_conference);
|
|
||||||
builder.setMessage(getString(R.string.removing_from_public_conference, user.getName()));
|
|
||||||
builder.setNegativeButton(R.string.cancel, null);
|
|
||||||
builder.setPositiveButton(R.string.ban_now, (dialog, which) -> {
|
|
||||||
xmppConnectionService.changeAffiliationInConference(mConversation, user.getRealJid(), MucOptions.Affiliation.OUTCAST, ConferenceDetailsActivity.this);
|
|
||||||
if (user.getRole() != MucOptions.Role.NONE) {
|
|
||||||
xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, ConferenceDetailsActivity.this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.create().show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void startConversation(User user) {
|
protected void startConversation(User user) {
|
||||||
if (user.getRealJid() != null) {
|
MucDetailsContextMenuHelper.startConversation(user, this.mConversation, this);
|
||||||
Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(), user.getRealJid().asBareJid(), false, true);
|
|
||||||
switchToConversation(conversation);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void saveAsBookmark() {
|
protected void saveAsBookmark() {
|
||||||
|
|
|
@ -73,6 +73,7 @@ import eu.siacs.conversations.entities.Conversational;
|
||||||
import eu.siacs.conversations.entities.DownloadableFile;
|
import eu.siacs.conversations.entities.DownloadableFile;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
import eu.siacs.conversations.entities.MucOptions;
|
import eu.siacs.conversations.entities.MucOptions;
|
||||||
|
import eu.siacs.conversations.entities.MucOptions.User;
|
||||||
import eu.siacs.conversations.entities.Presence;
|
import eu.siacs.conversations.entities.Presence;
|
||||||
import eu.siacs.conversations.entities.ReadByMarker;
|
import eu.siacs.conversations.entities.ReadByMarker;
|
||||||
import eu.siacs.conversations.entities.Transferable;
|
import eu.siacs.conversations.entities.Transferable;
|
||||||
|
@ -89,6 +90,7 @@ import eu.siacs.conversations.ui.util.DateSeparator;
|
||||||
import eu.siacs.conversations.ui.util.EditMessageActionModeCallback;
|
import eu.siacs.conversations.ui.util.EditMessageActionModeCallback;
|
||||||
import eu.siacs.conversations.ui.util.ListViewUtils;
|
import eu.siacs.conversations.ui.util.ListViewUtils;
|
||||||
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
|
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
|
||||||
|
import eu.siacs.conversations.ui.util.MucDetailsContextMenuHelper;
|
||||||
import eu.siacs.conversations.ui.util.PendingItem;
|
import eu.siacs.conversations.ui.util.PendingItem;
|
||||||
import eu.siacs.conversations.ui.util.PresenceSelector;
|
import eu.siacs.conversations.ui.util.PresenceSelector;
|
||||||
import eu.siacs.conversations.ui.util.ScrollState;
|
import eu.siacs.conversations.ui.util.ScrollState;
|
||||||
|
@ -978,21 +980,28 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
}
|
}
|
||||||
activity.switchToAccount(message.getConversation().getAccount(), fingerprint);
|
activity.switchToAccount(message.getConversation().getAccount(), fingerprint);
|
||||||
});
|
});
|
||||||
messageListAdapter.setOnContactPictureLongClicked(message -> {
|
messageListAdapter.setOnContactPictureLongClicked((v, message) -> {
|
||||||
if (message.getStatus() <= Message.STATUS_RECEIVED) {
|
if (message.getStatus() <= Message.STATUS_RECEIVED) {
|
||||||
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
||||||
final MucOptions mucOptions = conversation.getMucOptions();
|
Jid tcp = message.getTrueCounterpart();
|
||||||
if (!mucOptions.allowPm()) {
|
Jid cp = message.getCounterpart();
|
||||||
Toast.makeText(getActivity(), R.string.private_messages_are_disabled, Toast.LENGTH_SHORT).show();
|
if (cp != null && !cp.isBareJid()) {
|
||||||
return;
|
User userByRealJid = conversation.getMucOptions().findOrCreateUserByRealJid(tcp);
|
||||||
}
|
final User user = userByRealJid != null ? userByRealJid : conversation.getMucOptions().findUserByFullJid(cp);
|
||||||
Jid user = message.getCounterpart();
|
final PopupMenu popupMenu = new PopupMenu(getActivity(), v);
|
||||||
if (user != null && !user.isBareJid()) {
|
popupMenu.inflate(R.menu.muc_details_context);
|
||||||
if (mucOptions.isUserInRoom(user)) {
|
final Menu menu = popupMenu.getMenu();
|
||||||
privateMessageWith(user);
|
final boolean advancedMode = activity.getPreferences().getBoolean("advanced_muc_mode", false);
|
||||||
} else {
|
MucDetailsContextMenuHelper.configureMucDetailsContextMenu(menu, conversation, user, advancedMode);
|
||||||
Toast.makeText(getActivity(), activity.getString(R.string.user_has_left_conference, user.getResource()), Toast.LENGTH_SHORT).show();
|
final MucOptions mucOptions = ((Conversation) message.getConversation()).getMucOptions();
|
||||||
|
popupMenu.setOnMenuItemClickListener(menuItem -> {
|
||||||
|
if (menuItem.getItemId() == R.id.send_private_message) {
|
||||||
|
privateMessageWith(cp);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return MucDetailsContextMenuHelper.onContextItemSelected(menuItem, user, conversation, activity, activity, activity);
|
||||||
|
});
|
||||||
|
popupMenu.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -78,10 +78,11 @@ import eu.siacs.conversations.utils.EmojiWrapper;
|
||||||
import eu.siacs.conversations.utils.ExceptionHelper;
|
import eu.siacs.conversations.utils.ExceptionHelper;
|
||||||
import eu.siacs.conversations.utils.XmppUri;
|
import eu.siacs.conversations.utils.XmppUri;
|
||||||
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
|
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
|
||||||
|
import rocks.xmpp.addr.Jid;
|
||||||
|
|
||||||
import static eu.siacs.conversations.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
|
import static eu.siacs.conversations.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
|
||||||
|
|
||||||
public class ConversationsActivity extends XmppActivity implements OnConversationSelected, OnConversationArchived, OnConversationsListItemUpdated, OnConversationRead, XmppConnectionService.OnAccountUpdate, XmppConnectionService.OnConversationUpdate, XmppConnectionService.OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
|
public class ConversationsActivity extends XmppActivity implements OnConversationSelected, OnConversationArchived, OnConversationsListItemUpdated, OnConversationRead, XmppConnectionService.OnAccountUpdate, XmppConnectionService.OnConversationUpdate, XmppConnectionService.OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged {
|
||||||
|
|
||||||
public static final String ACTION_VIEW_CONVERSATION = "eu.siacs.conversations.action.VIEW";
|
public static final String ACTION_VIEW_CONVERSATION = "eu.siacs.conversations.action.VIEW";
|
||||||
public static final String EXTRA_CONVERSATION = "conversationUuid";
|
public static final String EXTRA_CONVERSATION = "conversationUuid";
|
||||||
|
@ -415,6 +416,30 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
openConversation(conversation, null);
|
openConversation(conversation, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void displayToast(final String msg) {
|
||||||
|
runOnUiThread(() -> Toast.makeText(ConversationsActivity.this, msg, Toast.LENGTH_SHORT).show());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAffiliationChangedSuccessful(Jid jid) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAffiliationChangeFailed(Jid jid, int resId) {
|
||||||
|
displayToast(getString(resId, jid.asBareJid().toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRoleChangedSuccessful(String nick) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRoleChangeFailed(String nick, int resId) {
|
||||||
|
displayToast(getString(resId, nick));
|
||||||
|
}
|
||||||
|
|
||||||
private void openConversation(Conversation conversation, Bundle extras) {
|
private void openConversation(Conversation conversation, Bundle extras) {
|
||||||
ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
|
ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
|
||||||
final boolean mainNeedsRefresh;
|
final boolean mainNeedsRefresh;
|
||||||
|
|
|
@ -730,7 +730,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
|
||||||
viewHolder.contact_picture.setOnLongClickListener(v -> {
|
viewHolder.contact_picture.setOnLongClickListener(v -> {
|
||||||
if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
|
if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
|
||||||
MessageAdapter.this.mOnContactPictureLongClickedListener
|
MessageAdapter.this.mOnContactPictureLongClickedListener
|
||||||
.onContactPictureLongClicked(message);
|
.onContactPictureLongClicked(v, message);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -975,7 +975,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnContactPictureLongClicked {
|
public interface OnContactPictureLongClicked {
|
||||||
void onContactPictureLongClicked(Message message);
|
void onContactPictureLongClicked(View v, Message message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ViewHolder {
|
private static class ViewHolder {
|
||||||
|
|
|
@ -0,0 +1,150 @@
|
||||||
|
package eu.siacs.conversations.ui.util;
|
||||||
|
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.Config;
|
||||||
|
import eu.siacs.conversations.entities.Contact;
|
||||||
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
|
import eu.siacs.conversations.entities.MucOptions;
|
||||||
|
import eu.siacs.conversations.entities.MucOptions.User;
|
||||||
|
import eu.siacs.conversations.R;
|
||||||
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
|
import eu.siacs.conversations.ui.XmppActivity;
|
||||||
|
import rocks.xmpp.addr.Jid;
|
||||||
|
|
||||||
|
|
||||||
|
public final class MucDetailsContextMenuHelper {
|
||||||
|
public static void configureMucDetailsContextMenu(Menu menu, Conversation conversation, User user, boolean advancedMode) {
|
||||||
|
if (user != null) {
|
||||||
|
if (user.getRealJid() != null) {
|
||||||
|
MenuItem showContactDetails = menu.findItem(R.id.action_contact_details);
|
||||||
|
MenuItem startConversation = menu.findItem(R.id.start_conversation);
|
||||||
|
MenuItem giveMembership = menu.findItem(R.id.give_membership);
|
||||||
|
MenuItem removeMembership = menu.findItem(R.id.remove_membership);
|
||||||
|
MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges);
|
||||||
|
MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges);
|
||||||
|
MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room);
|
||||||
|
MenuItem banFromConference = menu.findItem(R.id.ban_from_conference);
|
||||||
|
MenuItem invite = menu.findItem(R.id.invite);
|
||||||
|
startConversation.setVisible(true);
|
||||||
|
final Contact contact = user.getContact();
|
||||||
|
final User self = conversation.getMucOptions().getSelf();
|
||||||
|
if (contact != null && contact.showInRoster()) {
|
||||||
|
showContactDetails.setVisible(!contact.isSelf());
|
||||||
|
}
|
||||||
|
if (user.getRole() == MucOptions.Role.NONE) {
|
||||||
|
invite.setVisible(true);
|
||||||
|
}
|
||||||
|
if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) &&
|
||||||
|
self.getAffiliation().outranks(user.getAffiliation())) {
|
||||||
|
if (advancedMode) {
|
||||||
|
if (user.getAffiliation() == MucOptions.Affiliation.NONE) {
|
||||||
|
giveMembership.setVisible(true);
|
||||||
|
} else {
|
||||||
|
removeMembership.setVisible(true);
|
||||||
|
}
|
||||||
|
if (!Config.DISABLE_BAN) {
|
||||||
|
banFromConference.setVisible(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!Config.DISABLE_BAN || conversation.getMucOptions().membersOnly()) {
|
||||||
|
removeFromRoom.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) {
|
||||||
|
giveAdminPrivileges.setVisible(true);
|
||||||
|
} else {
|
||||||
|
removeAdminPrivileges.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
|
||||||
|
sendPrivateMessage.setVisible(true);
|
||||||
|
sendPrivateMessage.setEnabled(user.getRole().ranks(MucOptions.Role.VISITOR));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
|
||||||
|
sendPrivateMessage.setVisible(true);
|
||||||
|
sendPrivateMessage.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean onContextItemSelected(MenuItem item, User user, Conversation conversation, XmppActivity activity, XmppConnectionService.OnAffiliationChanged onAffiliationChanged, XmppConnectionService.OnRoleChanged onRoleChanged) {
|
||||||
|
Jid jid = user.getRealJid();
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.action_contact_details:
|
||||||
|
Contact contact = user.getContact();
|
||||||
|
if (contact != null) {
|
||||||
|
activity.switchToContactDetails(contact);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case R.id.start_conversation:
|
||||||
|
startConversation(user, conversation, activity);
|
||||||
|
return true;
|
||||||
|
case R.id.give_admin_privileges:
|
||||||
|
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.ADMIN, onAffiliationChanged);
|
||||||
|
return true;
|
||||||
|
case R.id.give_membership:
|
||||||
|
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.MEMBER, onAffiliationChanged);
|
||||||
|
return true;
|
||||||
|
case R.id.remove_membership:
|
||||||
|
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.NONE, onAffiliationChanged);
|
||||||
|
return true;
|
||||||
|
case R.id.remove_admin_privileges:
|
||||||
|
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.MEMBER, onAffiliationChanged);
|
||||||
|
return true;
|
||||||
|
case R.id.remove_from_room:
|
||||||
|
removeFromRoom(user, conversation, activity, onAffiliationChanged, onRoleChanged);
|
||||||
|
return true;
|
||||||
|
case R.id.ban_from_conference:
|
||||||
|
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.OUTCAST, onAffiliationChanged);
|
||||||
|
if (user.getRole() != MucOptions.Role.NONE) {
|
||||||
|
activity.xmppConnectionService.changeRoleInConference(conversation, user.getName(), MucOptions.Role.NONE, onRoleChanged);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case R.id.send_private_message:
|
||||||
|
if (conversation.getMucOptions().allowPm()) {
|
||||||
|
activity.privateMsgInMuc(conversation, user.getName());
|
||||||
|
} else {
|
||||||
|
Toast.makeText(activity, R.string.private_messages_are_disabled, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case R.id.invite:
|
||||||
|
activity.xmppConnectionService.directInvite(conversation, jid);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeFromRoom(final User user, Conversation conversation, XmppActivity activity, XmppConnectionService.OnAffiliationChanged onAffiliationChanged, XmppConnectionService.OnRoleChanged onRoleChanged) {
|
||||||
|
if (conversation.getMucOptions().membersOnly()) {
|
||||||
|
activity.xmppConnectionService.changeAffiliationInConference(conversation, user.getRealJid(), MucOptions.Affiliation.NONE, onAffiliationChanged);
|
||||||
|
if (user.getRole() != MucOptions.Role.NONE) {
|
||||||
|
activity.xmppConnectionService.changeRoleInConference(conversation, user.getName(), MucOptions.Role.NONE, onRoleChanged);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||||
|
builder.setTitle(R.string.ban_from_conference);
|
||||||
|
builder.setMessage(activity.getString(R.string.removing_from_public_conference, user.getName()));
|
||||||
|
builder.setNegativeButton(R.string.cancel, null);
|
||||||
|
builder.setPositiveButton(R.string.ban_now, (dialog, which) -> {
|
||||||
|
activity.xmppConnectionService.changeAffiliationInConference(conversation, user.getRealJid(), MucOptions.Affiliation.OUTCAST, onAffiliationChanged);
|
||||||
|
if (user.getRole() != MucOptions.Role.NONE) {
|
||||||
|
activity.xmppConnectionService.changeRoleInConference(conversation, user.getName(), MucOptions.Role.NONE, onRoleChanged);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.create().show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void startConversation(User user, Conversation conversation, XmppActivity activity) {
|
||||||
|
if (user.getRealJid() != null) {
|
||||||
|
Conversation newConversation = activity.xmppConnectionService.findOrCreateConversation(conversation.getAccount(), user.getRealJid().asBareJid(), false, true);
|
||||||
|
activity.switchToConversation(newConversation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue