From 15b38e3a8b054eaec28df4286e0ca2c0c76a8d98 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 20 Apr 2018 09:13:59 +0200 Subject: [PATCH] Fix unread chat message count. --- src/chat/chat-room/chat-room.cpp | 6 +++++- src/chat/notification/imdn.cpp | 6 ++++++ src/chat/notification/imdn.h | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index 30e0a8843..69e1e3f94 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -416,7 +416,11 @@ int ChatRoom::getChatMessageCount () const { } int ChatRoom::getUnreadChatMessageCount () const { - return getCore()->getPrivate()->mainDb->getUnreadChatMessageCount(getChatRoomId()); + L_D(); + int dbUnreadCount = getCore()->getPrivate()->mainDb->getUnreadChatMessageCount(getChatRoomId()); + int notifiedCount = d->imdnHandler->getDisplayNotificationCount(); + L_ASSERT(dbUnreadCount >= notifiedCount); + return dbUnreadCount - notifiedCount; } // ----------------------------------------------------------------------------- diff --git a/src/chat/notification/imdn.cpp b/src/chat/notification/imdn.cpp index 6cccf52f0..b538cf015 100644 --- a/src/chat/notification/imdn.cpp +++ b/src/chat/notification/imdn.cpp @@ -48,6 +48,12 @@ Imdn::~Imdn () { // ----------------------------------------------------------------------------- +int Imdn::getDisplayNotificationCount () const { + return static_cast(displayedMessages.size()); +} + +// ----------------------------------------------------------------------------- + void Imdn::notifyDelivery (const shared_ptr &message) { if (find(deliveredMessages.begin(), deliveredMessages.end(), message) == deliveredMessages.end()) { deliveredMessages.push_back(message); diff --git a/src/chat/notification/imdn.h b/src/chat/notification/imdn.h index 0d1b00940..cf8c46eb8 100644 --- a/src/chat/notification/imdn.h +++ b/src/chat/notification/imdn.h @@ -53,6 +53,8 @@ public: Imdn (ChatRoom *chatRoom); ~Imdn (); + int getDisplayNotificationCount () const; + void notifyDelivery (const std::shared_ptr &message); void notifyDeliveryError (const std::shared_ptr &message, LinphoneReason reason); void notifyDisplay (const std::shared_ptr &message);