1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 03:52:06 +01:00

[muc] Add roomconfig_changesubject support to MucConfigFormManager

This commit is contained in:
Florian Schmaus 2024-06-01 11:24:43 +02:00
parent 147071ff64
commit a708387210

View file

@ -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<Jid> 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.
*