summaryrefslogtreecommitdiffstats
blob: a5cccafacad38d2130fa9d04b8936f5b4df08e77 (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
#include "Swiften/Roster/XMPPRoster.h"

namespace Swift {

void XMPPRoster::addContact(const JID& jid, const String& name, const std::vector<String>& groups) {
	JID bareJID(jid.toBare());
	bool exists = containsJID(bareJID);
	if (exists) {
		entries_.erase(bareJID);
	}
	String oldName = getNameForJID(bareJID);
	std::vector<String> oldGroups = entries_[bareJID].second;
	entries_[bareJID] = std::pair<String, std::vector<String> >(name, groups);
	if (exists) {
		
		onJIDUpdated(bareJID, oldName, oldGroups);
	} else {
		onJIDAdded(bareJID);
	}
}

void XMPPRoster::removeContact(const JID& jid) {
	entries_.erase(JID(jid.toBare()));
	onJIDRemoved(jid);
}

bool XMPPRoster::containsJID(const JID& jid) {
	return entries_.find(JID(jid.toBare())) != entries_.end();
}

const String& XMPPRoster::getNameForJID(const JID& jid) {
	return entries_[JID(jid.toBare())].first;
}

const std::vector<String>& XMPPRoster::getGroupsForJID(const JID& jid) {
	return entries_[JID(jid.toBare())].second;
}

}