rights managment in muc

This commit is contained in:
Daniel Gultsch 2019-02-06 23:47:29 +01:00
parent 32ef3755e2
commit b6a501d24b
3 changed files with 38 additions and 12 deletions

View File

@ -51,6 +51,7 @@ public final class MucDetailsContextMenuHelper {
public static void configureMucDetailsContextMenu(Activity activity, Menu menu, Conversation conversation, User user) { public static void configureMucDetailsContextMenu(Activity activity, Menu menu, Conversation conversation, User user) {
final MucOptions mucOptions = conversation.getMucOptions(); final MucOptions mucOptions = conversation.getMucOptions();
final boolean advancedMode = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("advanced_muc_mode", false); final boolean advancedMode = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("advanced_muc_mode", false);
final boolean isGroupChat = mucOptions.isPrivateAndNonAnonymous();
MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message); MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
if (user != null && user.getRealJid() != null) { if (user != null && user.getRealJid() != null) {
MenuItem showContactDetails = menu.findItem(R.id.action_contact_details); MenuItem showContactDetails = menu.findItem(R.id.action_contact_details);
@ -58,6 +59,8 @@ public final class MucDetailsContextMenuHelper {
MenuItem giveMembership = menu.findItem(R.id.give_membership); MenuItem giveMembership = menu.findItem(R.id.give_membership);
MenuItem removeMembership = menu.findItem(R.id.remove_membership); MenuItem removeMembership = menu.findItem(R.id.remove_membership);
MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges); MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges);
MenuItem giveOwnerPrivileges = menu.findItem(R.id.give_owner_privileges);
MenuItem removeOwnerPrivileges = menu.findItem(R.id.revoke_owner_privileges);
MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges); MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges);
MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room); MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room);
MenuItem banFromConference = menu.findItem(R.id.ban_from_conference); MenuItem banFromConference = menu.findItem(R.id.ban_from_conference);
@ -71,12 +74,11 @@ public final class MucDetailsContextMenuHelper {
if ((activity instanceof ConferenceDetailsActivity || activity instanceof MucUsersActivity) && user.getRole() == MucOptions.Role.NONE) { if ((activity instanceof ConferenceDetailsActivity || activity instanceof MucUsersActivity) && user.getRole() == MucOptions.Role.NONE) {
invite.setVisible(true); invite.setVisible(true);
} }
if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) && if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) && self.getAffiliation().outranks(user.getAffiliation())) {
self.getAffiliation().outranks(user.getAffiliation())) {
if (advancedMode) { if (advancedMode) {
if (user.getAffiliation() == MucOptions.Affiliation.NONE) { if (!user.getAffiliation().ranks(MucOptions.Affiliation.MEMBER)) {
giveMembership.setVisible(true); giveMembership.setVisible(true);
} else { } else if (user.getAffiliation() == MucOptions.Affiliation.MEMBER) {
removeMembership.setVisible(true); removeMembership.setVisible(true);
} }
if (!Config.DISABLE_BAN) { if (!Config.DISABLE_BAN) {
@ -87,13 +89,24 @@ public final class MucDetailsContextMenuHelper {
removeFromRoom.setVisible(true); removeFromRoom.setVisible(true);
} }
} }
if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) { }
if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
if (isGroupChat || advancedMode || user.getAffiliation() == MucOptions.Affiliation.OWNER) {
if (!user.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
giveOwnerPrivileges.setVisible(true);
} else if (user.getAffiliation() == MucOptions.Affiliation.OWNER){
removeOwnerPrivileges.setVisible(true);
}
}
if (!isGroupChat || advancedMode || user.getAffiliation() == MucOptions.Affiliation.ADMIN) {
if (!user.getAffiliation().ranks(MucOptions.Affiliation.ADMIN)) {
giveAdminPrivileges.setVisible(true); giveAdminPrivileges.setVisible(true);
} else { } else if (user.getAffiliation() == MucOptions.Affiliation.ADMIN) {
removeAdminPrivileges.setVisible(true); removeAdminPrivileges.setVisible(true);
} }
} }
sendPrivateMessage.setVisible(!mucOptions.isPrivateAndNonAnonymous() && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR)); }
sendPrivateMessage.setVisible(!isGroupChat && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR));
} else { } else {
sendPrivateMessage.setVisible(true); sendPrivateMessage.setVisible(true);
sendPrivateMessage.setEnabled(user != null && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR)); sendPrivateMessage.setEnabled(user != null && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR));
@ -124,10 +137,14 @@ public final class MucDetailsContextMenuHelper {
case R.id.give_membership: case R.id.give_membership:
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.MEMBER, onAffiliationChanged); activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.MEMBER, onAffiliationChanged);
return true; return true;
case R.id.give_owner_privileges:
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.OWNER, onAffiliationChanged);
return true;
case R.id.remove_membership: case R.id.remove_membership:
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.NONE, onAffiliationChanged); activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.NONE, onAffiliationChanged);
return true; return true;
case R.id.remove_admin_privileges: case R.id.remove_admin_privileges:
case R.id.revoke_owner_privileges:
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.MEMBER, onAffiliationChanged); activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.MEMBER, onAffiliationChanged);
return true; return true;
case R.id.remove_from_room: case R.id.remove_from_room:

View File

@ -20,6 +20,10 @@
android:id="@+id/give_membership" android:id="@+id/give_membership"
android:title="@string/grant_membership" android:title="@string/grant_membership"
android:visible="false"/> android:visible="false"/>
<item
android:id="@+id/remove_membership"
android:title="@string/remove_membership"
android:visible="false"/>
<item <item
android:id="@+id/give_admin_privileges" android:id="@+id/give_admin_privileges"
android:title="@string/grant_admin_privileges" android:title="@string/grant_admin_privileges"
@ -28,10 +32,13 @@
android:id="@+id/remove_admin_privileges" android:id="@+id/remove_admin_privileges"
android:title="@string/remove_admin_privileges" android:title="@string/remove_admin_privileges"
android:visible="false"/> android:visible="false"/>
<item <item
android:id="@+id/remove_membership" android:id="@+id/give_owner_privileges"
android:title="@string/remove_membership" android:title="@string/grant_owner_privileges"
android:visible="false"/>
<item
android:id="@+id/revoke_owner_privileges"
android:title="@string/remove_owner_privileges"
android:visible="false"/> android:visible="false"/>
<item <item
android:id="@+id/ban_from_conference" android:id="@+id/ban_from_conference"

View File

@ -368,6 +368,8 @@
<string name="remove_membership">Revoke membership</string> <string name="remove_membership">Revoke membership</string>
<string name="grant_admin_privileges">Grant admin privileges</string> <string name="grant_admin_privileges">Grant admin privileges</string>
<string name="remove_admin_privileges">Revoke admin privileges</string> <string name="remove_admin_privileges">Revoke admin privileges</string>
<string name="grant_owner_privileges">Grant owner privileges</string>
<string name="remove_owner_privileges">Revoke owner privileges</string>
<string name="remove_from_room">Remove from group chat</string> <string name="remove_from_room">Remove from group chat</string>
<string name="could_not_change_affiliation">Could not change affiliation of %s</string> <string name="could_not_change_affiliation">Could not change affiliation of %s</string>
<string name="ban_from_conference">Ban from group chat</string> <string name="ban_from_conference">Ban from group chat</string>