diff options
author | Kevin Smith <git@kismith.co.uk> | 2010-03-22 20:37:30 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2010-03-22 20:37:30 (GMT) |
commit | 0c377fa93ffd8538da9e71ddc71d4e8c07600a22 (patch) | |
tree | fa655b09f94cdb9018bfad4aa1de3dba2d345969 /Swiften | |
parent | 1ebd045cadb3585c846ea38c63d508e5aa6ec1e7 (diff) | |
download | swift-0c377fa93ffd8538da9e71ddc71d4e8c07600a22.zip swift-0c377fa93ffd8538da9e71ddc71d4e8c07600a22.tar.bz2 |
Can now accept roster subscriptions.
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Presence/PresenceOracle.cpp | 26 | ||||
-rw-r--r-- | Swiften/Presence/PresenceOracle.h | 4 | ||||
-rw-r--r-- | Swiften/Roster/XMPPRoster.cpp | 22 | ||||
-rw-r--r-- | Swiften/Roster/XMPPRoster.h | 14 |
4 files changed, 56 insertions, 10 deletions
diff --git a/Swiften/Presence/PresenceOracle.cpp b/Swiften/Presence/PresenceOracle.cpp index d7239df..988fc10 100644 --- a/Swiften/Presence/PresenceOracle.cpp +++ b/Swiften/Presence/PresenceOracle.cpp @@ -8,9 +8,33 @@ typedef std::pair<JID, std::map<JID, boost::shared_ptr<Presence> > > JIDMapPair; typedef std::pair<JID, boost::shared_ptr<Presence> > JIDPresencePair; PresenceOracle::PresenceOracle(StanzaChannel* stanzaChannel) { - stanzaChannel->onPresenceReceived.connect(boost::bind(&PresenceOracle::handleIncomingPresence, this, _1)); + stanzaChannel_ = stanzaChannel; + stanzaChannel_->onPresenceReceived.connect(boost::bind(&PresenceOracle::handleIncomingPresence, this, _1)); } +void PresenceOracle::cancelSubscription(const JID& jid) { + boost::shared_ptr<Presence> stanza(new Presence()); + stanza->setType(Presence::Unsubscribed); + stanza->setTo(jid); + stanzaChannel_->sendPresence(stanza); +} + +void PresenceOracle::confirmSubscription(const JID& jid) { + boost::shared_ptr<Presence> stanza(new Presence()); + stanza->setType(Presence::Subscribed); + stanza->setTo(jid); + stanzaChannel_->sendPresence(stanza); +} + + +void PresenceOracle::requestSubscription(const JID& jid) { + boost::shared_ptr<Presence> stanza(new Presence()); + stanza->setType(Presence::Subscribe); + stanza->setTo(jid); + stanzaChannel_->sendPresence(stanza); +} + + void PresenceOracle::handleIncomingPresence(boost::shared_ptr<Presence> presence) { JID bareJID = JID(presence->getFrom().toBare()); diff --git a/Swiften/Presence/PresenceOracle.h b/Swiften/Presence/PresenceOracle.h index 320a999..dc6fe5d 100644 --- a/Swiften/Presence/PresenceOracle.h +++ b/Swiften/Presence/PresenceOracle.h @@ -14,6 +14,10 @@ class PresenceOracle { PresenceOracle(StanzaChannel* stanzaChannel); ~PresenceOracle() {}; + void cancelSubscription(const JID& jid); + void confirmSubscription(const JID& jid); + void requestSubscription(const JID& jid); + boost::signal<void (boost::shared_ptr<Presence>, boost::shared_ptr<Presence>)> onPresenceChange; boost::signal<void (const JID&, const String&)> onPresenceSubscriptionRequest; diff --git a/Swiften/Roster/XMPPRoster.cpp b/Swiften/Roster/XMPPRoster.cpp index a5cccaf..62edc45 100644 --- a/Swiften/Roster/XMPPRoster.cpp +++ b/Swiften/Roster/XMPPRoster.cpp @@ -2,17 +2,21 @@ namespace Swift { -void XMPPRoster::addContact(const JID& jid, const String& name, const std::vector<String>& groups) { +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); } - String oldName = getNameForJID(bareJID); - std::vector<String> oldGroups = entries_[bareJID].second; - entries_[bareJID] = std::pair<String, std::vector<String> >(name, groups); + 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); @@ -29,11 +33,15 @@ bool XMPPRoster::containsJID(const JID& jid) { } const String& XMPPRoster::getNameForJID(const JID& jid) { - return entries_[JID(jid.toBare())].first; + return entries_[JID(jid.toBare())].name; } const std::vector<String>& XMPPRoster::getGroupsForJID(const JID& jid) { - return entries_[JID(jid.toBare())].second; + return entries_[JID(jid.toBare())].groups; +} + +RosterItemPayload::Subscription XMPPRoster::getSubscriptionStateForJID(const JID& jid) { + return entries_[JID(jid.toBare())].subscription; } } diff --git a/Swiften/Roster/XMPPRoster.h b/Swiften/Roster/XMPPRoster.h index 7a72e00..47326c3 100644 --- a/Swiften/Roster/XMPPRoster.h +++ b/Swiften/Roster/XMPPRoster.h @@ -3,6 +3,7 @@ #include "Swiften/Base/String.h" #include "Swiften/JID/JID.h" +#include "Swiften/Elements/RosterItemPayload.h" #include <map> #include <vector> @@ -10,14 +11,22 @@ 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); + 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); + RosterItemPayload::Subscription getSubscriptionStateForJID(const JID& jid); const String& getNameForJID(const JID& jid); const std::vector<String>& getGroupsForJID(const JID& jid); @@ -26,7 +35,8 @@ class XMPPRoster { boost::signal<void (const JID&, const String&, const std::vector<String>&)> onJIDUpdated; private: - std::map<JID, std::pair<String, std::vector<String> > > entries_; + //std::map<JID, std::pair<String, std::vector<String> > > entries_; + std::map<JID, XMPPRosterItem> entries_; }; } |