This is the start of a significant refactoring of everything related to sending messages, which is roughly:
- the chatbox
- action handling
- message sending on the c++ side
- autocompletion of users/rooms/emojis/commands/things i forgot
Notable changes so far include:
- ChatBox is now a ColumnLayout. As part of this, i removed the height animations for now. <del>as far as i can tell, they were broken anyway.</del> I'll readd them later
- Actions were refactored to live outside of the message sending function and are now each an object; it's mostly a wrapper around a function that is executed when the action is invoked
- Everything that used to live in ChatBoxHelper is now in NeoChatRoom; that means that the exact input status (text, message being replied to, message being edited, attachment) is now saved between room switching).
- To edit/reply an event, set `NeoChatRoom::chatBox{edit,reply}Id` to the desired event id, `NeoChatRoom::chatBox{reply,edit}{User,Message}` will then be updated automatically
- Attachments behave equivalently with `NeoChatRoom::chatBoxAttachmentPath`
- Error message reporting from ActionsHandler has been fixed (same fix as in !517) and moved to NeoChatRoom
Broken at the moment:
- [x] Any kind of autocompletion
- [x] Mentions
- [x] Fancy effects
- [x] sed-style edits
- [x] last-user-message edits and replies
- [x] Some of the actions, probably
- [x] Replies from notifications
- [x] Lots of keyboard shortcuts
- [x] Custom emojis
- [x] ChatBox height animations
TODO:
- [x] User / room mentions based on QTextCursors instead of the hack we currently use
- [x] Refactor autocompletion stuff
- [x] ???
- [x] Profit
128 lines
4.5 KiB
QML
128 lines
4.5 KiB
QML
// SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
import QtQuick 2.15
|
|
import QtQuick.Controls 2.15
|
|
import Qt.labs.platform 1.1
|
|
|
|
import org.kde.kirigami 2.15 as Kirigami
|
|
|
|
import org.kde.neochat 1.0
|
|
import NeoChat.Dialog 1.0
|
|
import NeoChat.Menu 1.0
|
|
|
|
MessageDelegateContextMenu {
|
|
id: root
|
|
|
|
signal closeFullscreen
|
|
|
|
required property var file
|
|
required property var progressInfo
|
|
required property string mimeType
|
|
|
|
property list<Kirigami.Action> actions: [
|
|
Kirigami.Action {
|
|
text: i18n("Open Externally")
|
|
icon.name: "document-open"
|
|
onTriggered: {
|
|
if (file.downloaded) {
|
|
if (!UrlHelper.openUrl(progressInfo.localPath)) {
|
|
UrlHelper.openUrl(progressInfo.localDir);
|
|
}
|
|
} else {
|
|
file.onDownloadedChanged.connect(function() {
|
|
if (!UrlHelper.openUrl(progressInfo.localPath)) {
|
|
UrlHelper.openUrl(progressInfo.localDir);
|
|
}
|
|
});
|
|
currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId))
|
|
}
|
|
}
|
|
},
|
|
Kirigami.Action {
|
|
text: i18n("Save As")
|
|
icon.name: "document-save"
|
|
onTriggered: {
|
|
var dialog = saveAsDialog.createObject(ApplicationWindow.overlay)
|
|
dialog.open()
|
|
dialog.currentFile = dialog.folder + "/" + currentRoom.fileNameToDownload(eventId)
|
|
}
|
|
},
|
|
Kirigami.Action {
|
|
text: i18n("Reply")
|
|
icon.name: "mail-replied-symbolic"
|
|
onTriggered: {
|
|
currentRoom.chatBoxReplyId = eventId
|
|
currentRoom.chatBoxEditId = ""
|
|
root.closeFullscreen()
|
|
}
|
|
},
|
|
Kirigami.Action {
|
|
visible: author.id === currentRoom.localUser.id || currentRoom.canSendState("redact")
|
|
text: i18n("Remove")
|
|
icon.name: "edit-delete-remove"
|
|
icon.color: "red"
|
|
onTriggered: {
|
|
currentRoom.redactEvent(eventId);
|
|
root.closeFullscreen()
|
|
}
|
|
},
|
|
Kirigami.Action {
|
|
text: i18nc("@action:button 'Report' as in 'Report this event to the administrators'", "Report")
|
|
icon.name: "dialog-warning-symbolic"
|
|
visible: author.id !== currentRoom.localUser.id
|
|
onTriggered: applicationWindow().pageStack.pushDialogLayer("qrc:/imports/NeoChat/Menu/Timeline/ReportSheet.qml", {room: currentRoom, eventId: eventId}, {
|
|
title: i18nc("@title", "Report Message"),
|
|
width: Kirigami.Units.gridUnit * 25
|
|
})
|
|
},
|
|
Kirigami.Action {
|
|
text: i18n("View Source")
|
|
icon.name: "code-context"
|
|
onTriggered: {
|
|
applicationWindow().pageStack.pushDialogLayer('qrc:/imports/NeoChat/Menu/Timeline/MessageSourceSheet.qml', {
|
|
sourceText: root.source
|
|
}, {
|
|
title: i18n("Message Source"),
|
|
width: Kirigami.Units.gridUnit * 25
|
|
});
|
|
root.closeFullscreen()
|
|
}
|
|
}
|
|
]
|
|
|
|
property list<Kirigami.Action> nestedActions: [
|
|
ShareAction {
|
|
id: shareAction
|
|
inputData: {
|
|
'urls': [],
|
|
'mimeType': [mimeType]
|
|
}
|
|
property string filename: StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId);
|
|
|
|
doBeforeSharing: () => {
|
|
currentRoom.downloadFile(eventId, filename)
|
|
}
|
|
Component.onCompleted: {
|
|
shareAction.inputData = {
|
|
urls: [filename],
|
|
mimeType: [mimeType]
|
|
};
|
|
}
|
|
}
|
|
]
|
|
Component {
|
|
id: saveAsDialog
|
|
FileDialog {
|
|
fileMode: FileDialog.SaveFile
|
|
folder: StandardPaths.writableLocation(StandardPaths.DownloadLocation)
|
|
onAccepted: {
|
|
if (!currentFile) {
|
|
return;
|
|
}
|
|
currentRoom.downloadFile(eventId, currentFile)
|
|
}
|
|
}
|
|
}
|
|
}
|