1/**
2 * $RCSfile$
3 * $Revision$
4 * $Date$
5 *
6 * Copyright 2003-2007 Jive Software.
7 *
8 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 *     http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21package org.jivesoftware.smack;
22
23import org.jivesoftware.smack.packet.Presence;
24
25import java.util.Collection;
26
27/**
28 * A listener that is fired any time a roster is changed or the presence of
29 * a user in the roster is changed.
30 *
31 * @see Roster#addRosterListener(RosterListener)
32 * @author Matt Tucker
33 */
34public interface RosterListener {
35
36    /**
37     * Called when roster entries are added.
38     *
39     * @param addresses the XMPP addresses of the contacts that have been added to the roster.
40     */
41    public void entriesAdded(Collection<String> addresses);
42
43    /**
44     * Called when a roster entries are updated.
45     *
46     * @param addresses the XMPP addresses of the contacts whose entries have been updated.
47     */
48    public void entriesUpdated(Collection<String> addresses);
49
50    /**
51     * Called when a roster entries are removed.
52     *
53     * @param addresses the XMPP addresses of the contacts that have been removed from the roster.
54     */
55    public void entriesDeleted(Collection<String> addresses);
56
57    /**
58     * Called when the presence of a roster entry is changed. Care should be taken
59     * when using the presence data delivered as part of this event. Specifically,
60     * when a user account is online with multiple resources, the UI should account
61     * for that. For example, say a user is online with their desktop computer and
62     * mobile phone. If the user logs out of the IM client on their mobile phone, the
63     * user should not be shown in the roster (contact list) as offline since they're
64     * still available as another resource.<p>
65     *
66     * To get the current "best presence" for a user after the presence update, query the roster:
67     * <pre>
68     *    String user = presence.getFrom();
69     *    Presence bestPresence = roster.getPresence(user);
70     * </pre>
71     *
72     * That will return the presence value for the user with the highest priority and
73     * availability.
74     *
75     * Note that this listener is triggered for presence (mode) changes only
76     * (e.g presence of types available and unavailable. Subscription-related
77     * presence packets will not cause this method to be called.
78     *
79     * @param presence the presence that changed.
80     * @see Roster#getPresence(String)
81     */
82    public void presenceChanged(Presence presence);
83}