summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2018-11-08 14:12:36 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2018-11-08 15:30:19 (GMT)
commit0b4e062a59613b2597b712c0106c3ed08b747637 (patch)
tree7b062a8123d37be7226d4eb36c553b04563255c6 /Swift/Controllers/Chat
parentcf3d517763a3d74a2ec9fd6f7bdee8cbaee3550f (diff)
downloadswift-0b4e062a59613b2597b712c0106c3ed08b747637.zip
swift-0b4e062a59613b2597b712c0106c3ed08b747637.tar.bz2
Change unread counters to size_t
Since the counters cannot be negative, changing the type used for unread counters to size_t seems a better fit, and it avoids the need for numeric_casts. Test-Information: Unit tests pass on macOS 10.13 Change-Id: I61badcfc410f0cce7f922da90b50ef5a809c6521
Diffstat (limited to 'Swift/Controllers/Chat')
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.cpp9
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.h2
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp4
-rw-r--r--Swift/Controllers/Chat/Chattables.h2
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChattablesTest.cpp3
-rw-r--r--Swift/Controllers/Chat/UnitTest/MockChatListWindow.h2
6 files changed, 12 insertions, 10 deletions
diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp
index 8a26a56..3805084 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.cpp
+++ b/Swift/Controllers/Chat/ChatControllerBase.cpp
@@ -118,8 +118,8 @@ void ChatControllerBase::handleAllMessagesRead() {
118 } 118 }
119} 119}
120 120
121int ChatControllerBase::getUnreadCount() { 121size_t ChatControllerBase::getUnreadCount() {
122 return boost::numeric_cast<int>(targetedUnreadMessages_.size()); 122 return targetedUnreadMessages_.size();
123} 123}
124 124
125void ChatControllerBase::handleSendMessageRequest(const std::string &body, bool isCorrectionMessage) { 125void ChatControllerBase::handleSendMessageRequest(const std::string &body, bool isCorrectionMessage) {
@@ -193,11 +193,10 @@ ChatWindow::ChatMessage ChatControllerBase::buildChatWindowChatMessage(const std
193} 193}
194 194
195void ChatControllerBase::updateMessageCount() { 195void ChatControllerBase::updateMessageCount() {
196 int intCount = boost::numeric_cast<int>(unreadMessages_.size());
197 chatWindow_->setUnreadMessageCount(intCount);
198 auto baseJID = getBaseJID(); 196 auto baseJID = getBaseJID();
199 auto state = chattables_.getState(baseJID); 197 auto state = chattables_.getState(baseJID);
200 state.unreadCount = intCount; 198 state.unreadCount = unreadMessages_.size();
199 chatWindow_->setUnreadMessageCount(state.unreadCount);
201 chattables_.setState(baseJID, state); 200 chattables_.setState(baseJID, state);
202#ifndef NOT_YET 201#ifndef NOT_YET
203 onUnreadCountChanged(); 202 onUnreadCountChanged();
diff --git a/Swift/Controllers/Chat/ChatControllerBase.h b/Swift/Controllers/Chat/ChatControllerBase.h
index 527196c..92c6175 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.h
+++ b/Swift/Controllers/Chat/ChatControllerBase.h
@@ -73,7 +73,7 @@ namespace Swift {
73 boost::signals2::signal<void (const std::string& /*activity*/)> onActivity; 73 boost::signals2::signal<void (const std::string& /*activity*/)> onActivity;
74 boost::signals2::signal<void ()> onUnreadCountChanged; 74 boost::signals2::signal<void ()> onUnreadCountChanged;
75 boost::signals2::signal<void ()> onWindowClosed; 75 boost::signals2::signal<void ()> onWindowClosed;
76 int getUnreadCount(); 76 size_t getUnreadCount();
77 const JID& getToJID() {return toJID_;} 77 const JID& getToJID() {return toJID_;}
78 void handleCapsChanged(const JID& jid); 78 void handleCapsChanged(const JID& jid);
79 void setCanStartImpromptuChats(bool supportsImpromptu); 79 void setCanStartImpromptuChats(bool supportsImpromptu);
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index 532b925..6530a7e 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -372,7 +372,7 @@ void ChatsManager::handleMUCBookmarkRemoved(const MUCBookmark& bookmark) {
372 372
373#ifndef NOT_YET 373#ifndef NOT_YET
374ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const std::string& activity, bool privateMessage) { 374ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const std::string& activity, bool privateMessage) {
375 int unreadCount = 0; 375 size_t unreadCount = 0;
376 if (mucRegistry_->isMUC(jid)) { 376 if (mucRegistry_->isMUC(jid)) {
377 MUCController* controller = mucControllers_[jid.toBare()]; 377 MUCController* controller = mucControllers_[jid.toBare()];
378 StatusShow::Type type = StatusShow::None; 378 StatusShow::Type type = StatusShow::None;
@@ -447,7 +447,7 @@ void ChatsManager::handleChatClosed(const JID& /*jid*/) {
447#ifndef NOT_YET 447#ifndef NOT_YET
448 448
449void ChatsManager::handleUnreadCountChanged(ChatControllerBase* controller) { 449void ChatsManager::handleUnreadCountChanged(ChatControllerBase* controller) {
450 int unreadTotal = 0; 450 size_t unreadTotal = 0;
451 bool controllerIsMUC = dynamic_cast<MUCController*>(controller); 451 bool controllerIsMUC = dynamic_cast<MUCController*>(controller);
452 bool isPM = controller && !controllerIsMUC && mucRegistry_->isMUC(controller->getToJID().toBare()); 452 bool isPM = controller && !controllerIsMUC && mucRegistry_->isMUC(controller->getToJID().toBare());
453 for (ChatListWindow::Chat& chatItem : recentChats_) { 453 for (ChatListWindow::Chat& chatItem : recentChats_) {
diff --git a/Swift/Controllers/Chat/Chattables.h b/Swift/Controllers/Chat/Chattables.h
index c115fb3..3b5817a 100644
--- a/Swift/Controllers/Chat/Chattables.h
+++ b/Swift/Controllers/Chat/Chattables.h
@@ -22,7 +22,7 @@ class Chattables {
22 JID jid; 22 JID jid;
23 /// Empty for no name 23 /// Empty for no name
24 std::string name; 24 std::string name;
25 int unreadCount = 0; 25 size_t unreadCount = 0;
26 Type type; 26 Type type;
27 StatusShow::Type status = StatusShow::None; 27 StatusShow::Type status = StatusShow::None;
28 //avatar 28 //avatar
diff --git a/Swift/Controllers/Chat/UnitTest/ChattablesTest.cpp b/Swift/Controllers/Chat/UnitTest/ChattablesTest.cpp
index e052aff..f30e3fd 100644
--- a/Swift/Controllers/Chat/UnitTest/ChattablesTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChattablesTest.cpp
@@ -9,6 +9,9 @@
9 9
10#include <Swift/Controllers/Chat/Chattables.h> 10#include <Swift/Controllers/Chat/Chattables.h>
11 11
12// Clang wrongly things that tests for 0 are using 0 as null.
13#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
14
12using namespace Swift; 15using namespace Swift;
13 16
14class ChattablesTest : public ::testing::Test { 17class ChattablesTest : public ::testing::Test {
diff --git a/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h b/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h
index 395b050..1d980d3 100644
--- a/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h
+++ b/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h
@@ -20,7 +20,7 @@ namespace Swift {
20 void removeWhiteboardSession(const JID& /*jid*/) {} 20 void removeWhiteboardSession(const JID& /*jid*/) {}
21 void setBookmarksEnabled(bool /*enabled*/) {} 21 void setBookmarksEnabled(bool /*enabled*/) {}
22 void setRecents(const std::list<ChatListWindow::Chat>& /*recents*/) {} 22 void setRecents(const std::list<ChatListWindow::Chat>& /*recents*/) {}
23 void setUnreadCount(int /*unread*/) {} 23 void setUnreadCount(size_t /*unread*/) {}
24 void clearBookmarks() {} 24 void clearBookmarks() {}
25 void setOnline(bool /*isOnline*/) {} 25 void setOnline(bool /*isOnline*/) {}
26 }; 26 };