use of org.jivesoftware.openfire.roster.RosterItem in project Openfire by igniterealtime.
the class IQRosterPayloadProcessor method handleIQget.
private void handleIQget(IQ myPacket, String subdomain, String username) {
if (JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false)) {
Roster roster;
try {
roster = _rosterManager.getRoster(username);
Collection<RosterItem> items = roster.getRosterItems();
Log.debug("Sending contacts with subdomain " + subdomain + " from user " + username + " to external Component");
sendRosterToComponent(myPacket, items, subdomain);
} catch (UserNotFoundException e) {
e.printStackTrace();
}
} else {
Log.debug("Sending nonpersistant-RemoteRosterResponse to external Component for User: " + username);
sendEmptyRoster(myPacket, subdomain);
}
}
use of org.jivesoftware.openfire.roster.RosterItem in project Openfire by igniterealtime.
the class NonPersistantRosterProcessor method process.
@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
Presence myPacket = (Presence) packet;
if (myPacket.getType() != null && myPacket.getType().equals(Presence.Type.unavailable) && !myPacket.getElement().getStringValue().equals("Connecting")) {
String username = getUsernameFromJid(to);
Log.debug("Processing packet in NonPersistantRosterProcessor for " + subdomain + "and user " + username + " Packet: " + packet.toString());
try {
Roster roster = _rosterManager.getRoster(username);
Collection<RosterItem> items = roster.getRosterItems();
for (RosterItem item : items) {
String itemName = item.getJid().toString();
if (itemName.contains(subdomain)) {
Log.debug("Removing contact " + item.getJid().toString() + " from contact list.");
roster.deleteRosterItem(item.getJid(), false);
}
}
} catch (Exception e) {
Log.debug("Execption occured when cleaning up the Roster.", e);
e.printStackTrace();
}
}
}
use of org.jivesoftware.openfire.roster.RosterItem in project Openfire by igniterealtime.
the class IQRosterHandler method removeItem.
/**
* Remove the roster item from the sender's roster (and possibly the recipient's).
* Actual roster removal is done in the removeItem(Roster,RosterItem) method.
*
* @param roster The sender's roster.
* @param sender The JID of the sender of the removal request
* @param item The removal item element
* @return The removed item or null, if not item has been removed.
*/
private RosterItem removeItem(org.jivesoftware.openfire.roster.Roster roster, JID sender, org.xmpp.packet.Roster.Item item) throws SharedGroupException {
JID recipient = item.getJID();
// Remove recipient from the sender's roster
RosterItem removedItem = roster.deleteRosterItem(item.getJID(), true);
// Forward set packet to the subscriber
if (localServer.isLocal(recipient)) {
// Recipient is local so let's handle it here
try {
Roster recipientRoster = userManager.getUser(recipient.getNode()).getRoster();
// Instead of deleting the sender in the recipient's roster, update it.
// http://issues.igniterealtime.org/browse/OF-720
RosterItem rosterItem = recipientRoster.getRosterItem(sender);
// If the receiver doesn't have subscribed yet, delete the sender from the receiver's roster, too.
if (rosterItem.getRecvStatus().equals(RosterItem.RECV_SUBSCRIBE)) {
recipientRoster.deleteRosterItem(sender, true);
} else // Otherwise only update it, so that the sender is not deleted from the receivers roster.
{
rosterItem.setAskStatus(RosterItem.ASK_NONE);
rosterItem.setRecvStatus(RosterItem.RECV_NONE);
rosterItem.setSubStatus(RosterItem.SUB_NONE);
recipientRoster.updateRosterItem(rosterItem);
}
} catch (UserNotFoundException e) {
// Do nothing
}
} else {
// Recipient is remote so we just forward the packet to them
String serverDomain = localServer.getServerInfo().getXMPPDomain();
// Check if the recipient may be hosted by this server
if (!recipient.getDomain().contains(serverDomain)) {
// TODO Implete when s2s is implemented
} else {
Packet removePacket = createRemoveForward(sender, recipient);
router.route(removePacket);
}
}
return removedItem;
}
use of org.jivesoftware.openfire.roster.RosterItem in project Openfire by igniterealtime.
the class MSNSession method completedPendingContactAdd.
/**
* Completes the addition of groups to a new contact after the contact has been created.
*
* @param msnContact Contact that was added.
*/
public void completedPendingContactAdd(MsnContact msnContact) {
try {
Roster roster = getTransport().getRosterManager().getRoster(getJID().getNode());
Email contact = msnContact.getEmail();
JID contactJID = getTransport().convertIDToJID(contact.toString());
RosterItem item = roster.getRosterItem(contactJID);
getBuddyManager().storeBuddy(new MSNBuddy(getBuddyManager(), msnContact));
syncContactGroups(contact, item.getGroups());
} catch (UserNotFoundException e) {
Log.debug("MSN: Unable to find roster when adding pendingcontact for " + getJID());
}
}
use of org.jivesoftware.openfire.roster.RosterItem in project Openfire by igniterealtime.
the class MSNSession method completedPendingGroupAdd.
/**
* Completes the addition of a contact to a new group after the group has been created.
*
* @param msnGroup Group that was added.
*/
public void completedPendingGroupAdd(MsnGroup msnGroup) {
if (!msnPendingGroups.containsKey(msnGroup.getGroupName())) {
// Nothing to do, no pending.
return;
}
try {
Roster roster = getTransport().getRosterManager().getRoster(getJID().getNode());
for (Email contact : msnPendingGroups.get(msnGroup.getGroupName())) {
JID contactJID = getTransport().convertIDToJID(contact.toString());
RosterItem item = roster.getRosterItem(contactJID);
syncContactGroups(contact, item.getGroups());
}
} catch (UserNotFoundException e) {
Log.debug("MSN: Unable to find roster when adding pending group contacts for " + getJID());
}
}
Aggregations