Commit a0bda201 authored by Günther Niess's avatar Günther Niess Committed by niess

Fix presence broadcasts when leaving a room (Patch for OF-48 and OF-64 from Ben)

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@11365 b35dd754-fafc-0310-a699-88a17e54d16e
parent da1885f2
...@@ -727,7 +727,8 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -727,7 +727,8 @@ public class LocalMUCRoom implements MUCRoom {
} }
try { try {
Presence presence = leaveRole.getPresence().createCopy(); Presence originalPresence = leaveRole.getPresence();
Presence presence = originalPresence.createCopy();
presence.setType(Presence.Type.unavailable); presence.setType(Presence.Type.unavailable);
presence.setStatus(null); presence.setStatus(null);
// Change (or add) presence information about roles and affiliations // Change (or add) presence information about roles and affiliations
...@@ -740,11 +741,19 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -740,11 +741,19 @@ public class LocalMUCRoom implements MUCRoom {
item = childElement.addElement("item"); item = childElement.addElement("item");
} }
item.addAttribute("role", "none"); item.addAttribute("role", "none");
// Check to see if the user's original presence is one we should broadcast
// a leave packet for. Need to check the original presence because we just
// set the role to "none" above, which is always broadcast.
if(!shouldBroadcastPresence(originalPresence)){
// Inform the leaving user that he/she has left the room // Inform the leaving user that he/she has left the room
leaveRole.send(presence); leaveRole.send(presence);
}
else {
// Inform the rest of the room occupants that the user has left the room // Inform the rest of the room occupants that the user has left the room
broadcastPresence(presence); broadcastPresence(presence);
} }
}
catch (Exception e) { catch (Exception e) {
Log.error(e); Log.error(e);
} }
...@@ -962,6 +971,26 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -962,6 +971,26 @@ public class LocalMUCRoom implements MUCRoom {
} }
} }
/**
* Checks the role of the sender and returns true if the given presence should be broadcasted
*
* @param presence The presence to check
* @return true if the presence should be broadcast to the rest of the room
*/
private boolean shouldBroadcastPresence(Presence presence){
if (presence == null) {
return false;
}
if (hasToCheckRoleToBroadcastPresence()) {
Element frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
// Check if we can broadcast the presence for this role
if (!canBroadcastPresence(frag.element("item").attributeValue("role"))) {
return false;
}
}
return true;
}
/** /**
* Broadcasts the specified presence to all room occupants. If the presence belongs to a * Broadcasts the specified presence to all room occupants. If the presence belongs to a
* user whose role cannot be broadcast then the presence will only be sent to the presence's * user whose role cannot be broadcast then the presence will only be sent to the presence's
...@@ -974,10 +1003,7 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -974,10 +1003,7 @@ public class LocalMUCRoom implements MUCRoom {
if (presence == null) { if (presence == null) {
return; return;
} }
if (hasToCheckRoleToBroadcastPresence()) { if (!shouldBroadcastPresence(presence)) {
Element frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
// Check if we can broadcast the presence for this role
if (!canBroadcastPresence(frag.element("item").attributeValue("role"))) {
// Just send the presence to the sender of the presence // Just send the presence to the sender of the presence
try { try {
MUCRole occupant = getOccupant(presence.getFrom().getResource()); MUCRole occupant = getOccupant(presence.getFrom().getResource());
...@@ -988,7 +1014,6 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -988,7 +1014,6 @@ public class LocalMUCRoom implements MUCRoom {
} }
return; return;
} }
}
// Broadcast presence to occupants hosted by other cluster nodes // Broadcast presence to occupants hosted by other cluster nodes
BroadcastPresenceRequest request = new BroadcastPresenceRequest(this, presence); BroadcastPresenceRequest request = new BroadcastPresenceRequest(this, presence);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment