Commit ee9c95d2 authored by Ronan's avatar Ronan

fix(Timeline): avoid mark as read on selected chat room if window is not active (fix #69)

parent 5869fd7f
Pipeline #92 failed with stage
in 0 seconds
......@@ -20,6 +20,9 @@
* Author: Ronan Abhamon
*/
#include <QQuickWindow>
#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<QWindow *>(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<linphone::ChatMessage> &) {
mMaxDisplayedEntries++;
mChatModel->resetMessagesCount();
QWindow *window = getParentWindow(this);
if (window && window->isActive())
mChatModel->resetMessagesCount();
}
void ChatProxyModel::handleMessageSent (const shared_ptr<linphone::ChatMessage> &) {
......
......@@ -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<linphone::ChatMessage> &message);
void handleMessageSent (const std::shared_ptr<linphone::ChatMessage> &message);
......
......@@ -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
......
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