use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class LocalMUCRoom method createPresence.
@Override
public Presence createPresence(Presence.Type presenceType) throws UnauthorizedException {
Presence presence = new Presence();
presence.setType(presenceType);
presence.setFrom(role.getRoleAddress());
return presence;
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class LocalMUCRoom method kickOccupant.
@Override
public Presence kickOccupant(JID jid, JID actorJID, String actorNickname, String reason) throws NotAllowedException {
// Update the presence with the new role and inform all occupants
Presence updatedPresence = changeOccupantRole(jid, MUCRole.Role.none);
if (updatedPresence != null) {
Element frag = updatedPresence.getChildElement("x", "http://jabber.org/protocol/muc#user");
// Add the status code 307 that indicates that the user was kicked
frag.addElement("status").addAttribute("code", "307");
// Add the reason why the user was kicked
if (reason != null && reason.trim().length() > 0) {
frag.element("item").addElement("reason").setText(reason);
}
// Effectively kick the occupant from the room
kickPresence(updatedPresence, actorJID, actorNickname);
//Inform the other occupants that user has been kicked
broadcastPresence(updatedPresence, false);
}
return updatedPresence;
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class PubSubEngine method presenceSubscriptionRequired.
/**
* Requests the pubsub service to unsubscribe from the presence of the user. If the service
* was not subscribed to the user's presence or any node still requires to be subscribed to
* the user presence then do nothing.
*
* @param service the PubSub service this action is to be performed for.
* @param node the node that originated the unsubscription request.
* @param user the JID of the affiliate to unsubscribe from his presence.
*/
public static void presenceSubscriptionRequired(PubSubService service, Node node, JID user) {
Map<String, String> fullPresences = service.getBarePresences().get(user.toString());
if (fullPresences == null || fullPresences.isEmpty()) {
Presence subscription = new Presence(Presence.Type.subscribe);
subscription.setTo(user);
subscription.setFrom(service.getAddress());
service.send(subscription);
// Sending subscription requests based on received presences may generate
// that a sunscription request is sent to an offline user (since offline
// presences are not stored in the service's "barePresences"). However, this
// not optimal algorithm shouldn't bother the user since the user's server
// should reply when already subscribed to the user's presence instead of
// asking the user to accept the subscription request.
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class PubSubEngine method presenceSubscriptionNotRequired.
/**
* Requests the pubsub service to subscribe to the presence of the user. If the service
* has already subscribed to the user's presence then do nothing.
*
* @param service the PubSub service this action is to be performed for.
* @param node the node that originated the subscription request.
* @param user the JID of the affiliate to subscribe to his presence.
*/
public static void presenceSubscriptionNotRequired(PubSubService service, Node node, JID user) {
// Check that no node is requiring to be subscribed to this user
for (Node hostedNode : service.getNodes()) {
if (hostedNode.isPresenceBasedDelivery(user)) {
// Do not unsubscribe since presence subscription is still required
return;
}
}
// Unscribe from the user presence
Presence subscription = new Presence(Presence.Type.unsubscribe);
subscription.setTo(user);
subscription.setFrom(service.getAddress());
service.send(subscription);
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class PubSubEngine method process.
/**
* Handles Presence packets sent to the pubsub service. Only process available and not
* available presences.
*
* @param service the PubSub service this action is to be performed for.
* @param presence the Presence packet sent to the pubsub service.
*/
public void process(PubSubService service, Presence presence) {
if (presence.isAvailable()) {
JID subscriber = presence.getFrom();
Map<String, String> fullPresences = service.getBarePresences().get(subscriber.toBareJID());
if (fullPresences == null) {
synchronized (subscriber.toBareJID().intern()) {
fullPresences = service.getBarePresences().get(subscriber.toBareJID());
if (fullPresences == null) {
fullPresences = new ConcurrentHashMap<>();
service.getBarePresences().put(subscriber.toBareJID(), fullPresences);
}
}
}
Presence.Show show = presence.getShow();
fullPresences.put(subscriber.toString(), show == null ? "online" : show.name());
} else if (presence.getType() == Presence.Type.unavailable) {
JID subscriber = presence.getFrom();
Map<String, String> fullPresences = service.getBarePresences().get(subscriber.toBareJID());
if (fullPresences != null) {
fullPresences.remove(subscriber.toString());
if (fullPresences.isEmpty()) {
service.getBarePresences().remove(subscriber.toBareJID());
}
}
}
}
Aggregations