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

Merge pull request #494 from Flowdalic/mux-race-condition

[muc] Check for self-presence first
This commit is contained in:
Florian Schmaus 2021-10-19 14:08:32 +02:00 committed by GitHub
commit 2ff53abef3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -212,7 +212,12 @@ public class MultiUserChat {
switch (presence.getType()) { switch (presence.getType()) {
case available: case available:
Presence oldPresence = occupantsMap.put(from, presence); Presence oldPresence = occupantsMap.put(from, presence);
if (oldPresence != null) { if (mucUser.getStatus().contains(MUCUser.Status.PRESENCE_TO_SELF_110)) {
processedReflectedSelfPresence = true;
synchronized (this) {
notify();
}
} else if (oldPresence != null) {
// Get the previous occupant's affiliation & role // Get the previous occupant's affiliation & role
MUCUser mucExtension = MUCUser.from(oldPresence); MUCUser mucExtension = MUCUser.from(oldPresence);
MUCAffiliation oldAffiliation = mucExtension.getItem().getAffiliation(); MUCAffiliation oldAffiliation = mucExtension.getItem().getAffiliation();
@ -228,11 +233,6 @@ public class MultiUserChat {
newAffiliation, newAffiliation,
isUserStatusModification, isUserStatusModification,
from); from);
} else if (mucUser.getStatus().contains(MUCUser.Status.PRESENCE_TO_SELF_110)) {
processedReflectedSelfPresence = true;
synchronized (this) {
notify();
}
} else { } else {
// A new occupant has joined the room // A new occupant has joined the room
for (ParticipantStatusListener listener : participantStatusListeners) { for (ParticipantStatusListener listener : participantStatusListeners) {
@ -789,11 +789,14 @@ public class MultiUserChat {
StanzaFilter reflectedLeavePresenceFilter = new AndFilter(reflectedLeavePresenceFilters); StanzaFilter reflectedLeavePresenceFilter = new AndFilter(reflectedLeavePresenceFilters);
// Reset occupant information first so that we are assume that we left the room even if sendStanza() would Presence reflectedLeavePresence;
// throw. try {
userHasLeft(); reflectedLeavePresence = connection.createStanzaCollectorAndSend(reflectedLeavePresenceFilter, leavePresence).nextResultOrThrow();
} finally {
Presence reflectedLeavePresence = connection.createStanzaCollectorAndSend(reflectedLeavePresenceFilter, leavePresence).nextResultOrThrow(); // Reset occupant information after we send the leave presence. This ensures that we only call userHasLeft()
// and reset the local MUC state after we successfully left the MUC (or if an exception occurred).
userHasLeft();
}
return reflectedLeavePresence; return reflectedLeavePresence;
} }