Search in sources :

Example 11 with RosterItem

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);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Roster(org.jivesoftware.openfire.roster.Roster)

Example 12 with RosterItem

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();
        }
    }
}
Also used : RosterItem(org.jivesoftware.openfire.roster.RosterItem) Roster(org.jivesoftware.openfire.roster.Roster) Presence(org.xmpp.packet.Presence) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException)

Example 13 with RosterItem

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;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Packet(org.xmpp.packet.Packet) JID(org.xmpp.packet.JID) Roster(org.jivesoftware.openfire.roster.Roster)

Example 14 with RosterItem

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());
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Email(net.sf.jml.Email) Roster(org.jivesoftware.openfire.roster.Roster) JID(org.xmpp.packet.JID)

Example 15 with RosterItem

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());
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Email(net.sf.jml.Email) Roster(org.jivesoftware.openfire.roster.Roster) JID(org.xmpp.packet.JID)

Aggregations

RosterItem (org.jivesoftware.openfire.roster.RosterItem)37 Roster (org.jivesoftware.openfire.roster.Roster)27 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)26 JID (org.xmpp.packet.JID)18 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)11 ArrayList (java.util.ArrayList)10 Element (org.dom4j.Element)8 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)6 User (org.jivesoftware.openfire.user.User)5 StringTokenizer (java.util.StringTokenizer)4 IQ (org.xmpp.packet.IQ)4 StringprepException (gnu.inet.encoding.StringprepException)3 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)3 ParseException (java.text.ParseException)2 Email (net.sf.jml.Email)2 DefaultElement (org.dom4j.tree.DefaultElement)2 XMPPServer (org.jivesoftware.openfire.XMPPServer)2 Group (org.jivesoftware.openfire.group.Group)2 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)2 UserManager (org.jivesoftware.openfire.user.UserManager)2