Commit eca81905 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Added #canProbePresence(JID prober, String probee). JM-234


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1661 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7fc0c18e
......@@ -12,6 +12,7 @@
package org.jivesoftware.messenger;
import org.jivesoftware.messenger.user.User;
import org.jivesoftware.messenger.user.UserNotFoundException;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.xmpp.packet.Presence;
import org.xmpp.packet.JID;
......@@ -82,6 +83,17 @@ public interface PresenceManager {
*/
public void handleProbe(Presence packet) throws UnauthorizedException;
/**
* Returns true if the the prober is allowed to see the presence of the probee.
*
* @param prober the user that is trying to probe the presence of another user.
* @param probee the username of the uset that is being probed.
* @return true if the the prober is allowed to see the presence of the probee.
* @throws UserNotFoundException If the probee does not exist in the local server or the prober
* is not present in the roster of the probee.
*/
public boolean canProbePresence(JID prober, String probee) throws UserNotFoundException;
/**
* Sends unavailable presence from all of the user's available resources to the remote user.
* When a remote user unsubscribes from the presence of a local user then the server should
......
......@@ -219,6 +219,29 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
}
}
public boolean canProbePresence(JID prober, String probee) throws UserNotFoundException {
// Check that the probee is a valid user
UserManager.getInstance().getUser(probee);
// Check for a cached roster:
Roster roster = (Roster)CacheManager.getCache("username2roster").get(probee);
if (roster == null) {
synchronized(probee.intern()) {
roster = (Roster)CacheManager.getCache("username2roster").get(probee);
if (roster == null) {
// Not in cache so load a new one:
roster = new Roster(probee);
CacheManager.getCache("username2roster").put(probee, roster);
}
}
}
RosterItem item = roster.getRosterItem(prober);
if (item.getSubStatus() == RosterItem.SUB_FROM
|| item.getSubStatus() == RosterItem.SUB_BOTH) {
return true;
}
return false;
}
public void probePresence(JID prober, JID probee) {
try {
Component component = getPresenceComponent(probee);
......
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