Commit 97d8494a authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Initial changes for roster/presence management. (still lots of testing is pending)


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1388 b35dd754-fafc-0310-a699-88a17e54d16e
parent 6dc5f533
......@@ -110,6 +110,11 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
// subscribed to the presence of the local user and the local user accepted
presenceManager.probePresence(recipientJID, senderJID);
}
else if (getRoster(recipientJID) == null && type == Presence.Type.unsubscribed) {
// Send unavailable presence from all of the local user's available resources
// to the remote user
presenceManager.sendUnavailableFromSessions(recipientJID, senderJID);
}
}
catch (NoSuchRouteException e) {
deliverer.deliver(presence.createCopy());
......@@ -249,7 +254,7 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
subsTable.put(Presence.Type.subscribed, new Change(RosterItem.RECV_NONE, null, null));
// Owner asking to unsubscribe to item
// This makes no sense (there is no subscription to unsubscribe from)
subsTable.put(Presence.Type.unsubscribe, new Change(null, null, null));
subsTable.put(Presence.Type.unsubscribe, new Change(null, RosterItem.SUB_NONE, null));
// Item has subscription from owner revoked
// Immediately transition to NONE state
subsTable.put(Presence.Type.unsubscribed, new Change(RosterItem.RECV_NONE, RosterItem.SUB_NONE, null));
......@@ -263,7 +268,7 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
subrTable.put(Presence.Type.subscribed, new Change(null, RosterItem.SUB_BOTH, RosterItem.ASK_NONE));
// Item wishes to unsubscribe from owner
// This is the normal mechanism of removing subscription
subrTable.put(Presence.Type.unsubscribe, new Change(RosterItem.RECV_UNSUBSCRIBE, null, null));
subrTable.put(Presence.Type.unsubscribe, new Change(RosterItem.RECV_UNSUBSCRIBE, RosterItem.SUB_NONE, null));
// Owner has subscription to item revoked
// Valid response if owner requested subscription and item is denying request
subrTable.put(Presence.Type.unsubscribed, new Change(null, null, RosterItem.ASK_NONE));
......@@ -282,7 +287,7 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
subsTable.put(Presence.Type.subscribed, new Change(RosterItem.RECV_NONE, RosterItem.SUB_BOTH, null));
// Owner asking to unsubscribe to item
// Normal method of removing subscription
subsTable.put(Presence.Type.unsubscribe, new Change(null, null, RosterItem.ASK_UNSUBSCRIBE));
subsTable.put(Presence.Type.unsubscribe, new Change(null, RosterItem.SUB_NONE, RosterItem.ASK_UNSUBSCRIBE));
// Item has subscription from owner revoked
// No subscription to unsub, makes sense if denying subscription request or for
// situations where the original unsubscribed got lost
......@@ -295,7 +300,7 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
subrTable.put(Presence.Type.subscribed, new Change(null, null, RosterItem.ASK_NONE));
// Item wishes to unsubscribe from owner
// There is no subscription. May be trying to cancel earlier subscribe request.
subrTable.put(Presence.Type.unsubscribe, new Change(RosterItem.RECV_NONE, null, null));
subrTable.put(Presence.Type.unsubscribe, new Change(RosterItem.RECV_NONE, RosterItem.SUB_NONE, null));
// Owner has subscription to item revoked
// Setting subscription to none
subrTable.put(Presence.Type.unsubscribed, new Change(null, RosterItem.SUB_NONE, RosterItem.ASK_NONE));
......@@ -315,7 +320,7 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
subsTable.put(Presence.Type.subscribed, new Change(RosterItem.RECV_NONE, null, null));
// Owner asking to unsubscribe to item
// Set flags
subsTable.put(Presence.Type.unsubscribe, new Change(null, null, RosterItem.ASK_UNSUBSCRIBE));
subsTable.put(Presence.Type.unsubscribe, new Change(null, RosterItem.SUB_FROM, RosterItem.ASK_UNSUBSCRIBE));
// Item has subscription from owner revoked
// Immediately transition them to TO state
subsTable.put(Presence.Type.unsubscribed, new Change(RosterItem.RECV_NONE, RosterItem.SUB_TO, null));
......@@ -329,7 +334,7 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
subrTable.put(Presence.Type.subscribed, new Change(null, null, RosterItem.ASK_NONE));
// Item wishes to unsubscribe from owner
// This is the normal mechanism of removing subscription
subrTable.put(Presence.Type.unsubscribe, new Change(RosterItem.RECV_UNSUBSCRIBE, null, null));
subrTable.put(Presence.Type.unsubscribe, new Change(RosterItem.RECV_UNSUBSCRIBE, RosterItem.SUB_TO, null));
// Owner has subscription to item revoked
// Immediately downgrade state to FROM
subrTable.put(Presence.Type.unsubscribed, new Change(RosterItem.RECV_NONE, RosterItem.SUB_FROM, RosterItem.ASK_NONE));
......
......@@ -48,7 +48,7 @@ public class Roster implements Cacheable {
private RosterItemProvider rosterItemProvider;
private String username;
private SessionManager sessionManager;
private XMPPServer server;
private XMPPServer server = XMPPServer.getInstance();
private RoutingTable routingTable;
private PresenceManager presenceManager;
/**
......@@ -303,10 +303,9 @@ public class Roster implements Cacheable {
rosterItemProvider.updateItem(username, item);
}
// broadcast roster update
if (!(item.getSubStatus() == RosterItem.SUB_NONE
&& item.getAskStatus() == RosterItem.ASK_NONE)) {
//if (item.getAskStatus() != RosterItem.ASK_NONE) {
broadcast(item, true);
}
//}
if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_TO) {
probePresence(item.getJid());
}
......@@ -327,7 +326,7 @@ public class Roster implements Cacheable {
throw new SharedGroupException("Cannot remove contact that belongs to a shared group");
}
/*RosterItem.SubType subType = itemToRemove.getSubStatus();
RosterItem.SubType subType = itemToRemove.getSubStatus();
// Cancel any existing presence subscription between the user and the contact
if (subType == RosterItem.SUB_TO || subType == RosterItem.SUB_BOTH) {
Presence presence = new Presence();
......@@ -343,7 +342,7 @@ public class Roster implements Cacheable {
presence.setTo(itemToRemove.getJid());
presence.setType(Presence.Type.unsubscribed);
server.getPacketRouter().route(presence);
}*/
}
// If removing the user was successful, remove the user from the subscriber list:
RosterItem item = rosterItems.remove(user.toBareJID());
if (item != null) {
......@@ -359,14 +358,14 @@ public class Roster implements Cacheable {
roster.setType(IQ.Type.set);
roster.addItem(user, org.xmpp.packet.Roster.Subscription.remove);
broadcast(roster);
/*// Send unavailable presence from all of the user's available resources to the contact
// Send unavailable presence from all of the user's available resources to the contact
for (ClientSession session : sessionManager.getSessions(username)) {
Presence presence = new Presence();
presence.setFrom(session.getAddress());
presence.setTo(item.getJid());
presence.setType(Presence.Type.unavailable);
server.getPacketRouter().route(presence);
}*/
}
}
return item;
......@@ -403,10 +402,9 @@ public class Roster implements Cacheable {
for (Group sharedGroup : item.getSharedGroups()) {
groups.add(sharedGroup.getProperties().get("sharedRoster.displayName"));
}
if (item.getSubStatus() != RosterItem.SUB_NONE ||
item.getAskStatus() != RosterItem.ASK_NONE) {
//if (item.getAskStatus() != RosterItem.ASK_NONE) {
roster.addItem(item.getJid(), item.getNickname(), ask, sub, groups);
}
//}
}
return roster;
}
......@@ -485,9 +483,6 @@ public class Roster implements Cacheable {
}
private void broadcast(org.xmpp.packet.Roster roster) {
if (server == null) {
server = XMPPServer.getInstance();
}
JID recipient = server.createJID(username, null);
roster.setTo(recipient);
if (sessionManager == null) {
......
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