001/**
002 *
003 * Copyright 2003-2007 Jive Software.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.jivesoftware.smack.roster;
019
020import java.util.Collection;
021
022import org.jivesoftware.smack.packet.Presence;
023
024import org.jxmpp.jid.Jid;
025
026/**
027 * A listener that is fired any time a roster is changed or the presence of
028 * a user in the roster is changed.
029 *
030 * @see Roster#addRosterListener(RosterListener)
031 * @author Matt Tucker
032 */
033public interface RosterListener {
034
035    /**
036     * Called when roster entries are added.
037     *
038     * @param addresses the XMPP addresses of the contacts that have been added to the roster.
039     */
040    void entriesAdded(Collection<Jid> addresses);
041
042    /**
043     * Called when a roster entries are updated.
044     *
045     * @param addresses the XMPP addresses of the contacts whose entries have been updated.
046     */
047    void entriesUpdated(Collection<Jid> addresses);
048
049    /**
050     * Called when a roster entries are removed.
051     *
052     * @param addresses the XMPP addresses of the contacts that have been removed from the roster.
053     */
054    void entriesDeleted(Collection<Jid> addresses);
055
056    /**
057     * Called when the presence of a roster entry is changed. Care should be taken
058     * when using the presence data delivered as part of this event. Specifically,
059     * when a user account is online with multiple resources, the UI should account
060     * for that. For example, say a user is online with their desktop computer and
061     * mobile phone. If the user logs out of the IM client on their mobile phone, the
062     * user should not be shown in the roster (contact list) as offline since they're
063     * still available as another resource.<p>
064     *
065     * To get the current "best presence" for a user after the presence update, query the roster:
066     * <pre>
067     *    String user = presence.getFrom();
068     *    Presence bestPresence = roster.getPresence(user);
069     * </pre>
070     *
071     * That will return the presence value for the user with the highest priority and
072     * availability.
073     *
074     * Note that this listener is triggered for presence (mode) changes only
075     * (e.g presence of types available and unavailable. Subscription-related
076     * presence packets will not cause this method to be called.
077     *
078     * @param presence the presence that changed.
079     * @see Roster#getPresence(org.jxmpp.jid.BareJid)
080     */
081    void presenceChanged(Presence presence);
082}