diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index ec040b7..8620e15 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -330,6 +330,76 @@ Page { visible: ( chatPage.isBasicGroup || chatPage.isSuperGroup ) && !chatPage.isChannel } + Row { + id: inReplyToRow + spacing: Theme.paddingSmall + visible: display.reply_to_message_id !== 0 + width: parent.width + + property variant inReplyToMessage; + + Component.onCompleted: { + if (visible) { + tdLibWrapper.getMessage(chatInformation.id, display.reply_to_message_id); + } + } + + Connections { + target: tdLibWrapper + onReceivedMessage: { + if (messageId === display.reply_to_message_id.toString()) { + inReplyToRow.inReplyToMessage = message; + inReplyToUserText.text = (inReplyToRow.inReplyToMessage.sender_user_id !== chatPage.myUserId) ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(inReplyToRow.inReplyToMessage.sender_user_id)), inReplyToUserText.font.pixelSize) : qsTr("You"); + inReplyToMessageText.text = Emoji.emojify(Functions.getMessageText(inReplyToRow.inReplyToMessage, true), inReplyToMessageText.font.pixelSize); + } + } + } + + Rectangle { + id: inReplyToMessageRectangle + height: inReplyToMessageColumn.height + width: Theme.paddingSmall + color: Theme.secondaryHighlightColor + border.width: 0 + } + + Column { + id: inReplyToMessageColumn + spacing: Theme.paddingSmall + width: parent.width - Theme.paddingSmall - inReplyToMessageRectangle.width + + Text { + id: inReplyToUserText + + width: parent.width + font.pixelSize: Theme.fontSizeExtraSmall + font.weight: Font.ExtraBold + color: Theme.primaryColor + maximumLineCount: 1 + elide: Text.ElideRight + textFormat: Text.StyledText + horizontalAlignment: Text.AlignLeft + } + + Text { + id: inReplyToMessageText + font.pixelSize: Theme.fontSizeExtraSmall + color: Theme.primaryColor + width: parent.width + elide: Text.ElideRight + textFormat: Text.StyledText + onTruncatedChanged: { + // There is obviously a bug in QML in truncating text with images. + // We simply remove Emojis then... + if (truncated) { + text = text.replace(/\]+\/\>/g, ""); + } + } + } + } + + } + Text { id: messageText diff --git a/src/tdlibreceiver.cpp b/src/tdlibreceiver.cpp index 88f2890..d8c51f5 100644 --- a/src/tdlibreceiver.cpp +++ b/src/tdlibreceiver.cpp @@ -72,6 +72,7 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc if (objectTypeName == "updateChatOnlineMemberCount") { this->processChatOnlineMemberCountUpdated(receivedInformation); } if (objectTypeName == "messages") { this->processMessages(receivedInformation); } if (objectTypeName == "updateNewMessage") { this->processUpdateNewMessage(receivedInformation); } + if (objectTypeName == "message") { this->processMessage(receivedInformation); } } void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation) @@ -212,3 +213,11 @@ void TDLibReceiver::processUpdateNewMessage(const QVariantMap &receivedInformati qDebug() << "[TDLibReceiver] Received new message for chat " << chatId; emit newMessageReceived(chatId, receivedInformation.value("message").toMap()); } + +void TDLibReceiver::processMessage(const QVariantMap &receivedInformation) +{ + QString chatId = receivedInformation.value("chat_id").toString(); + QString messageId = receivedInformation.value("id").toString(); + qDebug() << "[TDLibReceiver] Received message " << chatId << messageId; + emit messageInformation(messageId, receivedInformation); +} diff --git a/src/tdlibreceiver.h b/src/tdlibreceiver.h index 11905a1..cf779b6 100644 --- a/src/tdlibreceiver.h +++ b/src/tdlibreceiver.h @@ -54,6 +54,7 @@ signals: void chatOnlineMemberCountUpdated(const QString &chatId, const int &onlineMemberCount); void messagesReceived(const QVariantList &messages); void newMessageReceived(const QString &chatId, const QVariantMap &message); + void messageInformation(const QString &messageId, const QVariantMap &message); private: void *tdLibClient; @@ -79,6 +80,7 @@ private: void processChatOnlineMemberCountUpdated(const QVariantMap &receivedInformation); void processMessages(const QVariantMap &receivedInformation); void processUpdateNewMessage(const QVariantMap &receivedInformation); + void processMessage(const QVariantMap &receivedInformation); }; #endif // TDLIBRECEIVER_H diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 38fabcb..3fca934 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -58,6 +58,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent) connect(this->tdLibReceiver, SIGNAL(chatOnlineMemberCountUpdated(QString, int)), this, SLOT(handleChatOnlineMemberCountUpdated(QString, int))); connect(this->tdLibReceiver, SIGNAL(messagesReceived(QVariantList)), this, SLOT(handleMessagesReceived(QVariantList))); connect(this->tdLibReceiver, SIGNAL(newMessageReceived(QString, QVariantMap)), this, SLOT(handleNewMessageReceived(QString, QVariantMap))); + connect(this->tdLibReceiver, SIGNAL(messageInformation(QString, QVariantMap)), this, SLOT(handleMessageInformation(QString, QVariantMap))); this->tdLibReceiver->start(); @@ -200,6 +201,16 @@ void TDLibWrapper::sendTextMessage(const QString &chatId, const QString &message this->sendRequest(requestObject); } +void TDLibWrapper::getMessage(const QString &chatId, const QString &messageId) +{ + qDebug() << "[TDLibWrapper] Retrieving message " << chatId << messageId; + QVariantMap requestObject; + requestObject.insert("@type", "getMessage"); + requestObject.insert("chat_id", chatId); + requestObject.insert("message_id", messageId); + this->sendRequest(requestObject); +} + QVariantMap TDLibWrapper::getUserInformation() { return this->userInformation; @@ -446,6 +457,11 @@ void TDLibWrapper::handleNewMessageReceived(const QString &chatId, const QVarian emit newMessageReceived(chatId, message); } +void TDLibWrapper::handleMessageInformation(const QString &messageId, const QVariantMap &message) +{ + emit receivedMessage(messageId, message); +} + void TDLibWrapper::setInitialParameters() { qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib"; diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index 3b3fc00..9a40127 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -81,6 +81,7 @@ public: 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); + Q_INVOKABLE void getMessage(const QString &chatId, const QString &messageId); signals: void versionDetected(const QString &version); @@ -103,6 +104,7 @@ signals: void newMessageReceived(const QString &chatId, const QVariantMap &message); void copyToDownloadsSuccessful(const QString &fileName, const QString &filePath); void copyToDownloadsError(const QString &fileName, const QString &filePath); + void receivedMessage(const QString &messageId, const QVariantMap &message); public slots: void handleVersionDetected(const QString &version); @@ -123,6 +125,7 @@ public slots: void handleChatOnlineMemberCountUpdated(const QString &chatId, const int &onlineMemberCount); void handleMessagesReceived(const QVariantList &messages); void handleNewMessageReceived(const QString &chatId, const QVariantMap &message); + void handleMessageInformation(const QString &messageId, const QVariantMap &message); private: void *tdLibClient;