From 4222febfac52106ae4a208228fbe269c0c28679c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20Badea?= Date: Thu, 16 Aug 2012 23:41:51 +0300 Subject: Improve presence handling in the history dialog. diff --git a/Swift/Controllers/HistoryViewController.cpp b/Swift/Controllers/HistoryViewController.cpp index 21eb9eb..f32447d 100644 --- a/Swift/Controllers/HistoryViewController.cpp +++ b/Swift/Controllers/HistoryViewController.cpp @@ -179,7 +179,7 @@ void HistoryViewController::handleReturnPressed(const std::string& keyword) { } roster_->addContact(jid, jid, nick, category[type], avatarManager_->getAvatarPath(jid).string()); - Presence::ref presence = presenceOracle_->getHighestPriorityPresence(jid); + Presence::ref presence = getPresence(jid, type == HistoryMessage::Groupchat); if (presence.get()) { roster_->applyOnItem(SetPresence(presence, JID::WithoutResource), jid); @@ -306,8 +306,15 @@ void HistoryViewController::handleCalendarClicked(const boost::gregorian::date& void HistoryViewController::handlePresenceChanged(Presence::ref presence) { JID jid = presence->getFrom(); - if (contacts_[HistoryMessage::Chat].count(jid)) { + if (contacts_[HistoryMessage::Chat].count(jid.toBare())) { roster_->applyOnItems(SetPresence(presence, JID::WithoutResource)); + return; + } + + if (contacts_[HistoryMessage::Groupchat].count(jid.toBare())) { + Presence::ref availablePresence = boost::make_shared(Presence()); + availablePresence->setFrom(jid.toBare()); + roster_->applyOnItems(SetPresence(availablePresence, JID::WithResource)); } if (contacts_[HistoryMessage::PrivateMessage].count(jid)) { @@ -320,4 +327,26 @@ void HistoryViewController::handleAvatarChanged(const JID& jid) { roster_->applyOnItems(SetAvatar(jid, path)); } +Presence::ref HistoryViewController::getPresence(const JID& jid, bool isMUC) { + if (jid.isBare() && !isMUC) { + return presenceOracle_->getHighestPriorityPresence(jid); + } + + std::vector mucPresence = presenceOracle_->getAllPresence(jid.toBare()); + + if (isMUC && !mucPresence.empty()) { + Presence::ref presence = boost::make_shared(Presence()); + presence->setFrom(jid); + return presence; + } + + foreach (Presence::ref presence, mucPresence) { + if (presence.get() && presence->getFrom() == jid) { + return presence; + } + } + + return Presence::create(); +} + } diff --git a/Swift/Controllers/HistoryViewController.h b/Swift/Controllers/HistoryViewController.h index 6ee94d9..283254d 100644 --- a/Swift/Controllers/HistoryViewController.h +++ b/Swift/Controllers/HistoryViewController.h @@ -47,6 +47,7 @@ namespace Swift { void addNewMessage(const HistoryMessage& message, bool addAtTheTop); void reset(); + Presence::ref getPresence(const JID& jid, bool isMUC); private: JID selfJID_; -- cgit v0.10.2-6-g49f6