Commit cc837309 authored by Armando Jagucki's avatar Armando Jagucki Committed by ajagucki

PEP: Added automatic PEP service subscription cancelling when presences are unsbuscribed from.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches/pep@8917 b35dd754-fafc-0310-a699-88a17e54d16e
parent 02e5394a
......@@ -177,6 +177,7 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
// Send unavailable presence from all of the local user's available resources
// to the remote user
presenceManager.sendUnavailableFromSessions(recipientJID, senderJID);
PresenceEventDispatcher.unsubscribedToPresence(senderJID, recipientJID);
}
}
catch (SharedGroupException e) {
......
......@@ -441,6 +441,29 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
pepService.sendLastPublishedItem(subscriberJID);
}
}
public void unsubscribedToPresence(JID unsubscriberJID, JID recipientJID) {
if (Log.isDebugEnabled()) {
Log.debug("PEP: " + unsubscriberJID + " unsubscribed from " + recipientJID + "'s presence.");
}
// Retrieve recipientJID's PEP service, if it exists.
PEPService pepService = pepServices.get(recipientJID.toBareJID());
if (pepService == null) {
return;
}
// Cancel unsubscriberJID's subscription to recipientJID's PEP service, if it exists.
CollectionNode rootNode = pepService.getRootCollectionNode();
NodeSubscription nodeSubscription = rootNode.getSubscription(unsubscriberJID);
if (nodeSubscription != null) {
rootNode.cancelSubscription(nodeSubscription);
if (Log.isDebugEnabled()) {
Log.debug("PEP: " + unsubscriberJID + " subscription to " + recipientJID + "'s PEP service was cancelled.");
}
}
}
public void unavailableSession(ClientSession session, Presence presence) {
// Do nothing
......
......@@ -96,14 +96,6 @@ public class PEPService implements PubSubService {
*/
private boolean nodeCreationRestricted = true;
/**
* Flag that indicates if a user may have more than one subscription with
* the node. When multiple subscriptions is enabled each subscription
* request, event notification, and unsubscription request should include a
* subid attribute.
*/
private boolean multipleSubscriptionsEnabled = false;
/**
* Keep a registry of the presence's show value of users that subscribed to
* a node of the pep service and for which the node only delivers
......@@ -296,7 +288,7 @@ public class PEPService implements PubSubService {
}
public boolean isMultipleSubscriptionsEnabled() {
return multipleSubscriptionsEnabled;
return false;
}
public boolean isServiceAdmin(JID user) {
......
......@@ -139,4 +139,19 @@ public class PresenceEventDispatcher {
}
}
}
/**
* Notification message indicating that a user has unsubscribed
* to the presence of another user.
*
* @param unsubscriberJID the user that initiated the unsubscribe request.
* @param recipientJID the recipient user of the unsubscribe request.
*/
public static void unsubscribedToPresence(JID unsubscriberJID, JID recipientJID) {
if (!listeners.isEmpty()) {
for (PresenceEventListener listener : listeners) {
listener.unsubscribedToPresence(unsubscriberJID, recipientJID);
}
}
}
}
......@@ -74,4 +74,13 @@ public interface PresenceEventListener {
* @param authorizerJID the user that authorized the subscription.
*/
public void subscribedToPresence(JID subscriberJID, JID authorizerJID);
/**
* Notification message indicating that a user has unsubscribed
* to the presence of another user.
*
* @param unsubscriberJID the user that initiated the unsubscribe request.
* @param recipientJID the recipient user of the unsubscribe request.
*/
public void unsubscribedToPresence(JID unsubscriberJID, JID recipientJID);
}
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