summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-10-24 12:17:55 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-10-24 13:06:26 (GMT)
commit0f078be02cd6818aeacc935a1ab790b41267a00d (patch)
treeacf7c1a08769c8332ccf9e07b00c48cf83f24172 /Swiften/Presence
parentb107bdd08df9ae3a978ad8f966a26eb8d551bd13 (diff)
downloadswift-contrib-0f078be02cd6818aeacc935a1ab790b41267a00d.zip
swift-contrib-0f078be02cd6818aeacc935a1ab790b41267a00d.tar.bz2
Use the highest priority for a contact's roster item, not the newest.
Resolves: #654 Release-Notes: Contacts online from several clients at once should now show the highest priority presence, not the most recent.
Diffstat (limited to 'Swiften/Presence')
-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);