summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-09-12 18:29:39 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-09-13 19:19:52 (GMT)
commitef1052bbdb315aaa1c6254098ea05638d9a25b2f (patch)
tree482277f649f6c0fc00027514ea8986861fe33437 /Swiften/Roster
parent3ae8cccfe9c6bfed5dda5f024a5cb046ccfc9793 (diff)
downloadswift-ef1052bbdb315aaa1c6254098ea05638d9a25b2f.zip
swift-ef1052bbdb315aaa1c6254098ea05638d9a25b2f.tar.bz2
Added presence notifier.
Diffstat (limited to 'Swiften/Roster')
-rw-r--r--Swiften/Roster/XMPPRoster.cpp13
-rw-r--r--Swiften/Roster/XMPPRoster.h63
2 files changed, 39 insertions, 37 deletions
diff --git a/Swiften/Roster/XMPPRoster.cpp b/Swiften/Roster/XMPPRoster.cpp
index 28b04c6..56616c2 100644
--- a/Swiften/Roster/XMPPRoster.cpp
+++ b/Swiften/Roster/XMPPRoster.cpp
@@ -8,6 +8,9 @@
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);
@@ -43,8 +46,14 @@ 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())].name;
+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) {
diff --git a/Swiften/Roster/XMPPRoster.h b/Swiften/Roster/XMPPRoster.h
index e449d28..abafdfe 100644
--- a/Swiften/Roster/XMPPRoster.h
+++ b/Swiften/Roster/XMPPRoster.h
@@ -4,8 +4,7 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFTEN_XMPPRoster_H
-#define SWIFTEN_XMPPRoster_H
+#pragma once
#include "Swiften/Base/String.h"
#include "Swiften/JID/JID.h"
@@ -16,37 +15,31 @@
#include "Swiften/Base/boost_bsignals.h"
namespace Swift {
-
-struct XMPPRosterItem {
- JID jid;
- String name;
- std::vector<String> groups;
- RosterItemPayload::Subscription subscription;
-};
-
-class XMPPRoster {
- public:
- XMPPRoster() {};
- ~XMPPRoster() {};
-
- void addContact(const JID& jid, const String& name, const std::vector<String>& groups, const RosterItemPayload::Subscription subscription);
- bool containsJID(const JID& jid);
- void removeContact(const JID& jid);
- void clear();
- RosterItemPayload::Subscription getSubscriptionStateForJID(const JID& jid);
- const String& getNameForJID(const JID& jid);
- const std::vector<String>& getGroupsForJID(const JID& jid);
-
- boost::signal<void (const JID&)> onJIDAdded;
- boost::signal<void (const JID&)> onJIDRemoved;
- boost::signal<void (const JID&, const String&, const std::vector<String>&)> onJIDUpdated;
- boost::signal<void ()> onRosterCleared;
-
- private:
- //std::map<JID, std::pair<String, std::vector<String> > > entries_;
- std::map<JID, XMPPRosterItem> entries_;
-};
+ class XMPPRoster {
+ public:
+ XMPPRoster();
+
+ void addContact(const JID& jid, const String& name, const std::vector<String>& groups, const RosterItemPayload::Subscription subscription);
+ void removeContact(const JID& jid);
+ void clear();
+
+ bool containsJID(const JID& jid);
+ RosterItemPayload::Subscription getSubscriptionStateForJID(const JID& jid);
+ String getNameForJID(const JID& jid) const;
+ const std::vector<String>& getGroupsForJID(const JID& jid);
+
+ boost::signal<void (const JID&)> onJIDAdded;
+ boost::signal<void (const JID&)> onJIDRemoved;
+ boost::signal<void (const JID&, const String&, const std::vector<String>&)> onJIDUpdated;
+ boost::signal<void ()> onRosterCleared;
+
+ private:
+ struct XMPPRosterItem {
+ JID jid;
+ String name;
+ std::vector<String> groups;
+ RosterItemPayload::Subscription subscription;
+ };
+ std::map<JID, XMPPRosterItem> entries_;
+ };
}
-
-#endif
-