diff options
-rw-r--r-- | Swift/Controllers/HistoryViewController.cpp | 33 | ||||
-rw-r--r-- | Swift/Controllers/HistoryViewController.h | 1 |
2 files changed, 32 insertions, 2 deletions
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>(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<Presence::ref> mucPresence = presenceOracle_->getAllPresence(jid.toBare()); + + if (isMUC && !mucPresence.empty()) { + Presence::ref presence = boost::make_shared<Presence>(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_; |