added possibiltiy to set conferences as moderated (only visible in advanced mode)

This commit is contained in:
Daniel Gultsch 2015-09-13 17:13:46 +02:00
parent add4302385
commit 96575d6290
5 changed files with 62 additions and 16 deletions

View File

@ -23,7 +23,7 @@ public class MucOptions {
OUTCAST("outcast", 0, R.string.outcast), OUTCAST("outcast", 0, R.string.outcast),
NONE("none", 1, R.string.no_affiliation); NONE("none", 1, R.string.no_affiliation);
private Affiliation(String string, int rank, int resId) { Affiliation(String string, int rank, int resId) {
this.string = string; this.string = string;
this.resId = resId; this.resId = resId;
this.rank = rank; this.rank = rank;
@ -52,18 +52,20 @@ public class MucOptions {
} }
public enum Role { public enum Role {
MODERATOR("moderator", R.string.moderator), MODERATOR("moderator", R.string.moderator,3),
VISITOR("visitor", R.string.visitor), VISITOR("visitor", R.string.visitor,1),
PARTICIPANT("participant", R.string.participant), PARTICIPANT("participant", R.string.participant,2),
NONE("none", R.string.no_role); NONE("none", R.string.no_role,0);
private Role(String string, int resId) { private Role(String string, int resId, int rank) {
this.string = string; this.string = string;
this.resId = resId; this.resId = resId;
this.rank = rank;
} }
private String string; private String string;
private int resId; private int resId;
private int rank;
public int getResId() { public int getResId() {
return resId; return resId;
@ -73,6 +75,10 @@ public class MucOptions {
public String toString() { public String toString() {
return this.string; return this.string;
} }
public boolean ranks(Role role) {
return rank >= role.rank;
}
} }
public static final int ERROR_NO_ERROR = 0; public static final int ERROR_NO_ERROR = 0;
@ -233,6 +239,10 @@ public class MucOptions {
return !membersOnly() || self.getAffiliation().ranks(Affiliation.ADMIN); return !membersOnly() || self.getAffiliation().ranks(Affiliation.ADMIN);
} }
public boolean participating() {
return !online() || self.getRole().ranks(Role.PARTICIPANT);
}
public boolean membersOnly() { public boolean membersOnly() {
return hasFeature("muc_membersonly"); return hasFeature("muc_membersonly");
} }
@ -245,6 +255,10 @@ public class MucOptions {
return hasFeature("muc_persistent"); return hasFeature("muc_persistent");
} }
public boolean moderated() {
return hasFeature("muc_moderated");
}
public void deleteUser(String name) { public void deleteUser(String name) {
for (int i = 0; i < users.size(); ++i) { for (int i = 0; i < users.size(); ++i) {
if (users.get(i).getName().equals(name)) { if (users.get(i).getName().equals(name)) {

View File

@ -102,11 +102,29 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
final MucOptions mucOptions = mConversation.getMucOptions(); final MucOptions mucOptions = mConversation.getMucOptions();
AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this);
builder.setTitle(R.string.conference_options); builder.setTitle(R.string.conference_options);
String[] options = {getString(R.string.members_only), final String[] options;
getString(R.string.non_anonymous)}; final boolean[] values;
final boolean[] values = new boolean[options.length]; if (mAdvancedMode) {
values[0] = mucOptions.membersOnly(); options = new String[]{
values[1] = mucOptions.nonanonymous(); getString(R.string.members_only),
getString(R.string.moderated),
getString(R.string.non_anonymous)
};
values = new boolean[]{
mucOptions.membersOnly(),
mucOptions.moderated(),
mucOptions.nonanonymous()
};
} else {
options = new String[]{
getString(R.string.members_only),
getString(R.string.non_anonymous)
};
values = new boolean[]{
mucOptions.membersOnly(),
mucOptions.nonanonymous()
};
}
builder.setMultiChoiceItems(options,values,new DialogInterface.OnMultiChoiceClickListener() { builder.setMultiChoiceItems(options,values,new DialogInterface.OnMultiChoiceClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) { public void onClick(DialogInterface dialog, int which, boolean isChecked) {
@ -124,7 +142,12 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
} }
Bundle options = new Bundle(); Bundle options = new Bundle();
options.putString("muc#roomconfig_membersonly", values[0] ? "1" : "0"); options.putString("muc#roomconfig_membersonly", values[0] ? "1" : "0");
options.putString("muc#roomconfig_whois", values[1] ? "anyone" : "moderators"); if (values.length == 2) {
options.putString("muc#roomconfig_whois", values[1] ? "anyone" : "moderators");
} else if (values.length == 3) {
options.putString("muc#roomconfig_moderatedroom", values[1] ? "1" : "0");
options.putString("muc#roomconfig_whois", values[2] ? "anyone" : "moderators");
}
options.putString("muc#roomconfig_persistentroom", "1"); options.putString("muc#roomconfig_persistentroom", "1");
xmppConnectionService.pushConferenceConfiguration(mConversation, xmppConnectionService.pushConferenceConfiguration(mConversation,
options, options,
@ -193,6 +216,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
}); });
} }
}); });
this.mAdvancedMode = getPreferences().getBoolean("advanced_muc_mode", false);
} }
@Override @Override
@ -215,6 +239,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
case R.id.action_advanced_mode: case R.id.action_advanced_mode:
this.mAdvancedMode = !menuItem.isChecked(); this.mAdvancedMode = !menuItem.isChecked();
menuItem.setChecked(this.mAdvancedMode); menuItem.setChecked(this.mAdvancedMode);
getPreferences().edit().putBoolean("advanced_muc_mode", mAdvancedMode).commit();
invalidateOptionsMenu(); invalidateOptionsMenu();
updateView(); updateView();
break; break;

View File

@ -399,7 +399,7 @@ public class ConversationActivity extends XmppActivity
} }
if (this.getSelectedConversation().getMode() == Conversation.MODE_MULTI) { if (this.getSelectedConversation().getMode() == Conversation.MODE_MULTI) {
menuContactDetails.setVisible(false); menuContactDetails.setVisible(false);
menuAttach.setVisible(getSelectedConversation().getAccount().httpUploadAvailable()); menuAttach.setVisible(getSelectedConversation().getAccount().httpUploadAvailable() && getSelectedConversation().getMucOptions().participating());
menuInviteContact.setVisible(getSelectedConversation().getMucOptions().canInvite()); menuInviteContact.setVisible(getSelectedConversation().getMucOptions().canInvite());
menuSecure.setVisible(!Config.HIDE_PGP_IN_UI); //if pgp is hidden conferences have no choice of encryption menuSecure.setVisible(!Config.HIDE_PGP_IN_UI); //if pgp is hidden conferences have no choice of encryption
} else { } else {

View File

@ -320,11 +320,13 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
} }
public void updateChatMsgHint() { public void updateChatMsgHint() {
if (conversation.getMode() == Conversation.MODE_MULTI final boolean multi = conversation.getMode() == Conversation.MODE_MULTI;
&& conversation.getNextCounterpart() != null) { if (multi && conversation.getNextCounterpart() != null) {
this.mEditMessage.setHint(getString( this.mEditMessage.setHint(getString(
R.string.send_private_message_to, R.string.send_private_message_to,
conversation.getNextCounterpart().getResourcepart())); conversation.getNextCounterpart().getResourcepart()));
} else if (multi && !conversation.getMucOptions().participating()) {
this.mEditMessage.setHint(R.string.you_are_not_participating);
} else { } else {
switch (conversation.getNextEncryption()) { switch (conversation.getNextEncryption()) {
case Message.ENCRYPTION_NONE: case Message.ENCRYPTION_NONE:
@ -664,6 +666,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (this.conversation.getMode() == Conversation.MODE_MULTI) { if (this.conversation.getMode() == Conversation.MODE_MULTI) {
this.conversation.setNextCounterpart(null); this.conversation.setNextCounterpart(null);
} }
boolean canWrite = this.conversation.getMode() == Conversation.MODE_SINGLE || this.conversation.getMucOptions().participating();
this.mEditMessage.setEnabled(canWrite);
this.mSendButton.setEnabled(canWrite);
this.mEditMessage.setKeyboardListener(null); this.mEditMessage.setKeyboardListener(null);
this.mEditMessage.setText(""); this.mEditMessage.setText("");
this.mEditMessage.append(this.conversation.getNextMessage()); this.mEditMessage.append(this.conversation.getNextMessage());

View File

@ -440,8 +440,10 @@
<string name="public_conference">Publicly accessible conference</string> <string name="public_conference">Publicly accessible conference</string>
<string name="private_conference">Private, members only conference</string> <string name="private_conference">Private, members only conference</string>
<string name="conference_options">Conference options</string> <string name="conference_options">Conference options</string>
<string name="members_only">Private (Members only)</string> <string name="members_only">Private, members only</string>
<string name="non_anonymous">Non-anonymous</string> <string name="non_anonymous">Non-anonymous</string>
<string name="moderated">Moderated</string>
<string name="you_are_not_participating">You are not participating</string>
<string name="modified_conference_options">Modified conference options!</string> <string name="modified_conference_options">Modified conference options!</string>
<string name="could_not_modify_conference_options">Could not modify conference options</string> <string name="could_not_modify_conference_options">Could not modify conference options</string>
<string name="never">Never</string> <string name="never">Never</string>