Commit 1f920bdd authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Send available/unavailable presence to all connected resources after...

Send available/unavailable presence to all connected resources after subscription is approved/canceled. JM-758

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4281 b35dd754-fafc-0310-a699-88a17e54d16e
parent 2f31e3b5
......@@ -11,11 +11,11 @@
package org.jivesoftware.wildfire;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.xmpp.packet.Presence;
import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
import java.util.Collection;
......@@ -66,7 +66,9 @@ public interface PresenceManager {
public Collection<Presence> getPresences(String username);
/**
* Probes the presence of the given XMPPAddress and attempts to send it to the given user.
* Probes the presence of the given XMPPAddress and attempts to send it to the given user. If
* the user probing the presence is using his bare JID then the probee's presence will be
* sent to all connected resources of the prober.
*
* @param prober The user requesting the probe
* @param probee The XMPPAddress whos presence we would like sent have have probed
......@@ -98,7 +100,8 @@ public interface PresenceManager {
* 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
* send to the remote user unavailable presence from all of the local user's available
* resources.
* resources. Moreover, if the recipient user is a local user then the unavailable presence
* will be sent to all user resources.
*
* @param recipientJID JID of the remote user that will receive the unavailable presences.
* @param userJID JID of the local user.
......
......@@ -153,7 +153,9 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
if (type == Presence.Type.subscribed) {
// Send the presence of the local user to the remote user. The remote user
// subscribed to the presence of the local user and the local user accepted
presenceManager.probePresence(recipientJID, senderJID);
JID prober = localServer.isLocal(recipientJID) ?
new JID(recipientJID.toBareJID()) : recipientJID;
presenceManager.probePresence(prober, senderJID);
}
}
......
......@@ -226,6 +226,16 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
public void probePresence(JID prober, JID probee) {
try {
if (server.isLocal(probee)) {
// Local probers should receive presences of probee in all connected resources
Collection<JID> proberFullJIDs = new ArrayList<JID>();
if (prober.getResource() == null && server.isLocal(prober)) {
for (ClientSession session : sessionManager.getSessions(prober.getNode())) {
proberFullJIDs.add(session.getAddress());
}
}
else {
proberFullJIDs.add(prober);
}
// If the probee is a local user then don't send a probe to the contact's server.
// But instead just send the contact's presence to the prober
Collection<ClientSession> sessions = sessionManager.getSessions(probee.getNode());
......@@ -242,14 +252,17 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
// Create the presence from the parsed element
Presence presencePacket = new Presence(element.getRootElement());
presencePacket.setFrom(probee.toBareJID());
presencePacket.setTo(prober);
// Check if default privacy list of the probee blocks the
// outgoing presence
PrivacyList list = PrivacyListManager.getInstance()
.getDefaultPrivacyList(probee.getNode());
if (list == null || !list.shouldBlockPacket(presencePacket)) {
// Send the presence to the prober
deliverer.deliver(presencePacket);
// Send presence to all prober's resources
for (JID receipient : proberFullJIDs) {
presencePacket.setTo(receipient);
if (list == null || !list.shouldBlockPacket(presencePacket)) {
// Send the presence to the prober
deliverer.deliver(presencePacket);
}
}
}
catch (Exception e) {
......@@ -264,21 +277,24 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
// Create presence to send from probee to prober
Presence presencePacket = session.getPresence().createCopy();
presencePacket.setFrom(session.getAddress());
presencePacket.setTo(prober);
// Check if a privacy list of the probee blocks the outgoing presence
PrivacyList list = session.getActiveList();
list = list == null ? session.getDefaultList() : list;
if (list != null) {
if (list.shouldBlockPacket(presencePacket)) {
// Default list blocked outgoing presence so skip this session
continue;
// Send presence to all prober's resources
for (JID receipient : proberFullJIDs) {
presencePacket.setTo(receipient);
if (list != null) {
if (list.shouldBlockPacket(presencePacket)) {
// Default list blocked outgoing presence so skip this session
continue;
}
}
try {
deliverer.deliver(presencePacket);
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
try {
deliverer.deliver(presencePacket);
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
}
......@@ -331,12 +347,25 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
Presence presencePacket = new Presence();
presencePacket.setType(Presence.Type.unavailable);
presencePacket.setFrom(session.getAddress());
presencePacket.setTo(recipientJID);
try {
deliverer.deliver(presencePacket);
// Ensure that unavailable presence is sent to all receipient's resources
Collection<JID> recipientFullJIDs = new ArrayList<JID>();
if (server.isLocal(recipientJID)) {
for (ClientSession targetSession : sessionManager
.getSessions(recipientJID.getNode())) {
recipientFullJIDs.add(targetSession.getAddress());
}
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
else {
recipientFullJIDs.add(recipientJID);
}
for (JID jid : recipientFullJIDs) {
presencePacket.setTo(jid);
try {
deliverer.deliver(presencePacket);
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
}
}
......
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