summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Presence/PresenceOracle.cpp28
-rw-r--r--Swiften/Presence/PresenceOracle.h1
2 files changed, 22 insertions, 7 deletions
diff --git a/Swiften/Presence/PresenceOracle.cpp b/Swiften/Presence/PresenceOracle.cpp
index 439a84d..83bbbf7 100644
--- a/Swiften/Presence/PresenceOracle.cpp
+++ b/Swiften/Presence/PresenceOracle.cpp
@@ -30,17 +30,31 @@ void PresenceOracle::handleStanzaChannelAvailableChanged(bool available) {
}
-void PresenceOracle::handleIncomingPresence(boost::shared_ptr<Presence> presence) {
- JID bareJID = JID(presence->getFrom().toBare());
-
+void PresenceOracle::handleIncomingPresence(Presence::ref presence) {
+ JID bareJID(presence->getFrom().toBare());
if (presence->getType() == Presence::Subscribe) {
onPresenceSubscriptionRequest(bareJID, presence->getStatus());
- }
- else {
+ } else {
+ Presence::ref passedPresence = presence;
+ if (presence->getType() == Presence::Unsubscribe) {
+ /* 3921bis says that we don't follow up with an unavailable, so simulate this ourselves */
+ onPresenceSubscriptionRevoked(bareJID, presence->getStatus());
+ passedPresence = Presence::ref(new Presence());
+ passedPresence->setType(Presence::Unavailable);
+ passedPresence->setFrom(bareJID);
+ passedPresence->setStatus(presence->getStatus());
+ }
std::map<JID, boost::shared_ptr<Presence> > jidMap = entries_[bareJID];
- jidMap[presence->getFrom()] = presence;
+ if (passedPresence->getFrom().isBare() && presence->getType() == Presence::Unavailable) {
+ /* Have a bare-JID only presence of offline */
+ jidMap.clear();
+ } else if (passedPresence->getType() == Presence::Available) {
+ /* Don't have a bare-JID only offline presence once there are available presences */
+ jidMap.erase(bareJID);
+ }
+ jidMap[passedPresence->getFrom()] = passedPresence;
entries_[bareJID] = jidMap;
- onPresenceChange(presence);
+ onPresenceChange(passedPresence);
}
}
diff --git a/Swiften/Presence/PresenceOracle.h b/Swiften/Presence/PresenceOracle.h
index 8c4fce4..b0d1e15 100644
--- a/Swiften/Presence/PresenceOracle.h
+++ b/Swiften/Presence/PresenceOracle.h
@@ -26,6 +26,7 @@ class StanzaChannel;
public:
boost::signal<void (boost::shared_ptr<Presence>)> onPresenceChange;
boost::signal<void (const JID&, const String&)> onPresenceSubscriptionRequest;
+ boost::signal<void (const JID&, const String&)> onPresenceSubscriptionRevoked;
private:
void handleIncomingPresence(boost::shared_ptr<Presence> presence);