diff options
| -rw-r--r-- | Swift/Controllers/Chat/ChatController.cpp | 5 | ||||
| -rw-r--r-- | Swift/Controllers/Chat/ChatController.h | 4 | ||||
| -rw-r--r-- | Swift/Controllers/Chat/ChatControllerBase.cpp | 4 | ||||
| -rw-r--r-- | Swift/Controllers/Chat/ChatControllerBase.h | 2 | ||||
| -rw-r--r-- | Swift/Controllers/Chat/ChatsManager.cpp | 56 | ||||
| -rw-r--r-- | Swift/Controllers/Chat/ChatsManager.h | 4 | ||||
| -rw-r--r-- | Swift/Controllers/UIInterfaces/ChatListWindow.h | 7 | ||||
| -rw-r--r-- | Swift/Controllers/UIInterfaces/ChatWindow.h | 1 | ||||
| -rw-r--r-- | Swift/Controllers/UnitTest/MockChatWindow.h | 1 | ||||
| -rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 4 | ||||
| -rw-r--r-- | Swift/QtUI/QtChatWindow.h | 1 |
11 files changed, 70 insertions, 19 deletions
diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp index 9df7708..9b65c9f 100644 --- a/Swift/Controllers/Chat/ChatController.cpp +++ b/Swift/Controllers/Chat/ChatController.cpp @@ -97,2 +97,3 @@ ChatController::ChatController(const JID& self, StanzaChannel* stanzaChannel, IQ chatWindow_->onInviteToChat.connect(boost::bind(&ChatController::handleInviteToChat, this, _1)); + chatWindow_->onClosed.connect(boost::bind(&ChatController::handleWindowClosed, this)); handleBareJIDCapsChanged(toJID_); @@ -308,2 +309,6 @@ void ChatController::handleInviteToChat(const std::vector<JID>& droppedJIDs) { +void ChatController::handleWindowClosed() { + onWindowClosed(); +} + void ChatController::handleUIEvent(boost::shared_ptr<UIEvent> event) { diff --git a/Swift/Controllers/Chat/ChatController.h b/Swift/Controllers/Chat/ChatController.h index 8b1bb9a..2e92be7 100644 --- a/Swift/Controllers/Chat/ChatController.h +++ b/Swift/Controllers/Chat/ChatController.h @@ -81,4 +81,4 @@ namespace Swift { void handleInviteToChat(const std::vector<JID>& droppedJIDs); - void handleInviteToMUCWindowDismissed(); - void handleInviteToMUCWindowCompleted(); + + void handleWindowClosed(); diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp index 5363e0c..24341e6 100644 --- a/Swift/Controllers/Chat/ChatControllerBase.cpp +++ b/Swift/Controllers/Chat/ChatControllerBase.cpp @@ -199,2 +199,6 @@ void ChatControllerBase::activateChatWindow() { +bool ChatControllerBase::hasOpenWindow() const { + return chatWindow_ && chatWindow_->isVisible(); +} + std::string ChatControllerBase::addMessage(const std::string& message, const std::string& senderName, bool senderIsSelf, const boost::shared_ptr<SecurityLabel> label, const boost::filesystem::path& avatarPath, const boost::posix_time::ptime& time, const HighlightAction& highlight) { diff --git a/Swift/Controllers/Chat/ChatControllerBase.h b/Swift/Controllers/Chat/ChatControllerBase.h index cf0a4d2..a0b848b 100644 --- a/Swift/Controllers/Chat/ChatControllerBase.h +++ b/Swift/Controllers/Chat/ChatControllerBase.h @@ -54,2 +54,3 @@ namespace Swift { void activateChatWindow(); + bool hasOpenWindow() const; virtual void setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info); @@ -64,2 +65,3 @@ namespace Swift { boost::signal<void ()> onUnreadCountChanged; + boost::signal<void ()> onWindowClosed; int getUnreadCount(); 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)); diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h index 41435d9..179f536 100644 --- a/Swift/Controllers/Chat/ChatsManager.h +++ b/Swift/Controllers/Chat/ChatsManager.h @@ -91,3 +91,3 @@ namespace Swift { private: - ChatListWindow::Chat createChatListChatItem(const JID& jid, const std::string& activity); + ChatListWindow::Chat createChatListChatItem(const JID& jid, const std::string& activity, bool privateMessage); void handleChatRequest(const std::string& contact); @@ -105,2 +105,3 @@ namespace Swift { void handleChatActivity(const JID& jid, const std::string& activity, bool isMUC); + void handleChatClosed(const JID& jid); void handleNewFileTransferController(FileTransferController*); @@ -109,2 +110,3 @@ namespace Swift { boost::optional<ChatListWindow::Chat> removeExistingChat(const ChatListWindow::Chat& chat); + void cleanupPrivateMessageRecents(); void appendRecent(const ChatListWindow::Chat& chat); diff --git a/Swift/Controllers/UIInterfaces/ChatListWindow.h b/Swift/Controllers/UIInterfaces/ChatListWindow.h index 38d8c3e..f7eb151 100644 --- a/Swift/Controllers/UIInterfaces/ChatListWindow.h +++ b/Swift/Controllers/UIInterfaces/ChatListWindow.h @@ -23,5 +23,5 @@ namespace Swift { public: - Chat() : statusType(StatusShow::None), isMUC(false), unreadCount(0) {} - Chat(const JID& jid, const std::string& chatName, const std::string& activity, int unreadCount, StatusShow::Type statusType, const boost::filesystem::path& avatarPath, bool isMUC, const std::string& nick = "", const boost::optional<std::string> password = boost::optional<std::string>()) - : jid(jid), chatName(chatName), activity(activity), statusType(statusType), isMUC(isMUC), nick(nick), password(password), unreadCount(unreadCount), avatarPath(avatarPath) {} + Chat() : statusType(StatusShow::None), isMUC(false), unreadCount(0), isPrivateMessage(false) {} + Chat(const JID& jid, const std::string& chatName, const std::string& activity, int unreadCount, StatusShow::Type statusType, const boost::filesystem::path& avatarPath, bool isMUC, bool isPrivateMessage = false, const std::string& nick = "", const boost::optional<std::string> password = boost::optional<std::string>()) + : jid(jid), chatName(chatName), activity(activity), statusType(statusType), isMUC(isMUC), nick(nick), password(password), unreadCount(unreadCount), avatarPath(avatarPath), isPrivateMessage(isPrivateMessage) {} /** Assume that nicks and other transient features aren't important for equality */ @@ -79,2 +79,3 @@ namespace Swift { std::map<std::string, JID> impromptuJIDs; + bool isPrivateMessage; }; diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h index bf4744b..81d26c8 100644 --- a/Swift/Controllers/UIInterfaces/ChatWindow.h +++ b/Swift/Controllers/UIInterfaces/ChatWindow.h @@ -132,2 +132,3 @@ namespace Swift { virtual void show() = 0; + virtual bool isVisible() const = 0; virtual void activate() = 0; diff --git a/Swift/Controllers/UnitTest/MockChatWindow.h b/Swift/Controllers/UnitTest/MockChatWindow.h index 823ea3a..5e6606b 100644 --- a/Swift/Controllers/UnitTest/MockChatWindow.h +++ b/Swift/Controllers/UnitTest/MockChatWindow.h @@ -43,2 +43,3 @@ namespace Swift { virtual void show() {} + virtual bool isVisible() const { return true; } virtual void activate() {} diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 74ff109..47eeac0 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -527,2 +527,6 @@ void QtChatWindow::show() { +bool QtChatWindow::isVisible() const { + return QWidget::isVisible(); +} + void QtChatWindow::activate() { diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h index b8e3c6a..b3a3f5e 100644 --- a/Swift/QtUI/QtChatWindow.h +++ b/Swift/QtUI/QtChatWindow.h @@ -99,2 +99,3 @@ namespace Swift { void show(); + bool isVisible() const; void activate(); |
Swift