Allow "replying" to an event with a file
Send a pseudo-reply consisting of two messages: a `m.text` which is just a reply with an empty body, then the file event itself. This is a workaround to the restriction imposed by the Matrix API, which prevents us from simply attaching a reply to a media event: https://matrix.org/docs/spec/client_server/latest#rich-replies
This commit is contained in:
@@ -6,8 +6,11 @@ import Qt.labs.platform 1.1
|
||||
HFileDialogOpener {
|
||||
property string userId
|
||||
property string roomId
|
||||
property string replyToEventId: ""
|
||||
property bool destroyWhenDone: false
|
||||
|
||||
signal replied()
|
||||
|
||||
|
||||
fill: false
|
||||
dialog.title: qsTr("Select a file to send")
|
||||
@@ -16,14 +19,17 @@ HFileDialogOpener {
|
||||
onFilesPicked: {
|
||||
for (const file of files) {
|
||||
const path = Qt.resolvedUrl(file).replace(/^file:/, "")
|
||||
const args = [roomId, path, replyToEventId || undefined]
|
||||
|
||||
py.callClientCoro(userId, "send_file", [roomId, path], () => {
|
||||
py.callClientCoro(userId, "send_file", args, () => {
|
||||
if (destroyWhenDone) destroy()
|
||||
|
||||
}, (type, args, error, traceback) => {
|
||||
console.error(`python:\n${traceback}`)
|
||||
if (destroyWhenDone) destroy()
|
||||
})
|
||||
|
||||
if (replyToUserId) replied()
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -28,6 +28,14 @@ Item {
|
||||
readonly property bool composerHasFocus:
|
||||
Boolean(loader.item && loader.item.composer.hasFocus)
|
||||
|
||||
function clearReplyTo() {
|
||||
if (! replyToEventId) return
|
||||
|
||||
replyToEventId = ""
|
||||
replyToUserId = ""
|
||||
replyToDisplayName = ""
|
||||
}
|
||||
|
||||
|
||||
onFocusChanged: if (focus && loader.item) loader.item.composer.takeFocus()
|
||||
onReadyChanged: longLoading = false
|
||||
|
@@ -98,14 +98,6 @@ HTextArea {
|
||||
py.callClientCoro(userId, "room_typing", [chat.roomId, typing])
|
||||
}
|
||||
|
||||
function clearReplyTo() {
|
||||
if (! chat.replyToEventId) return
|
||||
|
||||
chat.replyToEventId = ""
|
||||
chat.replyToUserId = ""
|
||||
chat.replyToDisplayName = ""
|
||||
}
|
||||
|
||||
function addNewLine() {
|
||||
let indents = 0
|
||||
const parts = lineText.split(indent)
|
||||
@@ -171,7 +163,9 @@ HTextArea {
|
||||
userId: chat.userId,
|
||||
roomId: chat.roomId,
|
||||
roomName: chat.roomInfo.display_name,
|
||||
replyToEventId: chat.replyToEventId,
|
||||
},
|
||||
popup => popup.replied.connect(chat.clearReplyTo),
|
||||
)
|
||||
|
||||
Keys.onEscapePressed:
|
||||
|
@@ -28,7 +28,9 @@ HButton {
|
||||
roomId: chat.roomId,
|
||||
roomName: chat.roomInfo.display_name,
|
||||
filePath: Clipboard.text.trim(),
|
||||
replyToEventId: chat.replyToEventId,
|
||||
},
|
||||
popup => popup.replied.connect(chat.clearReplyTo),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -36,6 +38,8 @@ HButton {
|
||||
id: sendFilePicker
|
||||
userId: chat.userId
|
||||
roomId: chat.roomId
|
||||
replyToEventId: chat.replyToEventId
|
||||
onReplied: chat.clearReplyTo()
|
||||
|
||||
HShortcut {
|
||||
sequences: window.settings.keys.sendFile
|
||||
|
@@ -16,6 +16,9 @@ HColumnPopup {
|
||||
property string userId
|
||||
property string roomId
|
||||
property string roomName
|
||||
property string replyToEventId: ""
|
||||
|
||||
signal replied()
|
||||
|
||||
|
||||
contentWidthLimit: theme.controls.popup.defaultWidth * 1.25
|
||||
@@ -26,11 +29,14 @@ HColumnPopup {
|
||||
text: qsTr("Send")
|
||||
icon.name: "confirm-uploading-file"
|
||||
onClicked: {
|
||||
py.callClientCoro(
|
||||
popup.userId,
|
||||
"send_clipboard_image",
|
||||
[popup.roomId, Clipboard.image],
|
||||
)
|
||||
const args = [
|
||||
popup.roomId,
|
||||
Clipboard.image,
|
||||
popup.replyToEventId || undefined,
|
||||
]
|
||||
|
||||
py.callClientCoro(popup.userId, "send_clipboard_image", args)
|
||||
if (popup.replyToEventId) popup.replied()
|
||||
popup.close()
|
||||
}
|
||||
}
|
||||
|
@@ -13,9 +13,12 @@ HColumnPopup {
|
||||
property string roomId
|
||||
property string roomName
|
||||
property string filePath
|
||||
property string replyToEventId: ""
|
||||
|
||||
readonly property string fileName: filePath.split("/").slice(-1)[0]
|
||||
|
||||
signal replied()
|
||||
|
||||
|
||||
contentWidthLimit: theme.controls.popup.defaultWidth * 1.25
|
||||
|
||||
@@ -25,9 +28,14 @@ HColumnPopup {
|
||||
text: qsTr("Send")
|
||||
icon.name: "confirm-uploading-file"
|
||||
onClicked: {
|
||||
py.callClientCoro(
|
||||
popup.userId, "send_file", [popup.roomId, filePath],
|
||||
)
|
||||
const args = [
|
||||
popup.roomId,
|
||||
popup.filePath,
|
||||
popup.replyToEventId || undefined,
|
||||
]
|
||||
|
||||
py.callClientCoro(popup.userId, "send_file", args)
|
||||
if (popup.replyToEventId) popup.replied()
|
||||
popup.close()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user