aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-09-12 20:22:25 +0200
committerChristian Schneppe <christian@pix-art.de>2018-09-12 20:22:25 +0200
commitd02b6b9a8e3eb3d51d3e5e4c8c5d4793bf0302ef (patch)
treeb24a80844c511d9ae6908a29824847facd60b9a5 /src/main/java/de/pixart
parent777f6a383ba88a9f6b238e14f2f49c51c2dd38e6 (diff)
start new conversations by long press on avatar
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/entities/MucOptions.java10
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java119
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java43
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationsActivity.java25
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java4
-rw-r--r--src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java149
6 files changed, 219 insertions, 131 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java
index 774620707..8f9f4fd0d 100644
--- a/src/main/java/de/pixart/messenger/entities/MucOptions.java
+++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java
@@ -559,6 +559,16 @@ public class MucOptions {
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) {
if (readByMarker.getRealJid() != null) {
User user = findUserByRealJid(readByMarker.getRealJid().asBareJid());
diff --git a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java
index db70c8147..17e4e0cba 100644
--- a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java
@@ -49,6 +49,7 @@ import de.pixart.messenger.entities.MucOptions.User;
import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.services.XmppConnectionService.OnConversationUpdate;
import de.pixart.messenger.services.XmppConnectionService.OnMucRosterUpdate;
+import de.pixart.messenger.ui.util.MucDetailsContextMenuHelper;
import de.pixart.messenger.ui.util.MyLinkify;
import de.pixart.messenger.ui.util.SoftKeyboardUtils;
import de.pixart.messenger.utils.EmojiWrapper;
@@ -454,7 +455,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
final Contact contact = user.getContact();
if (contact != null && contact.showInRoster()) {
name = contact.getDisplayName();
- } else if (user.getRealJid() != null){
+ } else if (user.getRealJid() != null) {
name = user.getRealJid().asBareJid().toString();
} else {
name = user.getName();
@@ -463,129 +464,25 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
MenuItem highlightInMuc = menu.findItem(R.id.highlight_in_muc);
highlightInMuc.setVisible(true);
- if (user.getRealJid() != null) {
- 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 (user.getRole() == MucOptions.Role.NONE) {
- invite.setVisible(true);
- }
- if (jid != null && !jid.isBareJid()) {
- if (mConversation.getMucOptions().isUserInRoom(jid)) {
- sendPrivateMessage.setVisible(true);
- } else {
- sendPrivateMessage.setVisible(false);
- }
- }
- if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) &&
- self.getAffiliation().outranks(user.getAffiliation())) {
- if (mAdvancedMode) {
- if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) {
- giveAdminPrivileges.setVisible(true);
- } else {
- removeAdminPrivileges.setVisible(true);
- }
- } else {
- if (!Config.DISABLE_BAN || mConversation.getMucOptions().membersOnly()) {
- removeFromRoom.setVisible(true);
- }
- }
- if (user.getAffiliation() == MucOptions.Affiliation.NONE) {
- giveMembership.setVisible(true);
- } else {
- removeMembership.setVisible(true);
- }
- if (!Config.DISABLE_BAN) {
- banFromConference.setVisible(true);
- }
- }
- } else {
-
- sendPrivateMessage.setVisible(user.getRole().ranks(MucOptions.Role.VISITOR));
- }
-
+ MucDetailsContextMenuHelper.configureMucDetailsContextMenu(menu, mConversation, user, mAdvancedMode);
}
super.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
- Jid jid = mSelectedUser.getRealJid();
- switch (item.getItemId()) {
- case R.id.highlight_in_muc:
- highlightInMuc(mConversation, mSelectedUser.getName());
- 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.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.invite:
- xmppConnectionService.directInvite(mConversation, jid);
- return true;
- default:
- return super.onContextItemSelected(item);
+ if (!MucDetailsContextMenuHelper.onContextItemSelected(item, mSelectedUser, mConversation, this, this, this)) {
+ return super.onContextItemSelected(item);
}
+ return true;
}
private void removeFromRoom(final User user) {
- if (mConversation.getMucOptions().membersOnly()) {
- 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();
- }
+ MucDetailsContextMenuHelper.removeFromRoom(user, mConversation, this, this, this);
}
protected void startConversation(User user) {
- if (user.getRealJid() != null) {
- Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(), user.getRealJid().asBareJid(), false, true);
- switchToConversation(conversation);
- }
+ MucDetailsContextMenuHelper.startConversation(user, this.mConversation, this);
}
protected void saveAsBookmark() {
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 877696824..1ea11de90 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -88,6 +88,7 @@ import de.pixart.messenger.entities.Conversational;
import de.pixart.messenger.entities.DownloadableFile;
import de.pixart.messenger.entities.Message;
import de.pixart.messenger.entities.MucOptions;
+import de.pixart.messenger.entities.MucOptions.User;
import de.pixart.messenger.entities.Presence;
import de.pixart.messenger.entities.ReadByMarker;
import de.pixart.messenger.entities.Transferable;
@@ -103,6 +104,7 @@ import de.pixart.messenger.ui.util.ConversationMenuConfigurator;
import de.pixart.messenger.ui.util.DateSeparator;
import de.pixart.messenger.ui.util.EditMessageActionModeCallback;
import de.pixart.messenger.ui.util.ListViewUtils;
+import de.pixart.messenger.ui.util.MucDetailsContextMenuHelper;
import de.pixart.messenger.ui.util.PendingItem;
import de.pixart.messenger.ui.util.PresenceSelector;
import de.pixart.messenger.ui.util.ScrollState;
@@ -150,7 +152,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
public static final String RECENTLY_USED_QUICK_ACTION = "recently_used_quick_action";
public static final String STATE_CONVERSATION_UUID = ConversationFragment.class.getName() + ".uuid";
- public static final String STATE_SCROLL_POSITION = ConversationFragment.class.getName() + ".scroll_position";
+ public static final String STATE_SCROLL_POSITION = ConversationFragment.class.getName() + ".scroll_position";
public static final String STATE_PHOTO_URI = ConversationFragment.class.getName() + ".take_photo_uri";
public static final String STATE_VIDEO_URI = ConversationFragment.class.getName() + ".take_video_uri";
@@ -161,7 +163,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private String lastMessageUuid = null;
public Uri mPendingEditorContent = null;
private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
- private final PendingItem<String> pendingConversationsUuid = new PendingItem<>();
+ private final PendingItem<String> pendingConversationsUuid = new PendingItem<>();
private final PendingItem<Bundle> pendingExtras = new PendingItem<>();
private final PendingItem<Uri> pendingTakePhotoUri = new PendingItem<>();
private final PendingItem<Uri> pendingTakeVideoUri = new PendingItem<>();
@@ -170,7 +172,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private final PendingItem<Message> pendingMessage = new PendingItem<>();
protected MessageAdapter messageListAdapter;
private Conversation conversation;
- public FragmentConversationBinding binding;
+ public FragmentConversationBinding binding;
protected Message lastHistoryMessage = null;
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, dd. MMM yyyy", Locale.getDefault());
private Toast messageLoaderToast;
@@ -1264,21 +1266,28 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
activity.switchToAccount(message.getConversation().getAccount(), fingerprint);
});
- messageListAdapter.setOnContactPictureLongClicked(message -> {
+ messageListAdapter.setOnContactPictureLongClicked((v, message) -> {
if (message.getStatus() <= Message.STATUS_RECEIVED) {
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
- final MucOptions mucOptions = conversation.getMucOptions();
- if (!mucOptions.allowPm()) {
- Toast.makeText(getActivity(), R.string.private_messages_are_disabled, Toast.LENGTH_SHORT).show();
- return;
- }
- Jid user = message.getCounterpart();
- if (user != null && !user.isBareJid()) {
- if (mucOptions.isUserInRoom(user)) {
- privateMessageWith(user);
- } else {
- Toast.makeText(getActivity(), activity.getString(R.string.user_has_left_conference, user.getResource()), Toast.LENGTH_SHORT).show();
- }
+ Jid tcp = message.getTrueCounterpart();
+ Jid cp = message.getCounterpart();
+ if (cp != null && !cp.isBareJid()) {
+ User userByRealJid = conversation.getMucOptions().findOrCreateUserByRealJid(tcp);
+ final User user = userByRealJid != null ? userByRealJid : conversation.getMucOptions().findUserByFullJid(cp);
+ final PopupMenu popupMenu = new PopupMenu(getActivity(), v);
+ popupMenu.inflate(R.menu.muc_details_context);
+ final Menu menu = popupMenu.getMenu();
+ final boolean advancedMode = activity.getPreferences().getBoolean("advanced_muc_mode", false);
+ MucDetailsContextMenuHelper.configureMucDetailsContextMenu(menu, conversation, user, advancedMode);
+ 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 {
@@ -1864,7 +1873,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
};
if (account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) {
- if ((account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) && encryption != Message.ENCRYPTION_OTR) {
+ if ((account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) && encryption != Message.ENCRYPTION_OTR) {
conversation.setNextCounterpart(null);
callback.onPresenceSelected();
} else {
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java
index dcb15fec1..11d4cc31f 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java
@@ -92,13 +92,14 @@ import de.pixart.messenger.utils.UIHelper;
import de.pixart.messenger.utils.XmppUri;
import de.pixart.messenger.xmpp.OnUpdateBlocklist;
import de.pixart.messenger.xmpp.chatstate.ChatState;
+import rocks.xmpp.addr.Jid;
import static de.pixart.messenger.services.XmppConnectionService.FDroid;
import static de.pixart.messenger.services.XmppConnectionService.PlayStore;
import static de.pixart.messenger.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS;
-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 = "de.pixart.messenger.VIEW";
public static final String EXTRA_CONVERSATION = "conversationUuid";
@@ -489,6 +490,28 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
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) {
ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
final boolean mainNeedsRefresh;
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
index 0c42d11b4..b720375e7 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -878,7 +878,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
.setOnLongClickListener(v -> {
if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
MessageAdapter.this.mOnContactPictureLongClickedListener
- .onContactPictureLongClicked(message);
+ .onContactPictureLongClicked(v, message);
return true;
} else {
return false;
@@ -1151,7 +1151,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
}
public interface OnContactPictureLongClicked {
- void onContactPictureLongClicked(Message message);
+ void onContactPictureLongClicked(View v, Message message);
}
private static class ViewHolder {
diff --git a/src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java b/src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java
new file mode 100644
index 000000000..aa5987912
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/ui/util/MucDetailsContextMenuHelper.java
@@ -0,0 +1,149 @@
+package de.pixart.messenger.ui.util;
+
+import android.support.v7.app.AlertDialog;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.widget.Toast;
+
+import de.pixart.messenger.Config;
+import de.pixart.messenger.R;
+import de.pixart.messenger.entities.Contact;
+import de.pixart.messenger.entities.Conversation;
+import de.pixart.messenger.entities.MucOptions;
+import de.pixart.messenger.entities.MucOptions.User;
+import de.pixart.messenger.services.XmppConnectionService;
+import de.pixart.messenger.ui.XmppActivity;
+import rocks.xmpp.addr.Jid;
+
+public final class MucDetailsContextMenuHelper {
+ public static void configureMucDetailsContextMenu(Menu menu, Conversation conversation, MucOptions.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);
+ }
+ }
+} \ No newline at end of file