Skip to content

Commit

Permalink
Merge pull request #614 from guusdk/SMACK-947_MucConfigFormManager-ad…
Browse files Browse the repository at this point in the history
…min-support

Add support for room admin config to MucConfigFormManager
  • Loading branch information
Flowdalic authored Aug 27, 2024
2 parents 854f847 + 3534569 commit 9c4fcc0
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public class MucConfigFormManager {
*/
public static final String MUC_ROOMCONFIG_ROOMOWNERS = "muc#roomconfig_roomowners";

/**
* The constant String {@value}.
*
* @see <a href="http://xmpp.org/extensions/xep-0045.html#owner">XEP-0045 § 10. Owner Use Cases</a>
*/
public static final String MUC_ROOMCONFIG_ROOMADMINS = "muc#roomconfig_roomadmins";

/**
* The constant String {@value}.
*/
Expand Down Expand Up @@ -107,6 +114,7 @@ public class MucConfigFormManager {
private final MultiUserChat multiUserChat;
private final FillableForm answerForm;
private final List<Jid> owners;
private final List<Jid> admins;

/**
* Create a new MUC config form manager.
Expand Down Expand Up @@ -140,6 +148,18 @@ public class MucConfigFormManager {
// roomowners not supported, this should barely be the case
owners = null;
}

FormField roomAdminsFormField = answerForm.getDataForm().getField(MUC_ROOMCONFIG_ROOMADMINS);
if (roomAdminsFormField != null) {
// Set 'admins' to the currently configured admins
List<? extends CharSequence> adminStrings = roomAdminsFormField.getValues();
admins = new ArrayList<>(adminStrings.size());
JidUtil.jidsFrom(adminStrings, admins, null);
}
else {
// roomadmins not supported, this should barely be the case
admins = null;
}
}

/**
Expand All @@ -151,6 +171,15 @@ public boolean supportsRoomOwners() {
return owners != null;
}

/**
* Check if the room supports room admins.
* @return <code>true</code> if supported, <code>false</code> if not.
* @see #MUC_ROOMCONFIG_ROOMADMINS
*/
public boolean supportsRoomAdmins() {
return admins != null;
}

/**
* Set the owners of the room.
*
Expand All @@ -168,6 +197,23 @@ public MucConfigFormManager setRoomOwners(Collection<? extends Jid> newOwners) t
return this;
}

/**
* Set the admins of the room.
*
* @param newAdmins a collection of JIDs to become the new admins of the room.
* @return a reference to this object.
* @throws MucConfigurationNotSupportedException if the MUC service does not support this option.
* @see #MUC_ROOMCONFIG_ROOMADMINS
*/
public MucConfigFormManager setRoomAdmins(Collection<? extends Jid> newAdmins) throws MucConfigurationNotSupportedException {
if (!supportsRoomAdmins()) {
throw new MucConfigurationNotSupportedException(MUC_ROOMCONFIG_ROOMADMINS);
}
admins.clear();
admins.addAll(newAdmins);
return this;
}

/**
* Check if the room supports a members only configuration.
*
Expand Down Expand Up @@ -420,6 +466,9 @@ public void submitConfigurationForm() throws NoResponseException, XMPPErrorExcep
if (owners != null) {
answerForm.setAnswer(MUC_ROOMCONFIG_ROOMOWNERS, JidUtil.toStringList(owners));
}
if (admins != null) {
answerForm.setAnswer(MUC_ROOMCONFIG_ROOMADMINS, JidUtil.toStringList(admins));
}
multiUserChat.sendConfigurationForm(answerForm);
}
}

0 comments on commit 9c4fcc0

Please sign in to comment.