Java Code Examples for org.jivesoftware.smack.roster.RosterEntry#getType()

The following examples show how to use org.jivesoftware.smack.roster.RosterEntry#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContactList.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the users presence.
 *
 * @param presence the user to update.
 * @throws Exception if there is a problem while updating the user's presence.
 */
private synchronized void updateUserPresence(Presence presence) throws Exception {
    if (presence.getError() != null) {
        // We ignore this.
        return;
    }

    final Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );

    final BareJid bareJID = presence.getFrom().asBareJid();

    RosterEntry entry = roster.getEntry(bareJID);
    boolean isPending = entry != null && (entry.getType() == RosterPacket.ItemType.none || entry.getType() == RosterPacket.ItemType.from)
        && entry.isSubscriptionPending();

    // If online, check to see if they are in the offline group.
    // If so, remove from offline group and add to all groups they
    // belong to.

    if (presence.getType() == Presence.Type.available && offlineGroup.getContactItemByJID(bareJID) != null || ( presence.getFrom().toString().contains( "workgroup." ) )) {
        changeOfflineToOnline(bareJID, entry, presence);
    }
    else if (presence.getType() == Presence.Type.available) {
        updateContactItemsPresence(presence, entry, bareJID);
    }
    else if (presence.getType() == Presence.Type.unavailable && !isPending) {
        // If not available, move to offline group.
        Presence rosterPresence = PresenceManager.getPresence(bareJID);
        if (!rosterPresence.isAvailable()) {
            moveToOfflineGroup(presence, bareJID);
        }
        else {
            updateContactItemsPresence(rosterPresence, entry, bareJID);
        }
    }
    
}
 
Example 2
Source File: ContactList.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a single user to the ContactList.
 *
 * @param entry the <code>RosterEntry</code> of the the user.
 */
private void addUser(RosterEntry entry) {
    ContactItem newContactItem = UIComponentRegistry.createContactItem(entry.getName(), null, entry.getJid());

    if (entry.getType() == RosterPacket.ItemType.none || entry.getType() == RosterPacket.ItemType.from) {
        // Ignore, since the new user is pending to be added.
        for (RosterGroup group : entry.getGroups()) {
            ContactGroup contactGroup = getContactGroup(group.getName());
            if (contactGroup == null) {
                contactGroup = addContactGroup(group.getName());
            }

            boolean isPending = entry.getType() == RosterPacket.ItemType.none || entry.getType() == RosterPacket.ItemType.from
                && entry.isSubscriptionPending();
            if (isPending) {
                contactGroup.setVisible(true);
            }
            contactGroup.addContactItem(newContactItem);

        }
        return;
    }
    else {
        moveToOffline(newContactItem);
    }

    // Update users icon
    Presence presence = Roster.getInstanceFor( SparkManager.getConnection() ).getPresence(entry.getJid());
    try {
        updateUserPresence(presence);
    }
    catch (Exception e) {
        Log.error(e);
    }
}
 
Example 3
Source File: KonRosterListener.java    From desktopclient-java with GNU General Public License v3.0 4 votes vote down vote up
private static ClientUtils.KonRosterEntry clientToModel(RosterEntry entry) {
    return new ClientUtils.KonRosterEntry(JID.fromSmack(entry.getJid()),
            StringUtils.defaultString(entry.getName()),
            entry.getType(),
            entry.isSubscriptionPending());
}