diff --git a/src/apps/qml/qml/MainComponent.qml b/src/apps/qml/qml/MainComponent.qml --- a/src/apps/qml/qml/MainComponent.qml +++ b/src/apps/qml/qml/MainComponent.qml @@ -868,7 +868,7 @@ UserInput { id: userInputMessage rcAccount: appid.rocketChatAccount - inputCompleterModel: rcAccount.inputCompleterModel + inputTextManager: rcAccount.inputTextManager visible: appid.selectedRoom && (appid.selectedRoom.roomMessageInfo.length === 0) messageLineText: rcAccount.getUserCurrentMessage(appid.selectedRoomID) selectedRoomId: appid.selectedRoomID diff --git a/src/apps/qml/qml/MessageLine.qml b/src/apps/qml/qml/MessageLine.qml --- a/src/apps/qml/qml/MessageLine.qml +++ b/src/apps/qml/qml/MessageLine.qml @@ -38,7 +38,7 @@ property string threadmessageId property string selectedThreadMessage - property QtObject inputCompleterModel + property QtObject inputTextManager function sendMessage() { @@ -109,7 +109,7 @@ } onTextChanged: { - appid.rocketChatAccount.setInputTextChanged(text, cursorPosition); + inputTextManager.setInputTextChanged(text, cursorPosition); if (listView.count > 0) { showPopupCompleting() } else { @@ -181,7 +181,7 @@ width: parent.width interactive: true clip: true - model: inputCompleterModel + model: inputTextManager.inputCompleterModel delegate: Kirigami.BasicListItem { readonly property variant myData: model @@ -212,7 +212,7 @@ if (listView.currentItem) { var oldCursorPosition = messageLine.cursorPosition; var oldTextLength = messageLine.text.length; - messageLine.text = appid.rocketChatAccount.replaceWord(completerName + " ", messageLine.text, messageLine.cursorPosition) + messageLine.text = inputTextManager.replaceWord(completerName + " ", messageLine.text, messageLine.cursorPosition) // need to adjust cursor position by completer name length, '@' char and " " messageLine.cursorPosition = oldCursorPosition + (messageLine.text.length - oldTextLength) } diff --git a/src/apps/qml/qml/ShowThreadMessagesDialog.qml b/src/apps/qml/qml/ShowThreadMessagesDialog.qml --- a/src/apps/qml/qml/ShowThreadMessagesDialog.qml +++ b/src/apps/qml/qml/ShowThreadMessagesDialog.qml @@ -140,7 +140,7 @@ } //TODO improve it. UserInput { - inputCompleterModel: appid.rocketChatAccount.inputThreadMessageCompleterModel + inputTextManager: appid.rocketChatAccount.inputThreadMessageTextManager rcAccount: appid.rocketChatAccount visible: appid.selectedRoom && (appid.selectedRoom.roomMessageInfo.length === 0) diff --git a/src/apps/qml/qml/UserInput.qml b/src/apps/qml/qml/UserInput.qml --- a/src/apps/qml/qml/UserInput.qml +++ b/src/apps/qml/qml/UserInput.qml @@ -35,7 +35,7 @@ property string threadmessageId property string selectedRoomId property string selectedThreadMessage - property QtObject inputCompleterModel + property QtObject inputTextManager signal textEditing(string str) signal uploadFile() @@ -71,7 +71,7 @@ } MessageLine { id: messageLine - inputCompleterModel: footerItem.inputCompleterModel + inputTextManager: footerItem.inputTextManager selectedRoomId: footerItem.selectedRoomId messageId: footerItem.messageId threadmessageId: footerItem.threadmessageId diff --git a/src/core/autotests/rocketchataccounttest.cpp b/src/core/autotests/rocketchataccounttest.cpp --- a/src/core/autotests/rocketchataccounttest.cpp +++ b/src/core/autotests/rocketchataccounttest.cpp @@ -52,8 +52,8 @@ QVERIFY(w.ruqolaServerConfig()); QVERIFY(w.userCompleterFilterModelProxy()); QVERIFY(w.loginMethodModel()); - QVERIFY(w.inputCompleterModel()); - QVERIFY(w.inputThreadMessageCompleterModel()); + QVERIFY(w.inputTextManager()); + QVERIFY(w.inputThreadMessageTextManager()); QVERIFY(w.searchChannelFilterProxyModel()); QVERIFY(w.searchMessageModel()); QCOMPARE(w.searchMessageFilterProxyModel()->sourceModel(), w.searchMessageModel()); diff --git a/src/core/ddpapi/ddpclient.cpp b/src/core/ddpapi/ddpclient.cpp --- a/src/core/ddpapi/ddpclient.cpp +++ b/src/core/ddpapi/ddpclient.cpp @@ -71,7 +71,7 @@ } const QJsonObject obj = root.value(QLatin1String("result")).toObject(); - account->inputTextCompleter(obj); + account->inputTextManager()->inputTextCompleter(obj); } void process_backlog(const QJsonObject &root, RocketChatAccount *account) diff --git a/src/core/inputtextmanager.h b/src/core/inputtextmanager.h --- a/src/core/inputtextmanager.h +++ b/src/core/inputtextmanager.h @@ -29,6 +29,7 @@ class LIBRUQOLACORE_TESTS_EXPORT InputTextManager : public QObject { Q_OBJECT + Q_PROPERTY(InputCompleterModel* inputCompleterModel READ inputCompleterModel CONSTANT) public: enum CompletionForType { Channel = 0, @@ -41,10 +42,10 @@ void inputTextCompleter(const QJsonObject &obj); - Q_REQUIRED_RESULT QString replaceWord(const QString &newWord, const QString &str, int position); + Q_INVOKABLE Q_REQUIRED_RESULT QString replaceWord(const QString &newWord, const QString &str, int position); Q_REQUIRED_RESULT QString applyCompletion(const QString &newWord, const QString &str, int *pPosition); - void setInputTextChanged(const QString &str, int position); + Q_INVOKABLE void setInputTextChanged(const QString &str, int position); void clearCompleter(); diff --git a/src/core/rocketchataccount.h b/src/core/rocketchataccount.h --- a/src/core/rocketchataccount.h +++ b/src/core/rocketchataccount.h @@ -112,8 +112,8 @@ Q_PROPERTY(StatusModel* statusModel READ statusModel CONSTANT) Q_PROPERTY(DiscussionsFilterProxyModel* discussionsFilterProxyModel READ discussionsFilterProxyModel CONSTANT) Q_PROPERTY(SearchChannelFilterProxyModel* searchChannelFilterProxyModel READ searchChannelFilterProxyModel CONSTANT) - Q_PROPERTY(InputCompleterModel* inputCompleterModel READ inputCompleterModel CONSTANT) - Q_PROPERTY(InputCompleterModel* inputThreadMessageCompleterModel READ inputThreadMessageCompleterModel CONSTANT) + Q_PROPERTY(InputTextManager* inputTextManager READ inputTextManager CONSTANT) + Q_PROPERTY(InputTextManager* inputThreadMessageTextManager READ inputThreadMessageTextManager CONSTANT) Q_PROPERTY(ThreadsFilterProxyModel* threadsFilterProxyModel READ threadsFilterProxyModel CONSTANT) Q_PROPERTY(MessageModel* threadMessageModel READ threadMessageModel CONSTANT) Q_PROPERTY(EmoticonModel* emoticonModel READ emoticonModel CONSTANT) @@ -205,13 +205,14 @@ Q_INVOKABLE void addUserToRoom(const QString &username, const QString &roomId, const QString &channelType); Q_INVOKABLE void changeDefaultAuthentication(int index); Q_INVOKABLE void messageSearch(const QString &pattern, const QString &rid); - Q_INVOKABLE void setInputTextChanged(const QString &str, int position); - Q_INVOKABLE Q_REQUIRED_RESULT QString replaceWord(const QString &newWord, const QString &str, int position); InputTextManager *inputTextManager() const { return mInputTextManager; } - + InputTextManager *inputThreadMessageTextManager() const + { + return mInputThreadMessageTextManager; + } Q_INVOKABLE void blockUser(const QString &userId, bool block); Q_INVOKABLE Q_REQUIRED_RESULT QString avatarUrlFromDirectChannel(const QString &rid); Q_INVOKABLE void deleteFileMessage(const QString &roomId, const QString &fileId, const QString &channelType); @@ -274,8 +275,6 @@ SearchChannelModel *searchChannelModel() const; UserCompleterModel *userCompleterModel() const; RocketChatAccountSettings *settings() const; - InputCompleterModel *inputCompleterModel() const; - InputCompleterModel *inputThreadMessageCompleterModel() const; ThreadsFilterProxyModel *threadsFilterProxyModel() const; DDPClient *ddp(); @@ -336,7 +335,6 @@ void insertCompleterUsers(); - void inputTextCompleter(const QJsonObject &obj); PluginAuthenticationInterface *defaultAuthenticationInterface() const; SearchMessageModel *searchMessageModel() const; diff --git a/src/core/rocketchataccount.cpp b/src/core/rocketchataccount.cpp --- a/src/core/rocketchataccount.cpp +++ b/src/core/rocketchataccount.cpp @@ -363,16 +363,6 @@ mRoomModel->setInputMessage(roomId, message); } -void RocketChatAccount::setInputTextChanged(const QString &str, int position) -{ - mInputTextManager->setInputTextChanged(str, position); -} - -QString RocketChatAccount::replaceWord(const QString &newWord, const QString &str, int position) -{ - return mInputTextManager->replaceWord(newWord, str, position); -} - void RocketChatAccount::textEditing(const QString &roomId, bool clearNotification) { mTypingNotification->textNotificationChanged(roomId, clearNotification); @@ -1382,16 +1372,6 @@ return mDefaultAuthenticationInterface; } -InputCompleterModel *RocketChatAccount::inputThreadMessageCompleterModel() const -{ - return mInputThreadMessageTextManager->inputCompleterModel(); -} - -InputCompleterModel *RocketChatAccount::inputCompleterModel() const -{ - return mInputTextManager->inputCompleterModel(); -} - LoginMethodModel *RocketChatAccount::loginMethodModel() const { return mLoginMethodModel; @@ -1788,11 +1768,6 @@ return mAutoTranslateLanguagesModel; } -void RocketChatAccount::inputTextCompleter(const QJsonObject &obj) -{ - mInputTextManager->inputTextCompleter(obj); -} - void RocketChatAccount::updateUser(const QJsonObject &object) { mUserModel->updateUser(object); diff --git a/src/widgets/room/messagetextedit.cpp b/src/widgets/room/messagetextedit.cpp --- a/src/widgets/room/messagetextedit.cpp +++ b/src/widgets/room/messagetextedit.cpp @@ -39,7 +39,7 @@ : CompletionTextEdit(parent) { connect(this, &QTextEdit::textChanged, this, &MessageTextEdit::slotTextChanged); - setCompletionModel(Ruqola::self()->rocketChatAccount()->inputCompleterModel()); + setCompletionModel(Ruqola::self()->rocketChatAccount()->inputTextManager()->inputCompleterModel()); connect(this, &MessageTextEdit::complete, this, &MessageTextEdit::slotComplete); setAcceptRichText(false); @@ -107,7 +107,7 @@ void MessageTextEdit::slotTextChanged() { auto *rcAccount = Ruqola::self()->rocketChatAccount(); - rcAccount->setInputTextChanged(text(), textCursor().position()); + rcAccount->inputTextManager()->setInputTextChanged(text(), textCursor().position()); Q_EMIT textEditing(document()->isEmpty()); }