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,10 +741,18 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -740,10 +741,18 @@ public class LocalMUCRoom implements MUCRoom {
item = childElement.addElement("item"); item = childElement.addElement("item");
} }
item.addAttribute("role", "none"); item.addAttribute("role", "none");
// Inform the leaving user that he/she has left the room
leaveRole.send(presence); // Check to see if the user's original presence is one we should broadcast
// Inform the rest of the room occupants that the user has left the room // a leave packet for. Need to check the original presence because we just
broadcastPresence(presence); // set the role to "none" above, which is always broadcast.
if(!shouldBroadcastPresence(originalPresence)){
// Inform the leaving user that he/she has left the room
leaveRole.send(presence);
}
else {
// Inform the rest of the room occupants that the user has left the room
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,20 +1003,16 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -974,20 +1003,16 @@ 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"); // Just send the presence to the sender of the presence
// Check if we can broadcast the presence for this role try {
if (!canBroadcastPresence(frag.element("item").attributeValue("role"))) { MUCRole occupant = getOccupant(presence.getFrom().getResource());
// Just send the presence to the sender of the presence occupant.send(presence);
try {
MUCRole occupant = getOccupant(presence.getFrom().getResource());
occupant.send(presence);
}
catch (UserNotFoundException e) {
// Do nothing
}
return;
} }
catch (UserNotFoundException e) {
// Do nothing
}
return;
} }
// Broadcast presence to occupants hosted by other cluster nodes // Broadcast presence to occupants hosted by other cluster nodes
......
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