From 3534569a8ddc8f223d3c190888c4e40bccc475b5 Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Tue, 13 Aug 2024 15:48:02 +0200 Subject: [PATCH] Add support for room admin config to MucConfigFormManager fixes SMACK-947 --- .../smackx/muc/MucConfigFormManager.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MucConfigFormManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MucConfigFormManager.java index f46124482..1c989c8bc 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MucConfigFormManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MucConfigFormManager.java @@ -62,6 +62,13 @@ public class MucConfigFormManager { */ public static final String MUC_ROOMCONFIG_ROOMOWNERS = "muc#roomconfig_roomowners"; + /** + * The constant String {@value}. + * + * @see XEP-0045 ยง 10. Owner Use Cases + */ + public static final String MUC_ROOMCONFIG_ROOMADMINS = "muc#roomconfig_roomadmins"; + /** * The constant String {@value}. */ @@ -107,6 +114,7 @@ public class MucConfigFormManager { private final MultiUserChat multiUserChat; private final FillableForm answerForm; private final List owners; + private final List admins; /** * Create a new MUC config form manager. @@ -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 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; + } } /** @@ -151,6 +171,15 @@ public class MucConfigFormManager { return owners != null; } + /** + * Check if the room supports room admins. + * @return true if supported, false if not. + * @see #MUC_ROOMCONFIG_ROOMADMINS + */ + public boolean supportsRoomAdmins() { + return admins != null; + } + /** * Set the owners of the room. * @@ -168,6 +197,23 @@ public class MucConfigFormManager { 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 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. * @@ -420,6 +466,9 @@ public class MucConfigFormManager { 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); } }