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

Merge pull request #616 from guusdk/SMACK-950_MUC-destroy-password

[muc] Add support for 'password' in room destroy
This commit is contained in:
Florian Schmaus 2024-08-27 09:52:04 +00:00 committed by GitHub
commit 6c7e88f3a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 51 additions and 8 deletions

View file

@ -82,7 +82,7 @@ public class DefaultUserStatusListener implements UserStatusListener {
} }
@Override @Override
public void roomDestroyed(MultiUserChat alternateMUC, String reason) { public void roomDestroyed(MultiUserChat alternateMUC, String password, String reason) {
} }
} }

View file

@ -290,7 +290,7 @@ public class MultiUserChat {
} }
for (UserStatusListener listener : userStatusListeners) { for (UserStatusListener listener : userStatusListeners) {
listener.roomDestroyed(alternateMuc, destroy.getReason()); listener.roomDestroyed(alternateMuc, destroy.getPassword(), destroy.getReason());
} }
} }
@ -965,12 +965,32 @@ public class MultiUserChat {
* @throws InterruptedException if the calling thread was interrupted. * @throws InterruptedException if the calling thread was interrupted.
*/ */
public void destroy(String reason, EntityBareJid alternateJID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { public void destroy(String reason, EntityBareJid alternateJID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
destroy(reason, alternateJID, null);
}
/**
* Sends a request to the server to destroy the room. The sender of the request
* should be the room's owner. If the sender of the destroy request is not the room's owner
* then the server will answer a "Forbidden" error (403).
*
* @param reason an optional reason for the room destruction.
* @param alternateJID an optional JID of an alternate location.
* @param password an optional password for the alternate location
* @throws XMPPErrorException if an error occurs while trying to destroy the room.
* An error can occur which will be wrapped by an XMPPException --
* XMPP error code 403. The error code can be used to present more
* appropriate error messages to end-users.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
public void destroy(String reason, EntityBareJid alternateJID, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCOwner iq = new MUCOwner(); MUCOwner iq = new MUCOwner();
iq.setTo(room); iq.setTo(room);
iq.setType(IQ.Type.set); iq.setType(IQ.Type.set);
// Create the reason for the room destruction // Create the reason for the room destruction
Destroy destroy = new Destroy(alternateJID, reason); Destroy destroy = new Destroy(alternateJID, password, reason);
iq.setDestroy(destroy); iq.setDestroy(destroy);
try { try {

View file

@ -28,7 +28,7 @@ import org.jxmpp.jid.Jid;
* banned, or granted admin permissions or the room is destroyed. * banned, or granted admin permissions or the room is destroyed.
* <p> * <p>
* Note that the methods {@link #kicked(Jid, String)}, {@link #banned(Jid, String)} and * Note that the methods {@link #kicked(Jid, String)}, {@link #banned(Jid, String)} and
* {@link #roomDestroyed(MultiUserChat, String)} will be called before the generic {@link #removed(MUCUser, Presence)} * {@link #roomDestroyed(MultiUserChat, String, String)} will be called before the generic {@link #removed(MUCUser, Presence)}
* callback will be invoked. The generic {@link #removed(MUCUser, Presence)} callback will be invoked every time the user * callback will be invoked. The generic {@link #removed(MUCUser, Presence)} callback will be invoked every time the user
* was removed from the MUC involuntarily. It is hence the recommended callback to listen for and act upon. * was removed from the MUC involuntarily. It is hence the recommended callback to listen for and act upon.
* </p> * </p>
@ -161,10 +161,11 @@ public interface UserStatusListener {
* Called when the room is destroyed. * Called when the room is destroyed.
* *
* @param alternateMUC an alternate MultiUserChat, may be null. * @param alternateMUC an alternate MultiUserChat, may be null.
* @param password a password for the alternative MultiUserChat, may be null.
* @param reason the reason why the room was closed, may be null. * @param reason the reason why the room was closed, may be null.
* @see #removed(MUCUser, Presence) * @see #removed(MUCUser, Presence)
*/ */
default void roomDestroyed(MultiUserChat alternateMUC, String reason) { default void roomDestroyed(MultiUserChat alternateMUC, String password, String reason) {
} }
} }

View file

@ -40,14 +40,22 @@ public class Destroy implements NamedElement, Serializable {
private final String reason; private final String reason;
private final EntityBareJid jid; private final EntityBareJid jid;
private final String password;
public Destroy(Destroy other) { public Destroy(Destroy other) {
this(other.jid, other.reason); this(other.jid, other.password, other.reason);
} }
public Destroy(EntityBareJid alternativeJid, String reason) { public Destroy(EntityBareJid alternativeJid, String reason) {
this.jid = alternativeJid; this.jid = alternativeJid;
this.reason = reason; this.reason = reason;
this.password = null;
}
public Destroy(EntityBareJid alternativeJid, String password, String reason) {
this.jid = alternativeJid;
this.password = password;
this.reason = reason;
} }
/** /**
@ -59,6 +67,15 @@ public class Destroy implements NamedElement, Serializable {
return jid; return jid;
} }
/**
* Returns the password of the alternate location.
*
* @return the password of the alternate location.
*/
public String getPassword() {
return password;
}
/** /**
* Returns the reason for the room destruction. * Returns the reason for the room destruction.
* *
@ -73,6 +90,7 @@ public class Destroy implements NamedElement, Serializable {
XmlStringBuilder xml = new XmlStringBuilder(this); XmlStringBuilder xml = new XmlStringBuilder(this);
xml.optAttribute("jid", getJid()); xml.optAttribute("jid", getJid());
xml.rightAngleBracket(); xml.rightAngleBracket();
xml.optElement("password", getPassword());
xml.optElement("reason", getReason()); xml.optElement("reason", getReason());
xml.closeElement(this); xml.closeElement(this);
return xml; return xml;

View file

@ -79,6 +79,7 @@ public class MUCParserUtils {
final int initialDepth = parser.getDepth(); final int initialDepth = parser.getDepth();
final EntityBareJid jid = ParserUtils.getBareJidAttribute(parser); final EntityBareJid jid = ParserUtils.getBareJidAttribute(parser);
String reason = null; String reason = null;
String password = null;
outerloop: while (true) { outerloop: while (true) {
XmlPullParser.Event eventType = parser.next(); XmlPullParser.Event eventType = parser.next();
switch (eventType) { switch (eventType) {
@ -88,6 +89,9 @@ public class MUCParserUtils {
case "reason": case "reason":
reason = parser.nextText(); reason = parser.nextText();
break; break;
case "password":
password = parser.nextText();
break;
} }
break; break;
case END_ELEMENT: case END_ELEMENT:
@ -100,6 +104,6 @@ public class MUCParserUtils {
break; break;
} }
} }
return new Destroy(jid, reason); return new Destroy(jid, password, reason);
} }
} }

View file

@ -112,7 +112,7 @@ public class MultiUserChatIntegrationTest extends AbstractMultiUserChatIntegrati
UserStatusListener userStatusListener = new UserStatusListener() { UserStatusListener userStatusListener = new UserStatusListener() {
@Override @Override
public void roomDestroyed(MultiUserChat alternateMUC, String reason) { public void roomDestroyed(MultiUserChat alternateMUC, String password, String reason) {
mucDestroyed.signal(); mucDestroyed.signal();
} }
}; };