From 79853f9995283c51ca8ca5a888a83bf6cb657504 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 11 Jan 2017 17:09:27 +0100 Subject: [PATCH] fix(src/components/chat/ChatProxyModel): increment properly visible messages number --- tests/src/components/chat/ChatModel.cpp | 2 ++ tests/src/components/chat/ChatModel.hpp | 3 ++- tests/src/components/chat/ChatProxyModel.cpp | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/src/components/chat/ChatModel.cpp b/tests/src/components/chat/ChatModel.cpp index d74dbd551..fda7dba23 100644 --- a/tests/src/components/chat/ChatModel.cpp +++ b/tests/src/components/chat/ChatModel.cpp @@ -83,6 +83,8 @@ ChatModel::ChatModel (QObject *parent) : QAbstractListModel(parent) { if (m_chat_room == message->getChatRoom()) { insertMessageAtEnd(message); m_chat_room->markAsRead(); + + emit messageReceived(message); } } ); diff --git a/tests/src/components/chat/ChatModel.hpp b/tests/src/components/chat/ChatModel.hpp index 189bf884d..888db62c4 100644 --- a/tests/src/components/chat/ChatModel.hpp +++ b/tests/src/components/chat/ChatModel.hpp @@ -72,7 +72,8 @@ signals: void sipAddressChanged (const QString &sip_address); void allEntriesRemoved (); - void messageSent (std::shared_ptr &message); + void messageSent (const std::shared_ptr &message); + void messageReceived (const std::shared_ptr &message); private: void fillMessageEntry ( diff --git a/tests/src/components/chat/ChatProxyModel.cpp b/tests/src/components/chat/ChatProxyModel.cpp index c1e966308..80567244d 100644 --- a/tests/src/components/chat/ChatProxyModel.cpp +++ b/tests/src/components/chat/ChatProxyModel.cpp @@ -27,6 +27,20 @@ const unsigned int ChatProxyModel::ENTRIES_CHUNK_SIZE = 50; ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) { setSourceModel(&m_chat_model_filter); + + ChatModel *chat = static_cast(m_chat_model_filter.sourceModel()); + + QObject::connect( + chat, &ChatModel::messageReceived, this, [this](const shared_ptr &) { + m_n_max_displayed_entries++; + } + ); + + QObject::connect( + chat, &ChatModel::messageSent, this, [this](const shared_ptr &) { + m_n_max_displayed_entries++; + } + ); } void ChatProxyModel::loadMoreEntries () { @@ -42,7 +56,6 @@ void ChatProxyModel::loadMoreEntries () { invalidateFilter(); count = rowCount() - count; - if (count > 0) emit moreEntriesLoaded(count); }