Commit 97a100c7 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(App): provide a `MessagesCountNotifier` component created by `CoreManager`

parent 15f1d4de
...@@ -127,6 +127,7 @@ set(SOURCES ...@@ -127,6 +127,7 @@ set(SOURCES
src/components/contacts/ContactsListProxyModel.cpp src/components/contacts/ContactsListProxyModel.cpp
src/components/core/CoreHandlers.cpp src/components/core/CoreHandlers.cpp
src/components/core/CoreManager.cpp src/components/core/CoreManager.cpp
src/components/core/MessagesCountNotifier.cpp
src/components/notifier/Notifier.cpp src/components/notifier/Notifier.cpp
src/components/other/colors/Colors.cpp src/components/other/colors/Colors.cpp
src/components/other/clipboard/Clipboard.cpp src/components/other/clipboard/Clipboard.cpp
...@@ -181,6 +182,7 @@ set(HEADERS ...@@ -181,6 +182,7 @@ set(HEADERS
src/components/contacts/ContactsListProxyModel.hpp src/components/contacts/ContactsListProxyModel.hpp
src/components/core/CoreHandlers.hpp src/components/core/CoreHandlers.hpp
src/components/core/CoreManager.hpp src/components/core/CoreManager.hpp
src/components/core/MessagesCountNotifier.hpp
src/components/notifier/Notifier.hpp src/components/notifier/Notifier.hpp
src/components/other/colors/Colors.hpp src/components/other/colors/Colors.hpp
src/components/other/clipboard/Clipboard.hpp src/components/other/clipboard/Clipboard.hpp
......
...@@ -272,9 +272,6 @@ void ChatModel::setSipAddress (const QString &sipAddress) { ...@@ -272,9 +272,6 @@ void ChatModel::setSipAddress (const QString &sipAddress) {
handleIsComposingChanged(mChatRoom); handleIsComposingChanged(mChatRoom);
if (mChatRoom->getUnreadMessagesCount() > 0)
resetMessagesCount();
// Get messages. // Get messages.
for (auto &message : mChatRoom->getHistory(0)) { for (auto &message : mChatRoom->getHistory(0)) {
QVariantMap map; QVariantMap map;
...@@ -461,6 +458,13 @@ void ChatModel::compose () { ...@@ -461,6 +458,13 @@ void ChatModel::compose () {
mChatRoom->compose(); mChatRoom->compose();
} }
void ChatModel::resetMessagesCount () {
if (mChatRoom->getUnreadMessagesCount() > 0) {
mChatRoom->markAsRead();
emit messagesCountReset();
}
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
const ChatModel::ChatEntryData ChatModel::getFileMessageEntry (int id) { const ChatModel::ChatEntryData ChatModel::getFileMessageEntry (int id) {
...@@ -617,11 +621,6 @@ void ChatModel::insertMessageAtEnd (const shared_ptr<linphone::ChatMessage> &mes ...@@ -617,11 +621,6 @@ void ChatModel::insertMessageAtEnd (const shared_ptr<linphone::ChatMessage> &mes
endInsertRows(); endInsertRows();
} }
void ChatModel::resetMessagesCount () {
mChatRoom->markAsRead();
emit messagesCountReset();
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void ChatModel::handleCallStateChanged (const shared_ptr<linphone::Call> &call, linphone::CallState state) { void ChatModel::handleCallStateChanged (const shared_ptr<linphone::Call> &call, linphone::CallState state) {
...@@ -645,8 +644,6 @@ void ChatModel::handleIsComposingChanged (const shared_ptr<linphone::ChatRoom> & ...@@ -645,8 +644,6 @@ void ChatModel::handleIsComposingChanged (const shared_ptr<linphone::ChatRoom> &
void ChatModel::handleMessageReceived (const shared_ptr<linphone::ChatMessage> &message) { void ChatModel::handleMessageReceived (const shared_ptr<linphone::ChatMessage> &message) {
if (mChatRoom == message->getChatRoom()) { if (mChatRoom == message->getChatRoom()) {
insertMessageAtEnd(message); insertMessageAtEnd(message);
resetMessagesCount();
emit messageReceived(message); emit messageReceived(message);
} }
} }
...@@ -106,6 +106,8 @@ public: ...@@ -106,6 +106,8 @@ public:
void compose (); void compose ();
void resetMessagesCount ();
signals: signals:
bool isRemoteComposingChanged (bool status); bool isRemoteComposingChanged (bool status);
...@@ -132,8 +134,6 @@ private: ...@@ -132,8 +134,6 @@ private:
void insertCall (const std::shared_ptr<linphone::CallLog> &callLog); void insertCall (const std::shared_ptr<linphone::CallLog> &callLog);
void insertMessageAtEnd (const std::shared_ptr<linphone::ChatMessage> &message); void insertMessageAtEnd (const std::shared_ptr<linphone::ChatMessage> &message);
void resetMessagesCount ();
void handleCallStateChanged (const std::shared_ptr<linphone::Call> &call, linphone::CallState state); void handleCallStateChanged (const std::shared_ptr<linphone::Call> &call, linphone::CallState state);
void handleIsComposingChanged (const std::shared_ptr<linphone::ChatRoom> &chatRoom); void handleIsComposingChanged (const std::shared_ptr<linphone::ChatRoom> &chatRoom);
void handleMessageReceived (const std::shared_ptr<linphone::ChatMessage> &message); void handleMessageReceived (const std::shared_ptr<linphone::ChatMessage> &message);
......
...@@ -159,6 +159,8 @@ void ChatProxyModel::setSipAddress (const QString &sipAddress) { ...@@ -159,6 +159,8 @@ void ChatProxyModel::setSipAddress (const QString &sipAddress) {
} }
mChatModel = CoreManager::getInstance()->getChatModelFromSipAddress(sipAddress); mChatModel = CoreManager::getInstance()->getChatModelFromSipAddress(sipAddress);
mChatModel->resetMessagesCount();
if (mChatModel) { if (mChatModel) {
ChatModel *chatModel = mChatModel.get(); ChatModel *chatModel = mChatModel.get();
QObject::connect(chatModel, &ChatModel::isRemoteComposingChanged, this, &ChatProxyModel::handleIsRemoteComposingChanged); QObject::connect(chatModel, &ChatModel::isRemoteComposingChanged, this, &ChatProxyModel::handleIsRemoteComposingChanged);
...@@ -181,6 +183,7 @@ void ChatProxyModel::handleIsRemoteComposingChanged (bool status) { ...@@ -181,6 +183,7 @@ void ChatProxyModel::handleIsRemoteComposingChanged (bool status) {
void ChatProxyModel::handleMessageReceived (const shared_ptr<linphone::ChatMessage> &) { void ChatProxyModel::handleMessageReceived (const shared_ptr<linphone::ChatMessage> &) {
mMaxDisplayedEntries++; mMaxDisplayedEntries++;
mChatModel->resetMessagesCount();
} }
void ChatProxyModel::handleMessageSent (const shared_ptr<linphone::ChatMessage> &) { void ChatProxyModel::handleMessageSent (const shared_ptr<linphone::ChatMessage> &) {
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "../../app/paths/Paths.hpp" #include "../../app/paths/Paths.hpp"
#include "../../utils/Utils.hpp" #include "../../utils/Utils.hpp"
#include "MessagesCountNotifier.hpp"
#include "CoreManager.hpp" #include "CoreManager.hpp"
...@@ -54,6 +55,8 @@ CoreManager::CoreManager (QObject *parent, const QString &configPath) : ...@@ -54,6 +55,8 @@ CoreManager::CoreManager (QObject *parent, const QString &configPath) :
CoreHandlers *coreHandlers = mHandlers.get(); CoreHandlers *coreHandlers = mHandlers.get();
QObject::connect(coreHandlers, &CoreHandlers::coreStarted, this, [] { QObject::connect(coreHandlers, &CoreHandlers::coreStarted, this, [] {
new MessagesCountNotifier(mInstance);
mInstance->mCallsListModel = new CallsListModel(mInstance); mInstance->mCallsListModel = new CallsListModel(mInstance);
mInstance->mContactsListModel = new ContactsListModel(mInstance); mInstance->mContactsListModel = new ContactsListModel(mInstance);
mInstance->mSipAddressesModel = new SipAddressesModel(mInstance); mInstance->mSipAddressesModel = new SipAddressesModel(mInstance);
......
...@@ -127,7 +127,7 @@ signals: ...@@ -127,7 +127,7 @@ signals:
void coreCreated (); void coreCreated ();
void coreStarted (); void coreStarted ();
void chatModelCreated (const std::shared_ptr<ChatModel> chatModel); void chatModelCreated (const std::shared_ptr<ChatModel> &chatModel);
void logsUploaded (const QString &url); void logsUploaded (const QString &url);
......
/*
* MessagesCountNotifier.cpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: June 29, 2017
* Author: Ronan Abhamon
*/
#include "../core/CoreManager.hpp"
#include "MessagesCountNotifier.hpp"
using namespace std;
// =============================================================================
MessagesCountNotifier::MessagesCountNotifier (QObject *parent) : QObject(parent) {
CoreManager *coreManager = CoreManager::getInstance();
QObject::connect(
coreManager, &CoreManager::chatModelCreated,
this, &MessagesCountNotifier::handleChatModelCreated
);
QObject::connect(
coreManager->getHandlers().get(), &CoreHandlers::messageReceived,
this, &MessagesCountNotifier::handleMessageReceived
);
updateUnreadMessagesCount();
}
// -----------------------------------------------------------------------------
void MessagesCountNotifier::updateUnreadMessagesCount () {
mUnreadMessagesCount = 0;
for (const auto &chatRoom : CoreManager::getInstance()->getCore()->getChatRooms())
mUnreadMessagesCount += chatRoom->getUnreadMessagesCount();
notifyUnreadMessagesCount();
}
void MessagesCountNotifier::notifyUnreadMessagesCount () {
qInfo() << QStringLiteral("Notify unread messages count: %1.").arg(mUnreadMessagesCount);
#ifdef Q_OS_LINUX
// TODO.
#elif Q_OS_MACOS
// TODO.
#elif Q_OS_WIN
// TODO.
#endif // ifdef Q_OS_LINUX
}
// -----------------------------------------------------------------------------
void MessagesCountNotifier::handleChatModelCreated (const shared_ptr<ChatModel> &chatModel) {
QObject::connect(
chatModel.get(), &ChatModel::messagesCountReset,
this, &MessagesCountNotifier::updateUnreadMessagesCount
);
}
void MessagesCountNotifier::handleMessageReceived (const shared_ptr<linphone::ChatMessage> &) {
mUnreadMessagesCount++;
notifyUnreadMessagesCount();
}
/*
* MessagesCountNotifier.hpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: June 29, 2017
* Author: Ronan Abhamon
*/
#include <memory>
#include <QObject>
// =============================================================================
namespace linphone {
class ChatMessage;
}
class ChatModel;
class MessagesCountNotifier : public QObject {
Q_OBJECT;
public:
MessagesCountNotifier (QObject *parent = Q_NULLPTR);
~MessagesCountNotifier () = default;
private:
void updateUnreadMessagesCount ();
void notifyUnreadMessagesCount ();
void handleChatModelCreated (const std::shared_ptr<ChatModel> &chatModel);
void handleMessageReceived (const std::shared_ptr<linphone::ChatMessage> &message);
int mUnreadMessagesCount = 0;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment