if (sub != SubscriptionType.none && (type == null || !type.equals(ANON))) {
Element pres = new Element("presence");
pres.setAttribute("to", buddy);
pres.setAttribute("from", session.getUserId());
pres.setAttribute("type", "unsubscribe");
results.offer(new Packet(pres));
pres = new Element("presence");
pres.setAttribute("to", buddy);
pres.setAttribute("from", session.getUserId());
pres.setAttribute("type", "unsubscribed");
results.offer(new Packet(pres));
pres = new Element("presence");
pres.setAttribute("to", buddy);
pres.setAttribute("from", session.getJID());
pres.setAttribute("type", "unavailable");
results.offer(new Packet(pres));
}
// It happens sometimes that the client still think the buddy
// is in the roster while he isn't. In such a case just ensure the
// client that the buddy has been removed for sure
Element it = new Element("item");
it.setAttribute("jid", buddy);
it.setAttribute("subscription", "remove");
roster_util.updateBuddyChange(session, results, it);
roster_util.removeBuddy(session, buddy);
results.offer(packet.okResult((String)null, 0));
} else {
String name = request.getAttribute("/iq/query/item", "name");
// if (name == null) {
// name = buddy;
// } // end of if (name == null)
List<Element> groups = item.getChildren();
String[] gr = null;
if (groups != null && groups.size() > 0) {
gr = new String[groups.size()];
int cnt = 0;
for (Element group : groups) {
gr[cnt++] = (group.getCData() == null ? "" : group.getCData());
} // end of for (ElementData group : groups)
}
//roster_util.setBuddyGroups(session, buddy, gr);
roster_util.addBuddy(session, buddy, name, gr);
String type = request.getAttribute("/iq/query/item", "type");
if (type != null && type.equals(ANON)) {
roster_util.setBuddySubscription(session, SubscriptionType.both, buddy);
Element pres = (Element)session.getSessionData(Presence.PRESENCE_KEY);
if (pres == null) {
pres = new Element("presence");
} else {
pres = pres.clone();
}
pres.setAttribute("to", buddy);
pres.setAttribute("from", session.getJID());
results.offer(new Packet(pres));
}
if (roster_util.getBuddySubscription(session, buddy) == null) {
roster_util.setBuddySubscription(session, SubscriptionType.none, buddy);
} // end of if (getBuddySubscription(session, buddy) == null)
results.offer(packet.okResult((String)null, 0));