summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Chat/ChatsManager.cpp')
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp56
1 files changed, 43 insertions, 13 deletions
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index 8a077d1..3db1327 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -226,2 +226,11 @@ void ChatsManager::saveRecents() {
+ class RemoveRecent {
+ public:
+ static bool ifPrivateMessage(const ChatListWindow::Chat& chat) {
+ return chat.isPrivateMessage;
+ }
+ };
+
+ recentsLimited.erase(std::remove_if(recentsLimited.begin(), recentsLimited.end(), RemoveRecent::ifPrivateMessage), recentsLimited.end());
+
oa << recentsLimited;
@@ -312,3 +321,3 @@ void ChatsManager::loadRecents() {
- ChatListWindow::Chat chat(jid, nickResolver_->jidToNick(jid), activity, 0, type, path, isMUC, nick);
+ ChatListWindow::Chat chat(jid, nickResolver_->jidToNick(jid), activity, 0, type, path, isMUC, false, nick);
chat = updateChatStatusAndAvatarHelper(chat);
@@ -370,3 +379,3 @@ void ChatsManager::handleMUCBookmarkRemoved(const MUCBookmark& bookmark) {
-ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const std::string& activity) {
+ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const std::string& activity, bool privateMessage) {
int unreadCount = 0;
@@ -389,3 +398,3 @@ ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const
if (controller->isImpromptu()) {
- ChatListWindow::Chat chat = ChatListWindow::Chat(jid, jid.toString(), activity, unreadCount, type, boost::filesystem::path(), true, nick, password);
+ ChatListWindow::Chat chat = ChatListWindow::Chat(jid, jid.toString(), activity, unreadCount, type, boost::filesystem::path(), true, privateMessage, nick, password);
typedef std::pair<std::string, JID> StringJIDPair;
@@ -396,3 +405,3 @@ ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const
}
- return ChatListWindow::Chat(jid, jid.toString(), activity, unreadCount, type, boost::filesystem::path(), true, nick, password);
+ return ChatListWindow::Chat(jid, jid.toString(), activity, unreadCount, type, boost::filesystem::path(), true, privateMessage, nick, password);
} else {
@@ -406,3 +415,3 @@ ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const
boost::filesystem::path avatarPath = avatarManager_ ? avatarManager_->getAvatarPath(bareishJID) : boost::filesystem::path();
- return ChatListWindow::Chat(bareishJID, nickResolver_->jidToNick(bareishJID), activity, unreadCount, type, avatarPath, false);
+ return ChatListWindow::Chat(bareishJID, nickResolver_->jidToNick(bareishJID), activity, unreadCount, type, avatarPath, false, privateMessage);
}
@@ -411,7 +420,4 @@ ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const
void ChatsManager::handleChatActivity(const JID& jid, const std::string& activity, bool isMUC) {
- if (mucRegistry_->isMUC(jid.toBare()) && !isMUC) {
- /* Don't include PMs in MUC rooms.*/
- return;
- }
- ChatListWindow::Chat chat = createChatListChatItem(jid, activity);
+ const bool privateMessage = mucRegistry_->isMUC(jid.toBare()) && !isMUC;
+ ChatListWindow::Chat chat = createChatListChatItem(jid, activity, privateMessage);
/* FIXME: handle nick changes */
@@ -422,2 +428,7 @@ void ChatsManager::handleChatActivity(const JID& jid, const std::string& activit
+void ChatsManager::handleChatClosed(const JID& /*jid*/) {
+ cleanupPrivateMessageRecents();
+ chatListWindow_->setRecents(recentChats_);
+}
+
void ChatsManager::handleUnreadCountChanged(ChatControllerBase* controller) {
@@ -456,2 +467,20 @@ boost::optional<ChatListWindow::Chat> ChatsManager::removeExistingChat(const Cha
+void ChatsManager::cleanupPrivateMessageRecents() {
+ /* if we leave a MUC and close a PM, remove it's recent chat entry */
+ const std::list<ChatListWindow::Chat> chats = recentChats_;
+ foreach (const ChatListWindow::Chat& chat, chats) {
+ if (chat.isPrivateMessage) {
+ typedef std::map<JID, MUCController*> ControllerMap;
+ ControllerMap::iterator muc = mucControllers_.find(chat.jid.toBare());
+ if (muc == mucControllers_.end() || !muc->second->isJoined()) {
+ ChatController* chatController = getChatControllerIfExists(chat.jid);
+ if (!chatController || !chatController->hasOpenWindow()) {
+ removeExistingChat(chat);
+ break;
+ }
+ }
+ }
+ }
+}
+
void ChatsManager::appendRecent(const ChatListWindow::Chat& chat) {
@@ -481,4 +510,2 @@ void ChatsManager::handleUserLeftMUC(MUCController* mucController) {
chat.statusType = StatusShow::None;
- chatListWindow_->setRecents(recentChats_);
- break;
}
@@ -487,5 +514,7 @@ void ChatsManager::handleUserLeftMUC(MUCController* mucController) {
delete mucController;
- return;
+ break;
}
}
+ cleanupPrivateMessageRecents();
+ chatListWindow_->setRecents(recentChats_);
}
@@ -703,2 +732,3 @@ ChatController* ChatsManager::createNewChatController(const JID& contact) {
controller->onActivity.connect(boost::bind(&ChatsManager::handleChatActivity, this, contact, _1, false));
+ controller->onWindowClosed.connect(boost::bind(&ChatsManager::handleChatClosed, this, contact));
controller->onUnreadCountChanged.connect(boost::bind(&ChatsManager::handleUnreadCountChanged, this, controller));