diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-02-07 21:24:12 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-02-07 21:24:12 +0100 |
commit | b31a9daf992012be7fa839cc3d25a042c55f9c7a (patch) | |
tree | e5b9ece969c8137f9849b87af6710a7bf3208c31 /src/main/java/de/pixart | |
parent | 1b3406cdbb6c620cca975b0bc32b43b60fa246cb (diff) |
show different room settings for channels and groups
Diffstat (limited to 'src/main/java/de/pixart')
6 files changed, 156 insertions, 54 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java index c1b776b9a..3ab763632 100644 --- a/src/main/java/de/pixart/messenger/entities/MucOptions.java +++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java @@ -155,13 +155,21 @@ public class MucOptions { } public boolean canInvite() { - Field field = getRoomInfoForm().getFieldByName("muc#roomconfig_allowinvites"); - return !membersOnly() || self.getRole().ranks(Role.MODERATOR) || (field != null && "1".equals(field.getValue())); + return !membersOnly() || self.getRole().ranks(Role.MODERATOR) || allowInvites(); + } + + public boolean allowInvites() { + final Field field = getRoomInfoForm().getFieldByName("muc#roomconfig_allowinvites"); + return field != null && "1".equals(field.getValue()); } public boolean canChangeSubject() { - Field field = getRoomInfoForm().getFieldByName("muc#roominfo_changesubject"); - return self.getRole().ranks(Role.MODERATOR) || (field != null && "1".equals(field.getValue())); + return self.getRole().ranks(Role.MODERATOR) || participantsCanChangeSubject(); + } + + public boolean participantsCanChangeSubject() { + final Field field = getRoomInfoForm().getFieldByName("muc#roominfo_changesubject"); + return field != null && "1".equals(field.getValue()); } public boolean allowPm() { diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java index d7ac6f994..024e7ab43 100644 --- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java +++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java @@ -472,6 +472,8 @@ public class IqGenerator extends AbstractGenerator { options.putString("muc#roomconfig_membersonly", "1"); options.putString("muc#roomconfig_publicroom", "0"); options.putString("muc#roomconfig_whois", "anyone"); + options.putString("muc#roomconfig_changesubject", "0"); + options.putString("muc#roomconfig_allowinvites", "0"); options.putString("muc#roomconfig_enablearchiving", "1"); //prosody options.putString("mam", "1"); //ejabberd community options.putString("muc#roomconfig_mam", "1"); //ejabberd saas @@ -484,6 +486,7 @@ public class IqGenerator extends AbstractGenerator { options.putString("muc#roomconfig_membersonly", "0"); options.putString("muc#roomconfig_publicroom", "1"); options.putString("muc#roomconfig_whois", "moderators"); + options.putString("muc#roomconfig_changesubject", "0"); options.putString("muc#roomconfig_enablearchiving", "1"); //prosody options.putString("mam", "1"); //ejabberd community options.putString("muc#roomconfig_mam", "1"); //ejabberd saas diff --git a/src/main/java/de/pixart/messenger/parser/PresenceParser.java b/src/main/java/de/pixart/messenger/parser/PresenceParser.java index 8728a8a9a..0c90dd4ac 100644 --- a/src/main/java/de/pixart/messenger/parser/PresenceParser.java +++ b/src/main/java/de/pixart/messenger/parser/PresenceParser.java @@ -95,7 +95,7 @@ public class PresenceParser extends AbstractParser implements + mucOptions.getConversation().getJid().asBareJid() + "' created. pushing default configuration"); mXmppConnectionService.pushConferenceConfiguration(mucOptions.getConversation(), - IqGenerator.defaultGroupChatConfiguration(), + IqGenerator.defaultChannelConfiguration(), null); } if (mXmppConnectionService.getPgpEngine() != null) { diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 41b83a76d..3b960cdb8 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -3123,6 +3123,10 @@ public class XmppConnectionService extends Service { } public void pushConferenceConfiguration(final Conversation conversation, final Bundle options, final OnConfigurationPushed callback) { + if (options.getString("muc#roomconfig_whois", "moderators").equals("anyone")) { + conversation.setAttribute("accept_non_anonymous", true); + updateConversation(conversation); + } IqPacket request = new IqPacket(IqPacket.TYPE.GET); request.setTo(conversation.getJid().asBareJid()); request.query("http://jabber.org/protocol/muc#owner"); @@ -3132,6 +3136,7 @@ public class XmppConnectionService extends Service { if (packet.getType() == IqPacket.TYPE.RESULT) { Data data = Data.parse(packet.query().findChild("x", Namespace.DATA)); data.submit(options); + Log.d(Config.LOGTAG, data.toString()); IqPacket set = new IqPacket(IqPacket.TYPE.SET); set.setTo(conversation.getJid().asBareJid()); set.query("http://jabber.org/protocol/muc#owner").addChild(data); diff --git a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java index 76c026308..6f6ab0976 100644 --- a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java @@ -39,6 +39,7 @@ import de.pixart.messenger.ui.interfaces.OnMediaLoaded; import de.pixart.messenger.ui.util.Attachment; import de.pixart.messenger.ui.util.AvatarWorkerTask; import de.pixart.messenger.ui.util.GridManager; +import de.pixart.messenger.ui.util.MucConfiguration; import de.pixart.messenger.ui.util.MucDetailsContextMenuHelper; import de.pixart.messenger.ui.util.MyLinkify; import de.pixart.messenger.ui.util.SoftKeyboardUtils; @@ -165,53 +166,16 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers public void onClick(View v) { final MucOptions mucOptions = mConversation.getMucOptions(); AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this); - builder.setTitle(R.string.conference_options); - final String[] options; - final boolean[] values; - if (mAdvancedMode) { - options = new String[]{ - 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, (dialog, which, isChecked) -> values[which] = isChecked); + MucConfiguration configuration = MucConfiguration.get(ConferenceDetailsActivity.this, mucOptions); + builder.setTitle(configuration.title); + final boolean[] values = configuration.values; + builder.setMultiChoiceItems(configuration.names, values, (dialog, which, isChecked) -> values[which] = isChecked); builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(R.string.confirm, (dialog, which) -> { - if (!mucOptions.membersOnly() && values[0]) { - xmppConnectionService.changeAffiliationsInConference(mConversation, - MucOptions.Affiliation.NONE, - MucOptions.Affiliation.MEMBER); - } - Bundle options1 = new Bundle(); - options1.putString("muc#roomconfig_membersonly", values[0] ? "1" : "0"); - if (values.length == 2) { - options1.putString("muc#roomconfig_whois", values[1] ? "anyone" : "moderators"); - } else if (values.length == 3) { - options1.putString("muc#roomconfig_moderatedroom", values[1] ? "1" : "0"); - options1.putString("muc#roomconfig_whois", values[2] ? "anyone" : "moderators"); - } - options1.putString("muc#roomconfig_persistentroom", "1"); - final boolean whois = values.length == 2 ? values[1] : values[2]; - if (values[0] == whois) { - options1.putString("muc#roomconfig_publicroom", whois ? "0" : "1"); - } + Bundle options = configuration.toBundle(values); + options.putString("muc#roomconfig_persistentroom", "1"); xmppConnectionService.pushConferenceConfiguration(mConversation, - options1, + options, ConferenceDetailsActivity.this); }); builder.create().show(); @@ -539,15 +503,18 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers this.binding.mucYourNick.setText(EmojiWrapper.transform(mucOptions.getActualNick())); if (mucOptions.online()) { this.binding.usersWrapper.setVisibility(View.VISIBLE); - this.binding.mucSettings.setVisibility(View.VISIBLE); this.binding.mucInfoMore.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE); this.binding.jid.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE); this.binding.mucRole.setVisibility(View.VISIBLE); this.binding.mucRole.setText(getStatus(self)); - if (mucOptions.membersOnly()) { - this.binding.mucConferenceType.setText(R.string.private_conference); + if (mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER)) { + this.binding.mucSettings.setVisibility(View.VISIBLE); + this.binding.mucConferenceType.setText(MucConfiguration.describe(this, mucOptions)); + } else if (!mucOptions.isPrivateAndNonAnonymous() && mucOptions.nonanonymous()) { + this.binding.mucSettings.setVisibility(View.VISIBLE); + this.binding.mucConferenceType.setText(R.string.group_chat_will_make_your_jabber_id_public); } else { - this.binding.mucConferenceType.setText(R.string.public_conference); + this.binding.mucSettings.setVisibility(View.GONE); } if (mucOptions.mamSupport()) { this.binding.mucInfoMam.setText(R.string.server_info_available); @@ -639,7 +606,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers this.binding.notificationStatusButton.setImageResource(ic_notifications_none); } - List<User> users = mucOptions.getUsers(); + final List<User> users = mucOptions.getUsers(); Collections.sort(users, (a, b) -> { if (b.getAffiliation().outranks(a.getAffiliation())) { return 1; @@ -657,6 +624,14 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers }); this.mUserPreviewAdapter.submitList(MucOptions.sub(users, GridManager.getCurrentColumnCount(binding.users))); this.binding.invite.setVisibility(mucOptions.canInvite() ? View.VISIBLE : View.GONE); + this.binding.showUsers.setVisibility(users.size() > 0 ? View.VISIBLE : View.GONE); + this.binding.usersWrapper.setVisibility(users.size() > 0 || mucOptions.canInvite() ? View.VISIBLE : View.GONE); + if (users.size() == 0) { + this.binding.noUsersHints.setText(mucOptions.isPrivateAndNonAnonymous() ? R.string.no_users_hint_group_chat : R.string.no_users_hint_channel); + this.binding.noUsersHints.setVisibility(View.VISIBLE); + } else { + this.binding.noUsersHints.setVisibility(View.GONE); + } } public static String getStatus(Context context, User user, final boolean advanced) { diff --git a/src/main/java/de/pixart/messenger/ui/util/MucConfiguration.java b/src/main/java/de/pixart/messenger/ui/util/MucConfiguration.java new file mode 100644 index 000000000..4630a5a93 --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/util/MucConfiguration.java @@ -0,0 +1,111 @@ +package de.pixart.messenger.ui.util; + +import android.content.Context; +import android.os.Bundle; +import android.support.annotation.StringRes; + +import de.pixart.messenger.R; +import de.pixart.messenger.entities.MucOptions; + +public class MucConfiguration { + + public final @StringRes + int title; + public final String[] names; + public final boolean[] values; + public final Option[] options; + + private MucConfiguration(@StringRes int title, String[] names, boolean[] values, Option[] options) { + this.title = title; + this.names = names; + this.values = values; + this.options = options; + } + + public static MucConfiguration get(Context context, MucOptions mucOptions) { + if (mucOptions.isPrivateAndNonAnonymous()) { + String[] names = new String[]{ + context.getString(R.string.allow_participants_to_edit_subject), + context.getString(R.string.allow_participants_to_invite_others) + }; + boolean[] values = new boolean[]{ + mucOptions.participantsCanChangeSubject(), + mucOptions.allowInvites() + }; + final Option[] options = new Option[]{ + new Option("muc#roomconfig_changesubject"), + new Option("muc#roomconfig_allowinvites") + }; + return new MucConfiguration(R.string.conference_options, names, values, options); + } else { + String[] names = new String[]{ + context.getString(R.string.non_anonymous), + context.getString(R.string.allow_participants_to_edit_subject), + }; + boolean[] values = new boolean[]{ + mucOptions.nonanonymous(), + mucOptions.participantsCanChangeSubject() + }; + final Option[] options = new Option[]{ + new Option("muc#roomconfig_whois", "anyone", "moderators"), + new Option("muc#roomconfig_changesubject") + }; + return new MucConfiguration(R.string.channel_options, names, values, options); + } + } + + public static String describe(final Context context, final MucOptions mucOptions) { + final StringBuilder builder = new StringBuilder(); + if (mucOptions.isPrivateAndNonAnonymous()) { + if (mucOptions.participantsCanChangeSubject()) { + builder.append(context.getString(R.string.anyone_can_edit_subject)); + } else { + builder.append(context.getString(R.string.owners_can_edit_subject)); + } + builder.append(' '); + if (mucOptions.allowInvites()) { + builder.append(context.getString(R.string.anyone_can_invite_others)); + } else { + builder.append(context.getString(R.string.owners_can_invite_others)); + } + } else { + if (mucOptions.nonanonymous()) { + builder.append(context.getString(R.string.jabber_ids_are_visible_to_anyone)); + } else { + builder.append(context.getString(R.string.jabber_ids_are_visible_to_admins)); + } + builder.append(' '); + if (mucOptions.participantsCanChangeSubject()) { + builder.append(context.getString(R.string.anyone_can_edit_subject)); + } else { + builder.append(context.getString(R.string.admins_can_edit_subject)); + } + } + return builder.toString(); + } + + public Bundle toBundle(boolean[] values) { + Bundle bundle = new Bundle(); + for (int i = 0; i < values.length; ++i) { + final Option option = options[i]; + bundle.putString(option.name, option.values[values[i] ? 0 : 1]); + } + return bundle; + } + + private static class Option { + public final String name; + public final String[] values; + + private Option(String name) { + this.name = name; + this.values = new String[]{"1", "0"}; + } + + private Option(String name, String on, String off) { + this.name = name; + this.values = new String[]{on, off}; + } + } + +}
\ No newline at end of file |