diff --git a/src/components/chat/ChatProxyModel.cpp b/src/components/chat/ChatProxyModel.cpp index ed9b6bea7..190c2cfd4 100644 --- a/src/components/chat/ChatProxyModel.cpp +++ b/src/components/chat/ChatProxyModel.cpp @@ -20,6 +20,9 @@ * Author: Ronan Abhamon */ +#include + +#include "app/App.hpp" #include "components/core/CoreManager.hpp" #include "ChatProxyModel.hpp" @@ -61,6 +64,14 @@ private: ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) { setSourceModel(new ChatModelFilter(this)); + + App *app = App::getInstance(); + QObject::connect(app->getMainWindow(), &QWindow::activeChanged, this, [this]() { + handleIsActiveChanged(App::getInstance()->getMainWindow()); + }); + QObject::connect(app->getCallsWindow(), &QWindow::activeChanged, this, [this]() { + handleIsActiveChanged(App::getInstance()->getCallsWindow()); + }); } // ----------------------------------------------------------------------------- @@ -176,13 +187,31 @@ bool ChatProxyModel::getIsRemoteComposing () const { // ----------------------------------------------------------------------------- +static inline QWindow *getParentWindow (QObject *object) { + App *app = App::getInstance(); + const QWindow *mainWindow = app->getMainWindow(); + const QWindow *callsWindow = app->getCallsWindow(); + for (QObject *parent = object->parent(); parent; parent = parent->parent()) + if (parent == mainWindow || parent == callsWindow) + return static_cast(parent); + return nullptr; +} + +void ChatProxyModel::handleIsActiveChanged (QWindow *window) { + if (window->isActive() && getParentWindow(this) == window) + mChatModel->resetMessagesCount(); +} + void ChatProxyModel::handleIsRemoteComposingChanged (bool status) { emit isRemoteComposingChanged(status); } void ChatProxyModel::handleMessageReceived (const shared_ptr &) { mMaxDisplayedEntries++; - mChatModel->resetMessagesCount(); + + QWindow *window = getParentWindow(this); + if (window && window->isActive()) + mChatModel->resetMessagesCount(); } void ChatProxyModel::handleMessageSent (const shared_ptr &) { diff --git a/src/components/chat/ChatProxyModel.hpp b/src/components/chat/ChatProxyModel.hpp index 285647f44..7ddf10d44 100644 --- a/src/components/chat/ChatProxyModel.hpp +++ b/src/components/chat/ChatProxyModel.hpp @@ -29,6 +29,8 @@ // ============================================================================= +class QWindow; + class ChatProxyModel : public QSortFilterProxyModel { class ChatModelFilter; @@ -74,6 +76,8 @@ private: bool getIsRemoteComposing () const; + void handleIsActiveChanged (QWindow *window); + void handleIsRemoteComposingChanged (bool status); void handleMessageReceived (const std::shared_ptr &message); void handleMessageSent (const std::shared_ptr &message); diff --git a/ui/modules/Linphone/Timeline/Timeline.qml b/ui/modules/Linphone/Timeline/Timeline.qml index 95205458c..3c1d3d212 100644 --- a/ui/modules/Linphone/Timeline/Timeline.qml +++ b/ui/modules/Linphone/Timeline/Timeline.qml @@ -99,22 +99,24 @@ Rectangle { width: parent ? parent.width : 0 Contact { + readonly property bool isSelected: view.currentIndex === index + anchors.fill: parent - color: view.currentIndex === index + color: isSelected ? TimelineStyle.contact.backgroundColor.selected : ( index % 2 == 0 ? TimelineStyle.contact.backgroundColor.a : TimelineStyle.contact.backgroundColor.b ) - displayUnreadMessagesCount: SettingsModel.chatEnabled && view.currentIndex !== index - entry: $timelineEntry - sipAddressColor: view.currentIndex === index - ? TimelineStyle.contact.sipAddress.color.selected - : TimelineStyle.contact.sipAddress.color.normal - usernameColor: view.currentIndex === index - ? TimelineStyle.contact.username.color.selected - : TimelineStyle.contact.username.color.normal + displayUnreadMessagesCount: SettingsModel.chatEnabled + entry: $timelineEntry + sipAddressColor: isSelected + ? TimelineStyle.contact.sipAddress.color.selected + : TimelineStyle.contact.sipAddress.color.normal + usernameColor: isSelected + ? TimelineStyle.contact.username.color.selected + : TimelineStyle.contact.username.color.normal Loader { anchors.fill: parent