diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java index aceb4d9ff..0ccf9ba24 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -450,7 +450,12 @@ public class MultiUserChat { return mucCreateConfigFormHandle; } // 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(); } @@ -684,28 +689,19 @@ public class MultiUserChat { /** * Leave the chat room. + * + * @return the leave presence as reflected by the MUC. * @throws NotConnectedException * @throws InterruptedException + * @throws XMPPErrorException + * @throws NoResponseException + * @throws MucNotJoinedException + * @deprecated use {@link #leave()} instead. */ - public synchronized void leave() throws NotConnectedException, InterruptedException { - // 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 - // state does not reflect the actual state. - - // 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); + @Deprecated + // TODO: Remove in Smack 4.5. + public synchronized Presence leaveSync() throws NotConnectedException, InterruptedException, MucNotJoinedException, NoResponseException, XMPPErrorException { + return leave(); } /** @@ -718,7 +714,7 @@ public class MultiUserChat { * @throws NoResponseException * @throws MucNotJoinedException */ - public synchronized Presence leaveSync() + public synchronized Presence leave() throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException, MucNotJoinedException { // 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 diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java index 33e36e76b..1730e4a67 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java @@ -52,6 +52,7 @@ import org.jivesoftware.smackx.disco.AbstractNodeInformationProvider; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.disco.packet.DiscoverInfo; 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.packet.MUCInitialPresence; import org.jivesoftware.smackx.muc.packet.MUCUser; @@ -206,7 +207,8 @@ public final class MultiUserChatManager extends Manager { try { muc.leave(); - } catch (NotConnectedException | InterruptedException e) { + } catch (NotConnectedException | InterruptedException | MucNotJoinedException + | NoResponseException | XMPPErrorException e) { if (failedCallback != null) { failedCallback.autoJoinFailed(muc, e); } else { diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatIntegrationTest.java index d57f4467e..9fa199d08 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatIntegrationTest.java @@ -79,7 +79,7 @@ public class MultiUserChatIntegrationTest extends AbstractSmackIntegrationTest { muc.join(Resourcepart.from("nick-one")); - Presence reflectedLeavePresence = muc.leaveSync(); + Presence reflectedLeavePresence = muc.leave(); MUCUser mucUser = MUCUser.from(reflectedLeavePresence); assertNotNull(mucUser);