1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 12:02:05 +01:00

Make MultiUserChat.leave() behave as leaveSync()

and mark leaveSync() as deprecated.

Fixes SMACK-848.
This commit is contained in:
Florian Schmaus 2018-12-26 21:44:35 +01:00
parent a9de8e2f76
commit e4c31541e0
3 changed files with 21 additions and 23 deletions

View file

@ -450,7 +450,12 @@ public class MultiUserChat {
return mucCreateConfigFormHandle; return mucCreateConfigFormHandle;
} }
// We need to leave the room since it seems that the room already existed // We need to leave the room since it seems that the room already existed
leave(); try {
leave();
}
catch (MucNotJoinedException e) {
LOGGER.log(Level.INFO, "Unexpected MucNotJoinedException", e);
}
throw new MissingMucCreationAcknowledgeException(); throw new MissingMucCreationAcknowledgeException();
} }
@ -684,28 +689,19 @@ public class MultiUserChat {
/** /**
* Leave the chat room. * Leave the chat room.
*
* @return the leave presence as reflected by the MUC.
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
* @throws XMPPErrorException
* @throws NoResponseException
* @throws MucNotJoinedException
* @deprecated use {@link #leave()} instead.
*/ */
public synchronized void leave() throws NotConnectedException, InterruptedException { @Deprecated
// Note that this method is intentionally not guarded by // TODO: Remove in Smack 4.5.
// "if (!joined) return" because it should be always be possible to leave the room in case the instance's public synchronized Presence leaveSync() throws NotConnectedException, InterruptedException, MucNotJoinedException, NoResponseException, XMPPErrorException {
// state does not reflect the actual state. return leave();
// Reset occupant information first so that we are assume that we left the room even if sendStanza() would
// throw.
userHasLeft();
final EntityFullJid myRoomJid = this.myRoomJid;
if (myRoomJid == null) {
return;
}
// We leave a room by sending a presence packet where the "to"
// field is in the form "roomName@service/nickname"
Presence leavePresence = new Presence(Presence.Type.unavailable);
leavePresence.setTo(myRoomJid);
connection.sendStanza(leavePresence);
} }
/** /**
@ -718,7 +714,7 @@ public class MultiUserChat {
* @throws NoResponseException * @throws NoResponseException
* @throws MucNotJoinedException * @throws MucNotJoinedException
*/ */
public synchronized Presence leaveSync() public synchronized Presence leave()
throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException, MucNotJoinedException { throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException, MucNotJoinedException {
// Note that this method is intentionally not guarded by // Note that this method is intentionally not guarded by
// "if (!joined) return" because it should be always be possible to leave the room in case the instance's // "if (!joined) return" because it should be always be possible to leave the room in case the instance's

View file

@ -52,6 +52,7 @@ import org.jivesoftware.smackx.disco.AbstractNodeInformationProvider;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.disco.packet.DiscoverItems; import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.muc.MultiUserChatException.MucNotJoinedException;
import org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException; import org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException;
import org.jivesoftware.smackx.muc.packet.MUCInitialPresence; import org.jivesoftware.smackx.muc.packet.MUCInitialPresence;
import org.jivesoftware.smackx.muc.packet.MUCUser; import org.jivesoftware.smackx.muc.packet.MUCUser;
@ -206,7 +207,8 @@ public final class MultiUserChatManager extends Manager {
try { try {
muc.leave(); muc.leave();
} catch (NotConnectedException | InterruptedException e) { } catch (NotConnectedException | InterruptedException | MucNotJoinedException
| NoResponseException | XMPPErrorException e) {
if (failedCallback != null) { if (failedCallback != null) {
failedCallback.autoJoinFailed(muc, e); failedCallback.autoJoinFailed(muc, e);
} else { } else {

View file

@ -79,7 +79,7 @@ public class MultiUserChatIntegrationTest extends AbstractSmackIntegrationTest {
muc.join(Resourcepart.from("nick-one")); muc.join(Resourcepart.from("nick-one"));
Presence reflectedLeavePresence = muc.leaveSync(); Presence reflectedLeavePresence = muc.leave();
MUCUser mucUser = MUCUser.from(reflectedLeavePresence); MUCUser mucUser = MUCUser.from(reflectedLeavePresence);
assertNotNull(mucUser); assertNotNull(mucUser);