From 4971ff9d24992491684f6e88380f2d8f69fbbf1f Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Mon, 26 Jun 2017 17:50:31 +0200 Subject: [PATCH] fix(Chat): better core on composing --- src/components/chat/ChatModel.cpp | 32 +++++++++---------- src/components/chat/ChatModel.hpp | 1 + src/components/core/CoreHandlers.cpp | 7 ++++ src/components/core/CoreHandlers.hpp | 6 ++++ ui/modules/Linphone/Chat/Chat.qml | 21 ++++++------ ui/modules/Linphone/Styles/Chat/ChatStyle.qml | 3 +- 6 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/components/chat/ChatModel.cpp b/src/components/chat/ChatModel.cpp index d8cc4b869..1fa18e341 100644 --- a/src/components/chat/ChatModel.cpp +++ b/src/components/chat/ChatModel.cpp @@ -197,22 +197,12 @@ ChatModel::ChatModel (QObject *parent) : QAbstractListModel(parent) { core->getSipAddressesModel()->connectToChatModel(this); - QObject::connect(mCoreHandlers.get(), &CoreHandlers::messageReceived, this, &ChatModel::handleMessageReceived); - QObject::connect(mCoreHandlers.get(), &CoreHandlers::callStateChanged, this, &ChatModel::handleCallStateChanged); - - // Deal with remote composing. - QTimer *timer = new QTimer(this); - timer->setInterval(500); - - QObject::connect(timer, &QTimer::timeout, this, [this] { - bool isRemoteComposing = mChatRoom->isRemoteComposing(); - if (isRemoteComposing != mIsRemoteComposing) { - mIsRemoteComposing = isRemoteComposing; - emit isRemoteComposingChanged(mIsRemoteComposing); - } - }); - - timer->start(); + { + CoreHandlers *coreHandlers = mCoreHandlers.get(); + QObject::connect(coreHandlers, &CoreHandlers::messageReceived, this, &ChatModel::handleMessageReceived); + QObject::connect(coreHandlers, &CoreHandlers::callStateChanged, this, &ChatModel::handleCallStateChanged); + QObject::connect(coreHandlers, &CoreHandlers::isComposingChanged, this, &ChatModel::handleIsComposingChanged); + } } ChatModel::~ChatModel () { @@ -669,6 +659,16 @@ void ChatModel::handleCallStateChanged (const shared_ptr &call, insertCall(call->getCallLog()); } +void ChatModel::handleIsComposingChanged (const shared_ptr &chatRoom) { + if (mChatRoom == chatRoom) { + bool isRemoteComposing = mChatRoom->isRemoteComposing(); + if (isRemoteComposing != mIsRemoteComposing) { + mIsRemoteComposing = isRemoteComposing; + emit isRemoteComposingChanged(mIsRemoteComposing); + } + } +} + void ChatModel::handleMessageReceived (const shared_ptr &message) { if (mChatRoom == message->getChatRoom()) { insertMessageAtEnd(message); diff --git a/src/components/chat/ChatModel.hpp b/src/components/chat/ChatModel.hpp index e4132242b..1111e722f 100644 --- a/src/components/chat/ChatModel.hpp +++ b/src/components/chat/ChatModel.hpp @@ -138,6 +138,7 @@ private: void resetMessagesCount (); void handleCallStateChanged (const std::shared_ptr &call, linphone::CallState state); + void handleIsComposingChanged (const std::shared_ptr &chatRoom); void handleMessageReceived (const std::shared_ptr &message); bool mIsRemoteComposing = false; diff --git a/src/components/core/CoreHandlers.cpp b/src/components/core/CoreHandlers.cpp index a175ac4da..c92e0c3eb 100644 --- a/src/components/core/CoreHandlers.cpp +++ b/src/components/core/CoreHandlers.cpp @@ -121,6 +121,13 @@ void CoreHandlers::onGlobalStateChanged ( } } +void CoreHandlers::onIsComposingReceived ( + const shared_ptr &, + const shared_ptr &room +) { + emit isComposingChanged(room); +} + void CoreHandlers::onLogCollectionUploadStateChanged ( const shared_ptr &, linphone::CoreLogCollectionUploadState state, diff --git a/src/components/core/CoreHandlers.hpp b/src/components/core/CoreHandlers.hpp index 5011cb8db..46305f05f 100644 --- a/src/components/core/CoreHandlers.hpp +++ b/src/components/core/CoreHandlers.hpp @@ -46,6 +46,7 @@ signals: void callTransferFailed (const std::shared_ptr &call); void callTransferSucceeded (const std::shared_ptr &call); void coreStarted (); + void isComposingChanged (const std::shared_ptr &chatRoom); void logsUploadStateChanged (linphone::CoreLogCollectionUploadState state, const std::string &info); void messageReceived (const std::shared_ptr &message); void presenceReceived (const QString &sipAddress, const std::shared_ptr &presenceModel); @@ -84,6 +85,11 @@ private: const std::string &message ) override; + void onIsComposingReceived ( + const std::shared_ptr &core, + const std::shared_ptr &room + ) override; + void onLogCollectionUploadStateChanged ( const std::shared_ptr &core, linphone::CoreLogCollectionUploadState state, diff --git a/ui/modules/Linphone/Chat/Chat.qml b/ui/modules/Linphone/Chat/Chat.qml index d5747b0e4..088cb40d9 100644 --- a/ui/modules/Linphone/Chat/Chat.qml +++ b/ui/modules/Linphone/Chat/Chat.qml @@ -187,6 +187,16 @@ Rectangle { } } } + + footer: Text { + color: ChatStyle.composingText.color + font.pointSize: ChatStyle.composingText.pointSize + height: visible ? ChatStyle.composingText.height : 0 + leftPadding: ChatStyle.composingText.leftPadding + visible: text.length > 0 + + text: Logic.getIsComposingMessage() + } } // ------------------------------------------------------------------------- @@ -199,7 +209,6 @@ Rectangle { borderColor: ChatStyle.sendArea.border.color - bottomWidth: ChatStyle.sendArea.border.width topWidth: ChatStyle.sendArea.border.width DroppableTextArea { @@ -216,16 +225,6 @@ Rectangle { onValidText: Logic.sendMessage(text) } } - - Text { - Layout.fillWidth: true - - color: ChatStyle.composingText.color - font.pointSize: ChatStyle.composingText.pointSize - leftPadding: ChatStyle.composingText.leftPadding - - text: Logic.getIsComposingMessage() - } } // --------------------------------------------------------------------------- diff --git a/ui/modules/Linphone/Styles/Chat/ChatStyle.qml b/ui/modules/Linphone/Styles/Chat/ChatStyle.qml index 2fac6eca8..d36c16536 100644 --- a/ui/modules/Linphone/Styles/Chat/ChatStyle.qml +++ b/ui/modules/Linphone/Styles/Chat/ChatStyle.qml @@ -35,8 +35,9 @@ QtObject { property QtObject composingText: QtObject { property color color: Colors.b - property int pointSize: Units.dp * 9 + property int height: 25 property int leftPadding: 6 + property int pointSize: Units.dp * 9 } property QtObject entry: QtObject {