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 org.jivesoftware.smack.packet.Presence;
021import org.jxmpp.jid.Jid;
022
023import java.util.Collection;
024
025/**
026 * A listener that is fired any time a roster is changed or the presence of
027 * a user in the roster is changed.
028 * 
029 * @see Roster#addRosterListener(RosterListener)
030 * @author Matt Tucker
031 */
032public interface RosterListener {
033
034    /**
035     * Called when roster entries are added.
036     *
037     * @param addresses the XMPP addresses of the contacts that have been added to the roster.
038     */
039    public void entriesAdded(Collection<Jid> addresses);
040
041    /**
042     * Called when a roster entries are updated.
043     *
044     * @param addresses the XMPP addresses of the contacts whose entries have been updated.
045     */
046    public void entriesUpdated(Collection<Jid> addresses);
047
048    /**
049     * Called when a roster entries are removed.
050     *
051     * @param addresses the XMPP addresses of the contacts that have been removed from the roster.
052     */
053    public void entriesDeleted(Collection<Jid> addresses);
054
055    /**
056     * Called when the presence of a roster entry is changed. Care should be taken
057     * when using the presence data delivered as part of this event. Specifically,
058     * when a user account is online with multiple resources, the UI should account
059     * for that. For example, say a user is online with their desktop computer and
060     * mobile phone. If the user logs out of the IM client on their mobile phone, the
061     * user should not be shown in the roster (contact list) as offline since they're
062     * still available as another resource.<p>
063     *
064     * To get the current "best presence" for a user after the presence update, query the roster:
065     * <pre>
066     *    String user = presence.getFrom();
067     *    Presence bestPresence = roster.getPresence(user);
068     * </pre>
069     *
070     * That will return the presence value for the user with the highest priority and
071     * availability.
072     *
073     * Note that this listener is triggered for presence (mode) changes only
074     * (e.g presence of types available and unavailable. Subscription-related
075     * presence packets will not cause this method to be called.
076     *
077     * @param presence the presence that changed.
078     * @see Roster#getPresence(org.jxmpp.jid.BareJid)
079     */
080    public void presenceChanged(Presence presence);
081}