blob: 56616c237215c4eddabcf94b82f4d75b87e912c8 (
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
|
/*
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include "Swiften/Roster/XMPPRoster.h"
namespace Swift {
XMPPRoster::XMPPRoster() {
}
void XMPPRoster::addContact(const JID& jid, const String& name, const std::vector<String>& groups, RosterItemPayload::Subscription subscription) {
JID bareJID(jid.toBare());
bool exists = containsJID(bareJID);
String oldName = getNameForJID(bareJID);
std::vector<String> oldGroups = entries_[bareJID].groups;
if (exists) {
entries_.erase(bareJID);
}
XMPPRosterItem item;
item.groups = groups;
item.name = name;
item.jid = jid;
item.subscription = subscription;
entries_[bareJID] = item;
if (exists) {
onJIDUpdated(bareJID, oldName, oldGroups);
} else {
onJIDAdded(bareJID);
}
}
void XMPPRoster::removeContact(const JID& jid) {
entries_.erase(JID(jid.toBare()));
onJIDRemoved(jid);
}
void XMPPRoster::clear() {
entries_.clear();
onRosterCleared();
}
bool XMPPRoster::containsJID(const JID& jid) {
return entries_.find(JID(jid.toBare())) != entries_.end();
}
String XMPPRoster::getNameForJID(const JID& jid) const {
std::map<JID, XMPPRosterItem>::const_iterator i = entries_.find(jid.toBare());
if (i != entries_.end()) {
return i->second.name;
}
else {
return "";
}
}
const std::vector<String>& XMPPRoster::getGroupsForJID(const JID& jid) {
return entries_[JID(jid.toBare())].groups;
}
RosterItemPayload::Subscription XMPPRoster::getSubscriptionStateForJID(const JID& jid) {
return entries_[JID(jid.toBare())].subscription;
}
}
|