diff --git a/qml/components/InReplyToRow.qml b/qml/components/InReplyToRow.qml index 33d87e8..79823c0 100644 --- a/qml/components/InReplyToRow.qml +++ b/qml/components/InReplyToRow.qml @@ -27,25 +27,17 @@ Row { id: inReplyToRow spacing: Theme.paddingSmall width: parent.width - visible: originalMessageId !== "0" - property string originalMessageId: "0"; - property variant inReplyToMessage; + property string myUserId; + property variant inReplyToMessage: ""; - onOriginalMessageIdChanged: { - if (originalMessageId !== "0") { - tdLibWrapper.getMessage(chatInformation.id, originalMessageId); - } - } - - Connections { - target: tdLibWrapper - onReceivedMessage: { - if (messageId === originalMessageId) { - 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); - } + onInReplyToMessageChanged: { + if (typeof inReplyToRow.inReplyToMessage === "object") { + inReplyToUserText.text = (inReplyToRow.inReplyToMessage.sender_user_id !== inReplyToRow.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); + } else { + inReplyToUserText.text = ""; + inReplyToMessageText.text = ""; } } diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index a74dab3..fc86d3a 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -279,7 +279,7 @@ Page { menu: ContextMenu { MenuItem { onClicked: { - newMessageColumn.replyToMessageId = display.id; + newMessageInReplyToRow.inReplyToMessage = display; sendMessageColumn.focus = true; } text: qsTr("Reply to Message") @@ -333,6 +333,22 @@ Page { width: messageBackground.width - Theme.horizontalPageMargin anchors.centerIn: messageBackground + Component.onCompleted: { + if (display.reply_to_message_id !== 0) { + tdLibWrapper.getMessage(chatInformation.id, display.reply_to_message_id); + } + } + + Connections { + target: tdLibWrapper + onReceivedMessage: { + if (messageId === display.reply_to_message_id.toString()) { + messageInReplyToRow.inReplyToMessage = message; + messageInReplyToRow.visible = true; + } + } + } + Text { id: userText @@ -349,7 +365,9 @@ Page { } InReplyToRow { - originalMessageId: display.reply_to_message_id + id: messageInReplyToRow + myUserId: chatPage.myUserId + visible: false } Text { @@ -445,11 +463,20 @@ Page { width: parent.width - ( 2 * Theme.horizontalPageMargin ) anchors.horizontalCenter: parent.horizontalCenter - property string replyToMessageId: "0" - InReplyToRow { - originalMessageId: newMessageColumn.replyToMessageId + onInReplyToMessageChanged: { + console.log("This is a reply!"); + if (typeof newMessageInReplyToRow.inReplyToMessage === "object") { + visible: true; + } else { + visible: false; + } + } + + id: newMessageInReplyToRow + myUserId: chatPage.myUserId anchors.horizontalCenter: parent.horizontalCenter + visible: false } Row { @@ -471,7 +498,7 @@ Page { labelVisible: false onFocusChanged: { if (!focus) { - newMessageColumn.replyToMessageId = "0"; + newMessageInReplyToRow.inReplyToMessage = ""; } } } diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index c2bc5b1..a87d2e0 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -89,7 +89,6 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages) while (messagesIterator.hasNext()) { QVariantMap currentMessage = messagesIterator.next().toMap(); if (currentMessage.value("chat_id").toString() == this->chatId) { - this->messagesToBeAdded.append(currentMessage); } }