From af8b7faaf5614941ee18365ee1c0d58171aa07b6 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Thu, 29 Oct 2020 17:13:24 +0100 Subject: [PATCH] Keep unsend typed message in memory when changing of chat room --- .../src/components/chat/ChatProxyModel.cpp | 14 +++++++++++++- .../src/components/chat/ChatProxyModel.hpp | 6 +++++- .../ui/modules/Common/Form/DroppableTextArea.qml | 1 + linphone-app/ui/modules/Linphone/Chat/Chat.js | 4 ++-- linphone-app/ui/modules/Linphone/Chat/Chat.qml | 1 + 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/linphone-app/src/components/chat/ChatProxyModel.cpp b/linphone-app/src/components/chat/ChatProxyModel.cpp index 97370fd08..5796bdb2d 100644 --- a/linphone-app/src/components/chat/ChatProxyModel.cpp +++ b/linphone-app/src/components/chat/ChatProxyModel.cpp @@ -29,6 +29,8 @@ using namespace std; +QString ChatProxyModel::gCachedText; + // Fetch the L last filtered chat entries. class ChatProxyModel::ChatModelFilter : public QSortFilterProxyModel { public: @@ -100,7 +102,6 @@ ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) ); \ } -CREATE_PARENT_MODEL_FUNCTION(compose); CREATE_PARENT_MODEL_FUNCTION(removeAllEntries); CREATE_PARENT_MODEL_FUNCTION_WITH_PARAM(sendFileMessage, const QString &); @@ -117,6 +118,13 @@ CREATE_PARENT_MODEL_FUNCTION_WITH_ID(resendMessage); #undef CREATE_PARENT_MODEL_FUNCTION_WITH_PARAM #undef CREATE_PARENT_MODEL_FUNCTION_WITH_ID + +void ChatProxyModel::compose (const QString& text) { + if (mChatModel) + mChatModel->compose(); + gCachedText = text; +} + // ----------------------------------------------------------------------------- void ChatProxyModel::loadMoreEntries () { @@ -194,6 +202,10 @@ bool ChatProxyModel::getIsRemoteComposing () const { return mChatModel ? mChatModel->getIsRemoteComposing() : false; } +QString ChatProxyModel::getCachedText() const{ + return gCachedText; +} + // ----------------------------------------------------------------------------- void ChatProxyModel::reload () { diff --git a/linphone-app/src/components/chat/ChatProxyModel.hpp b/linphone-app/src/components/chat/ChatProxyModel.hpp index 9ab97e3e9..cfc4e7573 100644 --- a/linphone-app/src/components/chat/ChatProxyModel.hpp +++ b/linphone-app/src/components/chat/ChatProxyModel.hpp @@ -39,6 +39,7 @@ class ChatProxyModel : public QSortFilterProxyModel { Q_PROPERTY(QString fullPeerAddress READ getFullPeerAddress WRITE setFullPeerAddress NOTIFY fullPeerAddressChanged); Q_PROPERTY(QString fullLocalAddress READ getFullLocalAddress WRITE setFullLocalAddress NOTIFY fullLocalAddressChanged); Q_PROPERTY(bool isRemoteComposing READ getIsRemoteComposing NOTIFY isRemoteComposingChanged); + Q_PROPERTY(QString cachedText READ getCachedText); public: ChatProxyModel (QObject *parent = Q_NULLPTR); @@ -58,7 +59,7 @@ public: Q_INVOKABLE void openFile (int id); Q_INVOKABLE void openFileDirectory (int id); - Q_INVOKABLE void compose (); + Q_INVOKABLE void compose (const QString& text); Q_INVOKABLE void resetMessageCount(); @@ -90,6 +91,8 @@ private: void setFullLocalAddress (const QString &localAddress); bool getIsRemoteComposing () const; + + QString getCachedText() const; void reload (); @@ -105,6 +108,7 @@ private: QString mLocalAddress; QString mFullPeerAddress; QString mFullLocalAddress; + static QString gCachedText; std::shared_ptr mChatModel; diff --git a/linphone-app/ui/modules/Common/Form/DroppableTextArea.qml b/linphone-app/ui/modules/Common/Form/DroppableTextArea.qml index 99d397d0d..29c1e3e70 100644 --- a/linphone-app/ui/modules/Common/Form/DroppableTextArea.qml +++ b/linphone-app/ui/modules/Common/Form/DroppableTextArea.qml @@ -13,6 +13,7 @@ Item { property alias placeholderText: textArea.placeholderText property alias text: textArea.text + property alias cursorPosition: textArea.cursorPosition property bool dropEnabled: true property string dropDisabledReason diff --git a/linphone-app/ui/modules/Linphone/Chat/Chat.js b/linphone-app/ui/modules/Linphone/Chat/Chat.js index 1e3c011da..b388db54b 100644 --- a/linphone-app/ui/modules/Linphone/Chat/Chat.js +++ b/linphone-app/ui/modules/Linphone/Chat/Chat.js @@ -86,8 +86,8 @@ function handleMovementStarted () { chat.bindToEnd = false } -function handleTextChanged () { - container.proxyModel.compose() +function handleTextChanged (text) { + container.proxyModel.compose(text) } function sendMessage (text) { diff --git a/linphone-app/ui/modules/Linphone/Chat/Chat.qml b/linphone-app/ui/modules/Linphone/Chat/Chat.qml index 0d72d1761..2708cc425 100644 --- a/linphone-app/ui/modules/Linphone/Chat/Chat.qml +++ b/linphone-app/ui/modules/Linphone/Chat/Chat.qml @@ -224,6 +224,7 @@ Rectangle { onDropped: Logic.handleFilesDropped(files) onTextChanged: Logic.handleTextChanged(text) onValidText: Logic.sendMessage(text) + Component.onCompleted: {text = proxyModel.cachedText; cursorPosition=text.length} } } }