From 26ab8324520f10aa8009f5054ee862c77ba1925c Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 16 Apr 2020 21:40:06 +0200 Subject: [PATCH] muc: only call userHasLeft() at one site There is no need to duplicate that code. Also ensure that userHasLeft() is invoked *before* the listeners are invoked, so that e.g. isJoined() returns false in the listeners. --- .../smackx/muc/MultiUserChat.java | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) 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 8dc709558..68624f7f1 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 @@ -233,6 +233,9 @@ public class MultiUserChat { occupantsMap.remove(from); MUCUser mucUser = MUCUser.from(packet); if (mucUser != null && mucUser.hasStatus()) { + if (isUserStatusModification) { + userHasLeft(); + } // Fire events according to the received presence code checkPresenceCode( mucUser.getStatus(), @@ -2438,9 +2441,6 @@ public class MultiUserChat { if (statusCodes.contains(Status.KICKED_307)) { // Check if this occupant was kicked if (isUserModification) { - // Reset occupant information. - userHasLeft(); - for (UserStatusListener listener : userStatusListeners) { listener.kicked(mucUser.getItem().getActor(), mucUser.getItem().getReason()); } @@ -2455,15 +2455,9 @@ public class MultiUserChat { if (statusCodes.contains(Status.BANNED_301)) { // Check if this occupant was banned if (isUserModification) { - joined = false; for (UserStatusListener listener : userStatusListeners) { listener.banned(mucUser.getItem().getActor(), mucUser.getItem().getReason()); } - - // Reset occupant information. - occupantsMap.clear(); - myRoomJid = null; - userHasLeft(); } else { for (ParticipantStatusListener listener : participantStatusListeners) { @@ -2475,15 +2469,9 @@ public class MultiUserChat { if (statusCodes.contains(Status.REMOVED_AFFIL_CHANGE_321)) { // Check if this occupant's membership was revoked if (isUserModification) { - joined = false; for (UserStatusListener listener : userStatusListeners) { listener.membershipRevoked(); } - - // Reset occupant information. - occupantsMap.clear(); - myRoomJid = null; - userHasLeft(); } } // A occupant has changed his nickname in the room @@ -2498,11 +2486,6 @@ public class MultiUserChat { for (UserStatusListener listener : userStatusListeners) { listener.roomDestroyed(alternateMUC, mucUser.getDestroy().getReason()); } - - // Reset occupant information. - occupantsMap.clear(); - myRoomJid = null; - userHasLeft(); } }