From c2dc47077e505ba1d45f203772dc6aa4f26656e4 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sat, 9 Jul 2011 11:42:47 +0100 Subject: Remember status type for chat list items. Resolves: #905 diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index a2abbad..0efbdfd 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -132,7 +132,9 @@ void ChatsManager::loadRecents() { std::string activity(recent[1]); bool isMUC = recent[2] == "true"; std::string nick(recent[3]); - ChatListWindow::Chat chat(jid, nickResolver_->jidToNick(jid), activity, 0, isMUC, nick); + Presence::ref presence = presenceOracle_->getHighestPriorityPresence(jid.toBare()); + StatusShow::Type type = presence ? presence->getShow() : StatusShow::None; + ChatListWindow::Chat chat(jid, nickResolver_->jidToNick(jid), activity, 0, type, isMUC, nick); prependRecent(chat); } handleUnreadCountChanged(NULL); @@ -177,7 +179,10 @@ ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const if (controller) { unreadCount = controller->getUnreadCount(); } - return ChatListWindow::Chat(jid, nickResolver_->jidToNick(jid), activity, unreadCount, false); + + Presence::ref presence = presenceOracle_->getHighestPriorityPresence(jid.toBare()); + StatusShow::Type type = presence ? presence->getShow() : StatusShow::None; + return ChatListWindow::Chat(jid, nickResolver_->jidToNick(jid), activity, unreadCount, type, false); } void ChatsManager::handleChatActivity(const JID& jid, const std::string& activity) { @@ -265,6 +270,16 @@ void ChatsManager::handleUIEvent(boost::shared_ptr event) { */ void ChatsManager::handlePresenceChange(boost::shared_ptr newPresence) { if (mucRegistry_->isMUC(newPresence->getFrom().toBare())) return; + + foreach (ChatListWindow::Chat& chat, recentChats_) { + if (newPresence->getFrom().toBare() == chat.jid.toBare()) { + Presence::ref presence = presenceOracle_->getHighestPriorityPresence(chat.jid.toBare()); + chat.setStatusType(presence ? presence->getShow() : StatusShow::None); + chatListWindow_->setRecents(recentChats_); + break; + } + } + //if (newPresence->getType() != Presence::Unavailable) return; JID fullJID(newPresence->getFrom()); std::map::iterator it = chatControllers_.find(fullJID); diff --git a/Swift/Controllers/UIInterfaces/ChatListWindow.h b/Swift/Controllers/UIInterfaces/ChatListWindow.h index 477de04..94d400d 100644 --- a/Swift/Controllers/UIInterfaces/ChatListWindow.h +++ b/Swift/Controllers/UIInterfaces/ChatListWindow.h @@ -9,16 +9,17 @@ #include #include #include +#include -#include "Swiften/Base/boost_bsignals.h" +#include namespace Swift { class ChatListWindow { public: class Chat { public: - Chat(const JID& jid, const std::string& chatName, const std::string& activity, int unreadCount, bool isMUC, const std::string& nick = "") - : jid(jid), chatName(chatName), activity(activity), isMUC(isMUC), nick(nick), unreadCount(unreadCount) {} + Chat(const JID& jid, const std::string& chatName, const std::string& activity, int unreadCount, StatusShow::Type statusType, bool isMUC, const std::string& nick = "") + : jid(jid), chatName(chatName), activity(activity), statusType(statusType), isMUC(isMUC), nick(nick), unreadCount(unreadCount) {} /** Assume that nicks and other transient features aren't important for equality */ bool operator==(const Chat& other) const { return jid.toBare() == other.jid.toBare() @@ -27,9 +28,13 @@ namespace Swift { void setUnreadCount(int unread) { unreadCount = unread; } + void setStatusType(StatusShow::Type type) { + statusType = type; + } JID jid; std::string chatName; std::string activity; + StatusShow::Type statusType; bool isMUC; std::string nick; int unreadCount; -- cgit v0.10.2-6-g49f6