Commit bcfabf3e authored by Jonah Brüchert's avatar Jonah Brüchert Committed by Linus Jahn

Implement XEP-0308: Last Message Correction (front-end)

parent 4da78fbc
Pipeline #325 passed with stages
in 5 minutes and 21 seconds
......@@ -33,6 +33,7 @@
<file alias="document-send-symbolic.svg">3rdparty/breeze-icons/icons/actions/symbolic/document-send-symbolic.svg</file>
<file alias="go-next-symbolic.svg">3rdparty/breeze-icons/icons/actions/symbolic/go-next-symbolic.svg</file>
<file alias="go-previous-symbolic.svg">3rdparty/breeze-icons/icons/actions/symbolic/go-previous-symbolic.svg</file>
<file alias="edit-symbolic.svg">3rdparty/breeze-icons/icons/actions/symbolic/edit-symbolic.svg</file>
</qresource>
<qresource prefix="/icons/breeze/mimetypes/64">
......
......@@ -137,6 +137,9 @@ Kirigami.ScrollablePage {
mediaType: model.type
mediaGetUrl: model.mediaUrl
mediaLocation: model.mediaLocation
isLastMessage: model.id === kaidan.messageModel.lastMessageId(recipientJid)
textEdit: messageField
edited: model.edited
}
}
......@@ -185,6 +188,7 @@ Kirigami.ScrollablePage {
Controls.TextArea {
id: messageField
Layout.fillWidth: true
placeholderText: qsTr("Compose message")
wrapMode: Controls.TextArea.Wrap
......@@ -192,6 +196,15 @@ Kirigami.ScrollablePage {
bottomPadding: topPadding
selectByMouse: true
background: Item {}
state: "compose"
states: [
State {
name: "compose"
},
State {
name: "edit"
}
]
Keys.onReturnPressed: {
if (event.key === Qt.Key_Return) {
if (event.modifiers & Qt.ControlModifier) {
......@@ -210,7 +223,12 @@ Kirigami.ScrollablePage {
Layout.preferredHeight: Kirigami.Units.gridUnit * 3
padding: 0
Kirigami.Icon {
source: "document-send"
source: {
if (messageField.state == "compose")
return "document-send"
else if (messageField.state == "edit")
return "edit-symbolic"
}
enabled: sendButton.enabled
isMask: true
smooth: true
......@@ -229,9 +247,16 @@ Kirigami.ScrollablePage {
sendButton.enabled = false
// send the message
kaidan.sendMessage(recipientJid, messageField.text)
if (messageField.state == "compose") {
kaidan.sendMessage(recipientJid, messageField.text)
} else if (messageField.state == "edit") {
kaidan.correctMessage(recipientJid, kaidan.messageModel.lastMessageId(recipientJid),
messageField.text)
}
// clean up the text field
messageField.text = ""
messageField.state = "compose"
// reenable the button
sendButton.enabled = true
......
......@@ -31,7 +31,7 @@
import QtQuick 2.6
import QtGraphicalEffects 1.0
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.0 as Controls
import QtQuick.Controls 2.3 as Controls
import org.kde.kirigami 2.0 as Kirigami
import im.kaidan.kaidan 1.0
......@@ -46,6 +46,9 @@ RowLayout {
property int mediaType
property string mediaGetUrl
property string mediaLocation
property var textEdit
property bool isLastMessage
property bool edited
// own messages are on the right, others on the left
layoutDirection: sentByMe ? Qt.RightToLeft : Qt.LeftToRight
......@@ -86,10 +89,31 @@ RowLayout {
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.RightButton
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
kaidan.copyToClipboard(messageBody)
passiveNotification(qsTr("Message copied to clipboard"))
if (mouse.button === Qt.RightButton)
contextMenu.popup()
}
onPressAndHold: {
if (mouse.source === Qt.MouseEventNotSynthesized)
contextMenu.popup()
}
}
Controls.Menu {
id: contextMenu
Controls.MenuItem {
text: qsTr("Copy Message")
onTriggered: kaidan.copyToClipboard(messageBody)
}
Controls.MenuItem {
text: qsTr("Edit Message")
visible: isLastMessage && sentByMe
onTriggered: {
textEdit.text = messageBody
textEdit.state = "edit"
}
}
}
......@@ -157,6 +181,12 @@ RowLayout {
sourceSize.height: Kirigami.Units.gridUnit * 0.65
sourceSize.width: Kirigami.Units.gridUnit * 0.65
}
Kirigami.Icon {
source: "edit-symbolic"
visible: edited
Layout.preferredHeight: Kirigami.Units.gridUnit * 0.65
Layout.preferredWidth: Kirigami.Units.gridUnit * 0.65
}
}
}
}
......
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