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() {
}
}
-int ChatControllerBase::getUnreadCount() {
- return boost::numeric_cast<int>(targetedUnreadMessages_.size());
+size_t ChatControllerBase::getUnreadCount() {
+ return targetedUnreadMessages_.size();
}
void ChatControllerBase::handleSendMessageRequest(const std::string &body, bool isCorrectionMessage) {
@@ -193,11 +193,10 @@ ChatWindow::ChatMessage ChatControllerBase::buildChatWindowChatMessage(const std
}
void ChatControllerBase::updateMessageCount() {
- int intCount = boost::numeric_cast<int>(unreadMessages_.size());
- chatWindow_->setUnreadMessageCount(intCount);
auto baseJID = getBaseJID();
auto state = chattables_.getState(baseJID);
- state.unreadCount = intCount;
+ state.unreadCount = unreadMessages_.size();
+ chatWindow_->setUnreadMessageCount(state.unreadCount);
chattables_.setState(baseJID, state);
#ifndef NOT_YET
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 {
boost::signals2::signal<void (const std::string& /*activity*/)> onActivity;
boost::signals2::signal<void ()> onUnreadCountChanged;
boost::signals2::signal<void ()> onWindowClosed;
- int getUnreadCount();
+ size_t getUnreadCount();
const JID& getToJID() {return toJID_;}
void handleCapsChanged(const JID& jid);
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) {
#ifndef NOT_YET
ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const std::string& activity, bool privateMessage) {
- int unreadCount = 0;
+ size_t unreadCount = 0;
if (mucRegistry_->isMUC(jid)) {
MUCController* controller = mucControllers_[jid.toBare()];
StatusShow::Type type = StatusShow::None;
@@ -447,7 +447,7 @@ void ChatsManager::handleChatClosed(const JID& /*jid*/) {
#ifndef NOT_YET
void ChatsManager::handleUnreadCountChanged(ChatControllerBase* controller) {
- int unreadTotal = 0;
+ size_t unreadTotal = 0;
bool controllerIsMUC = dynamic_cast<MUCController*>(controller);
bool isPM = controller && !controllerIsMUC && mucRegistry_->isMUC(controller->getToJID().toBare());
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 {
JID jid;
/// Empty for no name
std::string name;
- int unreadCount = 0;
+ size_t unreadCount = 0;
Type type;
StatusShow::Type status = StatusShow::None;
//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 @@
#include <Swift/Controllers/Chat/Chattables.h>
+// Clang wrongly things that tests for 0 are using 0 as null.
+#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
+
using namespace Swift;
class 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 {
void removeWhiteboardSession(const JID& /*jid*/) {}
void setBookmarksEnabled(bool /*enabled*/) {}
void setRecents(const std::list<ChatListWindow::Chat>& /*recents*/) {}
- void setUnreadCount(int /*unread*/) {}
+ void setUnreadCount(size_t /*unread*/) {}
void clearBookmarks() {}
void setOnline(bool /*isOnline*/) {}
};