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:
miruka
2020-08-24 10:17:04 -04:00
parent 6d9a013d5d
commit 0d2be820fe
7 changed files with 76 additions and 24 deletions

View File

@@ -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

View File

@@ -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:

View File

@@ -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