From cc266aa58b51376e4ae0d31a5a4ec1957226af8f Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Sun, 23 Aug 2020 00:17:34 +0200 Subject: [PATCH] Sending text messages works... :D --- qml/pages/ChatPage.qml | 4 +++- src/tdlibwrapper.cpp | 16 ++++++++++++++++ src/tdlibwrapper.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index a6c2055..cf636b4 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -355,7 +355,9 @@ Page { icon.source: "image://theme/icon-m-chat" anchors.horizontalCenter: parent.horizontalCenter onClicked: { - // Send message + tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text); + newMessageTextField.text = ""; + newMessageTextField.focus = false; } } } diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 4c07529..a6ed782 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -180,6 +180,22 @@ void TDLibWrapper::viewMessage(const QString &chatId, const QString &messageId) this->sendRequest(requestObject); } +void TDLibWrapper::sendTextMessage(const QString &chatId, const QString &message) +{ + qDebug() << "[TDLibWrapper] Sending text message " << chatId << message; + QVariantMap requestObject; + requestObject.insert("@type", "sendMessage"); + requestObject.insert("chat_id", chatId); + QVariantMap inputMessageContent; + inputMessageContent.insert("@type", "inputMessageText"); + QVariantMap formattedText; + formattedText.insert("text", message); + formattedText.insert("@type", "formattedText"); + inputMessageContent.insert("text", formattedText); + requestObject.insert("input_message_content", inputMessageContent); + this->sendRequest(requestObject); +} + QVariantMap TDLibWrapper::getUserInformation() { return this->userInformation; diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index f8a8849..cbbda40 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -78,6 +78,7 @@ public: Q_INVOKABLE void closeChat(const QString &chatId); Q_INVOKABLE void getChatHistory(const QString &chatId, const qlonglong &fromMessageId = 0, const int &offset = 0, const int &limit = 50, const bool &onlyLocal = false); Q_INVOKABLE void viewMessage(const QString &chatId, const QString &messageId); + Q_INVOKABLE void sendTextMessage(const QString &chatId, const QString &message); signals: void versionDetected(const QString &version);