From 52cc4918673a80739ae67c99943273339e848458 Mon Sep 17 00:00:00 2001 From: Kevin Smith <git@kismith.co.uk> Date: Sat, 1 Jan 2011 00:33:24 +0000 Subject: Use the PresenceOracle for getting chat window presence lines. Now instead of having its own logic for listening to presence updates, it checks if it's the same full JID, if the controller is bound, else it looks for changes in the highest priority resource. Combined with the previous commit, hopefully: Resolves: #718 diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp index 90764ae..e4a76fa 100644 --- a/Swift/Controllers/Chat/ChatController.cpp +++ b/Swift/Controllers/Chat/ChatController.cpp @@ -50,6 +50,7 @@ ChatController::ChatController(const JID& self, StanzaChannel* stanzaChannel, IQ if (theirPresence && !theirPresence->getStatus().isEmpty()) { startMessage += " (" + theirPresence->getStatus() + ")"; } + lastShownStatus_ = theirPresence ? theirPresence->getShow() : StatusShow::None; chatStateNotifier_->setContactIsOnline(theirPresence && theirPresence->getType() == Presence::Available); startMessage += "."; chatWindow_->addSystemMessage(startMessage); @@ -148,7 +149,7 @@ String ChatController::senderDisplayNameFromMessage(const JID& from) { String ChatController::getStatusChangeString(boost::shared_ptr<Presence> presence) { String nick = senderDisplayNameFromMessage(presence->getFrom()); String response = nick; - if (presence->getType() == Presence::Unavailable || presence->getType() == Presence::Error) { + if (!presence || presence->getType() == Presence::Unavailable || presence->getType() == Presence::Error) { response += " has gone offline"; } else if (presence->getType() == Presence::Available) { StatusShow::Type show = presence->getShow(); @@ -167,11 +168,19 @@ String ChatController::getStatusChangeString(boost::shared_ptr<Presence> presenc } void ChatController::handlePresenceChange(boost::shared_ptr<Presence> newPresence) { - if ((!toJID_.equals(newPresence->getFrom(), toJID_.isBare() ? JID::WithoutResource : JID::WithResource)) - || - (newPresence->getType() != Presence::Available && newPresence->getType() != Presence::Unavailable && newPresence->getType() != Presence::Error)) { + bool me = false; + if (toJID_.isBare()) { + newPresence = presenceOracle_->getHighestPriorityPresence(toJID_); + if ((newPresence ? newPresence->getShow() : StatusShow::None) != lastShownStatus_) { + me = true; + } + } else if (toJID_.equals(newPresence->getFrom(), JID::WithResource)) { + me = true; + } + if (!me) { return; } + lastShownStatus_ = newPresence->getShow(); chatStateTracker_->handlePresenceChange(newPresence); chatStateNotifier_->setContactIsOnline(newPresence->getType() == Presence::Available); diff --git a/Swift/Controllers/Chat/ChatController.h b/Swift/Controllers/Chat/ChatController.h index f9c686b..c013387 100644 --- a/Swift/Controllers/Chat/ChatController.h +++ b/Swift/Controllers/Chat/ChatController.h @@ -43,6 +43,7 @@ namespace Swift { bool lastWasPresence_; String lastStatusChangeString_; std::map<boost::shared_ptr<Stanza>, String> unackedStanzas_; + StatusShow::Type lastShownStatus_; }; } -- cgit v0.10.2-6-g49f6