summaryrefslogtreecommitdiffstats
blob: 676e8f9f4e7c9ca284ccec46db3ee3d3fe4e9b84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * Copyright (c) 2010 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#pragma once

#include <boost/optional.hpp>
#include <vector>
#include <set>
#include "Swiften/Base/boost_bsignals.h"

#include "Swiften/Base/String.h"
#include "Swiften/JID/JID.h"
#include "Swiften/Elements/RosterItemPayload.h"
#include <Swiften/Roster/XMPPRosterItem.h>

namespace Swift {
	/**
	 * This class represents the roster of an account, as stored on the XMPP server.
	 *
	 * Changes to the roster (either due to subscription requests or by going online/offline) are
	 * emitted through signals.
	 */
	class XMPPRoster {
		public:
			XMPPRoster();
			virtual ~XMPPRoster();

			/**
			 * Checks whether the bare jid of the given jid is in the roster.
			 */
			virtual bool containsJID(const JID& jid) = 0;

			/**
			 * Retrieves the subscription state for the given jid.
			 */
			virtual RosterItemPayload::Subscription getSubscriptionStateForJID(const JID& jid) = 0;

			/**
			 * Retrieves the stored roster name for the given jid.
			 */
			virtual String getNameForJID(const JID& jid) const = 0;

			/**
			 * Returns the list of groups for the given JID.
			 */
			virtual std::vector<String> getGroupsForJID(const JID& jid) = 0;

			/**
			 * Retrieve the items in the roster.
			 */
			virtual std::vector<XMPPRosterItem> getItems() const = 0;

			/**
			 * Retrieve the item with the given JID.
			 */
			virtual boost::optional<XMPPRosterItem> getItem(const JID&) const = 0;

			/**
			 * Retrieve the list of (existing) groups.
			 */
			virtual std::set<String> getGroups() const = 0;

		public:
			/**
			 * Emitted when the given JID is added to the roster.
			 */
			boost::signal<void (const JID&)> onJIDAdded;

			/**
			 * Emitted when the given JID is removed from the roster.
			 */
			boost::signal<void (const JID&)> onJIDRemoved;

			/**
			 * Emitted when the name or the groups of the roster item with the
			 * given JID changes.
			 */
			boost::signal<void (const JID&, const String&, const std::vector<String>&)> onJIDUpdated;

			/**
			 * Emitted when the roster is reset (e.g. due to logging in/logging out).
			 * After this signal is emitted, the roster is empty. It will be repopulated through
			 * onJIDAdded and onJIDRemoved events.
			 */
			boost::signal<void ()> onRosterCleared;
	};
}