From a7083872101454f6dde10d6d69e546be3115ad9b Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 1 Jun 2024 11:24:43 +0200 Subject: [PATCH] [muc] Add roomconfig_changesubject support to MucConfigFormManager --- .../smackx/muc/MucConfigFormManager.java | 33 +++++++++++++++++++ 1 file changed, 33 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 9f2778e9c..f46124482 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 @@ -25,6 +25,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smackx.muc.MultiUserChatException.MucConfigurationNotSupportedException; +import org.jivesoftware.smackx.xdata.BooleanFormField; import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.form.FillableForm; import org.jivesoftware.smackx.xdata.form.FilledForm; @@ -98,6 +99,11 @@ public class MucConfigFormManager { */ public static final String MUC_ROOMCONFIG_ENABLE_PUBLIC_LOGGING = "muc#roomconfig_enablelogging"; + /** + * The constant String {@value}. + */ + public static final String MUC_ROOMCONFIG_CHANGE_SUBJECT = "muc#roomconfig_changesubject"; + private final MultiUserChat multiUserChat; private final FillableForm answerForm; private final List owners; @@ -374,6 +380,33 @@ public class MucConfigFormManager { return this; } + public boolean supportsChangeSubjectByOccupant() { + return answerForm.hasField(MUC_ROOMCONFIG_CHANGE_SUBJECT); + } + + public boolean occupantsAreAllowedToChangeSubject() throws MucConfigurationNotSupportedException { + if (!supportsChangeSubjectByOccupant()) { + throw new MucConfigurationNotSupportedException(MUC_ROOMCONFIG_CHANGE_SUBJECT); + } + return answerForm.getField(MUC_ROOMCONFIG_CHANGE_SUBJECT).ifPossibleAsOrThrow(BooleanFormField.class).getValueAsBoolean(); + } + + public MucConfigFormManager setChangeSubjectByOccupant(boolean enabled) throws MucConfigurationNotSupportedException { + if (!supportsChangeSubjectByOccupant()) { + throw new MucConfigurationNotSupportedException(MUC_ROOMCONFIG_CHANGE_SUBJECT); + } + answerForm.setAnswer(MUC_ROOMCONFIG_CHANGE_SUBJECT, enabled); + return this; + } + + public MucConfigFormManager allowOccupantsToChangeSubject() throws MucConfigurationNotSupportedException { + return setChangeSubjectByOccupant(true); + } + + public MucConfigFormManager disallowOccupantsToChangeSubject() throws MucConfigurationNotSupportedException { + return setChangeSubjectByOccupant(false); + } + /** * Submit the configuration as {@link FilledForm} to the room. *