Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 30db3ee1 authored by Linus Jahn's avatar Linus Jahn

Fix message editing bugs

There were three edge cases:
1) The wrong message was replaced:
   - You send a message
   - You open the edit menu
   - Contact or another device of you sends a message
     (lastMessageId is updated)
   - You finish your edit and a message is sent to replace your contacts
     message, which is obviously not what we want. Database and XMPP
     both get the wrong message id to replace.
2) Can't edit last message:
   - You send a message
   - Contact sends a message
     (lastMessageId is updated)
   - You can't edit your last message, although that is expected to work.

The solution was to only update the lastMessageId for own messages.

Also the QML code has been slightly beautified by the use of a signal.
parent 7f50d351
......@@ -183,11 +183,10 @@ void MessageModel::updateMessage(const QString id, Message msg)
setRecord(recId, rec);
submitAll();
// check if we're author/recipient
QVariant jid = rec.value("author").toString() == ownJid ? rec.value("recipient")
: rec.value("author");
// update last message id
lastMsgIdCache[jid.toString()] = newId;
if (!msg.id.isEmpty() && msg.author == ownJid) {
lastMsgIdCache[msg.recipient] = msg.id;
}
}
void MessageModel::addMessage(Message msg)
......@@ -225,10 +224,8 @@ void MessageModel::addMessage(Message msg)
submitAll();
// update last message id
if (!msg.id.isEmpty()) {
// check if we're author/recipient
QString jid = msg.author == ownJid ? msg.recipient : msg.author;
lastMsgIdCache[jid] = msg.id;
// update last message id, in case we're author
if (!msg.id.isEmpty() && msg.author == ownJid) {
lastMsgIdCache[msg.recipient] = msg.id;
}
}
......@@ -41,6 +41,7 @@ Kirigami.ScrollablePage {
property string chatName
property string recipientJid
property bool isWritingSpoiler
property string messageToCorrect
title: chatName
keyboardNavigationEnabled: true
......@@ -145,11 +146,16 @@ Kirigami.ScrollablePage {
mediaGetUrl: model.mediaUrl
mediaLocation: model.mediaLocation
isLastMessage: model.id === kaidan.messageModel.lastMessageId(recipientJid)
textEdit: messageField
edited: model.edited
isSpoiler: model.isSpoiler
isShowingSpoiler: false
spoilerHint: model.spoilerHint
onMessageEditRequested: {
messageToCorrect = id
messageField.text = body
messageField.state = "edit"
}
}
}
......@@ -327,10 +333,10 @@ Kirigami.ScrollablePage {
// send the message
if (messageField.state == "compose") {
kaidan.sendMessage(recipientJid, messageField.text,
isWritingSpoiler, spoilerHintField.text)
isWritingSpoiler, spoilerHintField.text)
} else if (messageField.state == "edit") {
kaidan.correctMessage(recipientJid, kaidan.messageModel.lastMessageId(recipientJid),
messageField.text)
kaidan.correctMessage(recipientJid, messageToCorrect,
messageField.text)
}
// clean up the text fields
......
......@@ -47,7 +47,6 @@ RowLayout {
property int mediaType
property string mediaGetUrl
property string mediaLocation
property var textEdit
property bool isLastMessage
property bool edited
property bool isLoading: kaidan.transferCache.hasUpload(msgId)
......@@ -62,6 +61,8 @@ RowLayout {
property bool isShowingSpoiler
property string spoilerHint
signal messageEditRequested(string id, string body)
// own messages are on the right, others on the left
layoutDirection: sentByMe ? Qt.RightToLeft : Qt.LeftToRight
spacing: 8
......@@ -137,10 +138,7 @@ RowLayout {
Controls.MenuItem {
text: qsTr("Edit Message")
enabled: isLastMessage && sentByMe
onTriggered: {
textEdit.text = messageBody
textEdit.state = "edit"
}
onTriggered: root.messageEditRequested(msgId, messageBody)
}
}
}
......@@ -157,7 +155,7 @@ RowLayout {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
if (mouse.button === Qt.LeftButton){
if (mouse.button === Qt.LeftButton) {
isShowingSpoiler = !isShowingSpoiler
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment