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

This commit is contained in:
Ronan Abhamon 2018-06-20 11:01:51 +02:00
parent 5869fd7ffb
commit ee9c95d282
3 changed files with 45 additions and 10 deletions

View file

@ -20,6 +20,9 @@
* Author: Ronan Abhamon * Author: Ronan Abhamon
*/ */
#include <QQuickWindow>
#include "app/App.hpp"
#include "components/core/CoreManager.hpp" #include "components/core/CoreManager.hpp"
#include "ChatProxyModel.hpp" #include "ChatProxyModel.hpp"
@ -61,6 +64,14 @@ private:
ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) { ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
setSourceModel(new ChatModelFilter(this)); 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,12 +187,30 @@ 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) { void ChatProxyModel::handleIsRemoteComposingChanged (bool status) {
emit isRemoteComposingChanged(status); emit isRemoteComposingChanged(status);
} }
void ChatProxyModel::handleMessageReceived (const shared_ptr<linphone::ChatMessage> &) { void ChatProxyModel::handleMessageReceived (const shared_ptr<linphone::ChatMessage> &) {
mMaxDisplayedEntries++; mMaxDisplayedEntries++;
QWindow *window = getParentWindow(this);
if (window && window->isActive())
mChatModel->resetMessagesCount(); mChatModel->resetMessagesCount();
} }

View file

@ -29,6 +29,8 @@
// ============================================================================= // =============================================================================
class QWindow;
class ChatProxyModel : public QSortFilterProxyModel { class ChatProxyModel : public QSortFilterProxyModel {
class ChatModelFilter; class ChatModelFilter;
@ -74,6 +76,8 @@ private:
bool getIsRemoteComposing () const; bool getIsRemoteComposing () const;
void handleIsActiveChanged (QWindow *window);
void handleIsRemoteComposingChanged (bool status); void handleIsRemoteComposingChanged (bool status);
void handleMessageReceived (const std::shared_ptr<linphone::ChatMessage> &message); void handleMessageReceived (const std::shared_ptr<linphone::ChatMessage> &message);
void handleMessageSent (const std::shared_ptr<linphone::ChatMessage> &message); void handleMessageSent (const std::shared_ptr<linphone::ChatMessage> &message);

View file

@ -99,20 +99,22 @@ Rectangle {
width: parent ? parent.width : 0 width: parent ? parent.width : 0
Contact { Contact {
readonly property bool isSelected: view.currentIndex === index
anchors.fill: parent anchors.fill: parent
color: view.currentIndex === index color: isSelected
? TimelineStyle.contact.backgroundColor.selected ? TimelineStyle.contact.backgroundColor.selected
: ( : (
index % 2 == 0 index % 2 == 0
? TimelineStyle.contact.backgroundColor.a ? TimelineStyle.contact.backgroundColor.a
: TimelineStyle.contact.backgroundColor.b : TimelineStyle.contact.backgroundColor.b
) )
displayUnreadMessagesCount: SettingsModel.chatEnabled && view.currentIndex !== index displayUnreadMessagesCount: SettingsModel.chatEnabled
entry: $timelineEntry entry: $timelineEntry
sipAddressColor: view.currentIndex === index sipAddressColor: isSelected
? TimelineStyle.contact.sipAddress.color.selected ? TimelineStyle.contact.sipAddress.color.selected
: TimelineStyle.contact.sipAddress.color.normal : TimelineStyle.contact.sipAddress.color.normal
usernameColor: view.currentIndex === index usernameColor: isSelected
? TimelineStyle.contact.username.color.selected ? TimelineStyle.contact.username.color.selected
: TimelineStyle.contact.username.color.normal : TimelineStyle.contact.username.color.normal