summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Chat')
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.cpp6
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.h3
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp27
-rw-r--r--Swift/Controllers/Chat/ChatsManager.h2
-rw-r--r--Swift/Controllers/Chat/UnitTest/MockChatListWindow.h1
5 files changed, 37 insertions, 2 deletions
diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp
index fcaf4ce..5e3c45f 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.cpp
+++ b/Swift/Controllers/Chat/ChatControllerBase.cpp
@@ -87,6 +87,11 @@ void ChatControllerBase::handleAllMessagesRead() {
}
unreadMessages_.clear();
chatWindow_->setUnreadMessageCount(0);
+ onUnreadCountChanged();
+}
+
+int ChatControllerBase::getUnreadCount() {
+ return unreadMessages_.size();
}
void ChatControllerBase::handleSendMessageRequest(const std::string &body, bool isCorrectionMessage) {
@@ -203,6 +208,7 @@ void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> m
}
chatWindow_->show();
chatWindow_->setUnreadMessageCount(unreadMessages_.size());
+ onUnreadCountChanged();
postHandleIncomingMessage(messageEvent);
}
diff --git a/Swift/Controllers/Chat/ChatControllerBase.h b/Swift/Controllers/Chat/ChatControllerBase.h
index 3364ccb..86c1ef2 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.h
+++ b/Swift/Controllers/Chat/ChatControllerBase.h
@@ -49,6 +49,9 @@ namespace Swift {
virtual void setToJID(const JID& jid) {toJID_ = jid;};
/** Used for determining when something is recent.*/
boost::signal<void (const std::string& /*activity*/)> onActivity;
+ boost::signal<void ()> onUnreadCountChanged;
+ int getUnreadCount();
+ const JID& getToJID() {return toJID_;}
protected:
ChatControllerBase(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &toJID, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory);
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index 9d6d9c8..66817aa 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -132,7 +132,7 @@ 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, isMUC, nick);
+ ChatListWindow::Chat chat(jid, nickResolver_->jidToNick(jid), activity, 0, isMUC, nick);
prependRecent(chat);
}
chatListWindow_->setRecents(recentChats_);
@@ -171,15 +171,37 @@ void ChatsManager::handleMUCBookmarkRemoved(const MUCBookmark& bookmark) {
chatListWindow_->removeMUCBookmark(bookmark);
}
+ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const std::string& activity) {
+ int unreadCount = 0;
+ ChatController* controller = getChatControllerIfExists(jid);
+ if (controller) {
+ unreadCount = controller->getUnreadCount();
+ }
+ return ChatListWindow::Chat(jid, nickResolver_->jidToNick(jid), activity, unreadCount, false);
+}
+
void ChatsManager::handleChatActivity(const JID& jid, const std::string& activity) {
+ ChatListWindow::Chat chat = createChatListChatItem(jid, activity);
/* FIXME: MUC use requires changes here. */
- ChatListWindow::Chat chat(jid, nickResolver_->jidToNick(jid), activity, false);
+
/* FIXME: handle nick changes */
appendRecent(chat);
chatListWindow_->setRecents(recentChats_);
saveRecents();
}
+void ChatsManager::handleUnreadCountChanged(ChatController* controller) {
+ int unreadTotal = 0;
+ foreach (ChatListWindow::Chat chatItem, recentChats_) {
+ if (chatItem.jid == controller->getToJID()) {
+ chatItem.setUnreadCount(controller->getUnreadCount());
+ }
+ unreadTotal += chatItem.unreadCount;
+ }
+ chatListWindow_->setRecents(recentChats_);
+ chatListWindow_->setUnreadCount(unreadTotal);
+}
+
void ChatsManager::appendRecent(const ChatListWindow::Chat& chat) {
recentChats_.erase(std::remove(recentChats_.begin(), recentChats_.end(), chat), recentChats_.end());
recentChats_.push_front(chat);
@@ -314,6 +336,7 @@ ChatController* ChatsManager::createNewChatController(const JID& contact) {
chatControllers_[contact] = controller;
controller->setAvailableServerFeatures(serverDiscoInfo_);
controller->onActivity.connect(boost::bind(&ChatsManager::handleChatActivity, this, contact, _1));
+ controller->onUnreadCountChanged.connect(boost::bind(&ChatsManager::handleUnreadCountChanged, this, controller));
return controller;
}
diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h
index 24b0f97..ccfdb3a 100644
--- a/Swift/Controllers/Chat/ChatsManager.h
+++ b/Swift/Controllers/Chat/ChatsManager.h
@@ -51,6 +51,7 @@ namespace Swift {
void setOnline(bool enabled);
void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info);
void handleIncomingMessage(boost::shared_ptr<Message> message);
+ ChatListWindow::Chat createChatListChatItem(const JID& jid, const std::string& activity);
private:
void handleChatRequest(const std::string& contact);
@@ -73,6 +74,7 @@ namespace Swift {
void handleChatMadeRecent();
void handleMUCBookmarkActivated(const MUCBookmark&);
void handleRecentActivated(const ChatListWindow::Chat&);
+ void handleUnreadCountChanged(ChatController* controller);
ChatController* getChatControllerOrFindAnother(const JID &contact);
ChatController* createNewChatController(const JID &contact);
diff --git a/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h b/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h
index 408a490..b1e1329 100644
--- a/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h
+++ b/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h
@@ -18,6 +18,7 @@ namespace Swift {
void removeMUCBookmark(const MUCBookmark& /*bookmark*/) {}
void setBookmarksEnabled(bool /*enabled*/) {}
void setRecents(const std::list<ChatListWindow::Chat>& /*recents*/) {}
+ void setUnreadCount(int unread) {}
void clearBookmarks() {}
};