use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class InternalComponentManager method checkPresences.
private void checkPresences() {
for (JID prober : presenceMap.keySet()) {
JID probee = presenceMap.get(prober);
if (routingTable.hasComponentRoute(probee)) {
Presence presence = new Presence();
presence.setFrom(prober);
presence.setTo(probee);
routingTable.routePacket(probee, presence, false);
// No reason to hold onto prober reference.
presenceMap.remove(prober);
}
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class LocalMUCRoom method presenceUpdated.
/**
* Handles occupants updating their presence in the chatroom. Assumes the user updates their presence whenever their
* availability in the room changes. This method should not be called to handle other presence related updates, such
* as nickname changes.
* {@inheritDoc}
*/
@Override
public void presenceUpdated(final MUCRole occupantRole, final Presence newPresence) {
final String occupantNickName = occupantRole.getNickname();
// Update the presence of the occupant on the local node with the occupant's new availability. Updates the
// local node first so the remote nodes receive presence that correctly reflects the occupant's new
// availability and previously existing role and affiliation with the room.
final UpdatePresence localUpdateRequest = new UpdatePresence(this, newPresence.createCopy(), occupantNickName);
localUpdateRequest.setOriginator(true);
localUpdateRequest.run();
// Get the new, updated presence for the occupant in the room. The presence reflects the occupant's updated
// availability and their existing association.
final Presence updatedPresence = occupantRole.getPresence().createCopy();
// Ask other cluster nodes to update the presence of the occupant. Uses the updated presence from the local
// MUC role.
final UpdatePresence clusterUpdateRequest = new UpdatePresence(this, updatedPresence, occupantNickName);
CacheFactory.doClusterTask(clusterUpdateRequest);
// Broadcast updated presence of occupant.
broadcastPresence(updatedPresence, false);
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class LocalMUCRoom method leaveRoom.
@Override
public void leaveRoom(MUCRole leaveRole) {
if (leaveRole.isLocal()) {
// Ask other cluster nodes to remove occupant from room
OccupantLeftEvent event = new OccupantLeftEvent(this, leaveRole);
CacheFactory.doClusterTask(event);
}
try {
Presence originalPresence = leaveRole.getPresence();
Presence presence = originalPresence.createCopy();
presence.setType(Presence.Type.unavailable);
presence.setStatus(null);
// Change (or add) presence information about roles and affiliations
Element childElement = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
if (childElement == null) {
childElement = presence.addChildElement("x", "http://jabber.org/protocol/muc#user");
}
Element item = childElement.element("item");
if (item == null) {
item = childElement.addElement("item");
}
item.addAttribute("role", "none");
// 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 {
if (getOccupantsByNickname(leaveRole.getNickname()).size() <= 1) {
// Inform the rest of the room occupants that the user has left the room
broadcastPresence(presence, false);
}
}
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
// Remove occupant from room and destroy room if empty and not persistent
OccupantLeftEvent event = new OccupantLeftEvent(this, leaveRole);
event.setOriginator(true);
event.run();
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class LocalMUCRoom method changeOccupantAffiliation.
/**
* Updates all the presences of the given user with the new affiliation and role information. Do
* nothing if the given jid is not present in the room. If the user has joined the room from
* several client resources, all his/her occupants' presences will be updated.
*
* @param jid the bare jid of the user to update his/her role.
* @param newAffiliation the new affiliation for the JID.
* @param newRole the new role for the JID.
* @return the list of updated presences of all the client resources that the client used to
* join the room.
* @throws NotAllowedException If trying to change the moderator role to an owner or an admin or
* if trying to ban an owner or an administrator.
*/
private List<Presence> changeOccupantAffiliation(MUCRole senderRole, JID jid, MUCRole.Affiliation newAffiliation, MUCRole.Role newRole) throws NotAllowedException {
List<Presence> presences = new ArrayList<>();
// Get all the roles (i.e. occupants) of this user based on his/her bare JID
JID bareJID = jid.asBareJID();
List<MUCRole> roles = occupantsByBareJID.get(bareJID);
if (roles == null) {
return presences;
}
// Collect all the updated presences of these roles
for (MUCRole role : roles) {
// Update the presence with the new affiliation and role
if (role.isLocal()) {
role.setAffiliation(newAffiliation);
role.setRole(newRole);
// Notify the other cluster nodes to update the occupant
CacheFactory.doClusterTask(new UpdateOccupant(this, role));
// Prepare a new presence to be sent to all the room occupants
presences.add(role.getPresence().createCopy());
} else {
// Ask the cluster node hosting the occupant to make the changes. Note that if the change
// is not allowed a NotAllowedException will be thrown
Element element = (Element) CacheFactory.doSynchronousClusterTask(new UpdateOccupantRequest(this, role.getNickname(), newAffiliation, newRole), role.getNodeID().toByteArray());
if (element != null) {
// Prepare a new presence to be sent to all the room occupants
presences.add(new Presence(element, true));
} else {
throw new NotAllowedException();
}
}
}
// Answer all the updated presences
return presences;
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class LocalMUCRoom method setMembersOnly.
@Override
public List<Presence> setMembersOnly(boolean membersOnly) {
List<Presence> presences = new ArrayList<>();
if (membersOnly && !this.membersOnly) {
// of the room
for (MUCRole occupant : occupantsByFullJID.values()) {
if (occupant.getAffiliation().compareTo(MUCRole.Affiliation.member) > 0) {
try {
presences.add(kickOccupant(occupant.getRoleAddress(), null, null, LocaleUtils.getLocalizedString("muc.roomIsNowMembersOnly")));
} catch (NotAllowedException e) {
Log.error(e.getMessage(), e);
}
}
}
}
this.membersOnly = membersOnly;
return presences;
}
Aggregations