diff options
| author | Remko Tronçon <git@el-tramo.be> | 2010-10-24 12:10:44 (GMT) | 
|---|---|---|
| committer | Remko Tronçon <git@el-tramo.be> | 2010-10-24 12:15:24 (GMT) | 
| commit | b107bdd08df9ae3a978ad8f966a26eb8d551bd13 (patch) | |
| tree | ad1c4d6550f323a19dffd699c98513aa68acddaf /Swiften/Roster/XMPPRosterImpl.cpp | |
| parent | cfa314bd0b6f6ed9285c7167948899184f6a8c12 (diff) | |
| download | swift-b107bdd08df9ae3a978ad8f966a26eb8d551bd13.zip swift-b107bdd08df9ae3a978ad8f966a26eb8d551bd13.tar.bz2  | |
Creating abstract XMPPRoster base class.
Diffstat (limited to 'Swiften/Roster/XMPPRosterImpl.cpp')
| -rw-r--r-- | Swiften/Roster/XMPPRosterImpl.cpp | 68 | 
1 files changed, 68 insertions, 0 deletions
diff --git a/Swiften/Roster/XMPPRosterImpl.cpp b/Swiften/Roster/XMPPRosterImpl.cpp new file mode 100644 index 0000000..762ae29 --- /dev/null +++ b/Swiften/Roster/XMPPRosterImpl.cpp @@ -0,0 +1,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/XMPPRosterImpl.h" + +namespace Swift { + +XMPPRosterImpl::XMPPRosterImpl() { +} + +void XMPPRosterImpl::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 XMPPRosterImpl::removeContact(const JID& jid) { +	entries_.erase(JID(jid.toBare())); +	onJIDRemoved(jid); +} + +void XMPPRosterImpl::clear() { +	entries_.clear(); +	onRosterCleared(); +} + +bool XMPPRosterImpl::containsJID(const JID& jid) { +	return entries_.find(JID(jid.toBare())) != entries_.end(); +} + +String XMPPRosterImpl::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>& XMPPRosterImpl::getGroupsForJID(const JID& jid) { +	return entries_[JID(jid.toBare())].groups; +} + +RosterItemPayload::Subscription XMPPRosterImpl::getSubscriptionStateForJID(const JID& jid) { +	return entries_[JID(jid.toBare())].subscription; +} + +} +  | 
 Swift