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
148 lines
3.6 KiB
QML
148 lines
3.6 KiB
QML
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.de>
|
|
// SPDX-FileCopyrightText: 2020 Noah Davis <noahadvs@gmail.com>
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
import QtQuick 2.15
|
|
import QtQuick.Controls 2.15 as QQC2
|
|
import QtQuick.Layouts 1.15
|
|
import org.kde.kirigami 2.15 as Kirigami
|
|
|
|
import org.kde.neochat 1.0
|
|
import NeoChat.Component.ChatBox 1.0
|
|
import NeoChat.Component.Emoji 1.0
|
|
|
|
ColumnLayout {
|
|
id: chatBox
|
|
|
|
property alias inputFieldText: chatBar.inputFieldText
|
|
|
|
signal messageSent()
|
|
|
|
spacing: 0
|
|
|
|
Kirigami.Separator {
|
|
id: connectionPaneSeparator
|
|
visible: connectionPane.visible
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
QQC2.Pane {
|
|
id: connectionPane
|
|
padding: fontMetrics.lineSpacing * 0.25
|
|
FontMetrics {
|
|
id: fontMetrics
|
|
font: networkLabel.font
|
|
}
|
|
spacing: 0
|
|
Kirigami.Theme.colorSet: Kirigami.Theme.View
|
|
background: Rectangle {
|
|
color: Kirigami.Theme.backgroundColor
|
|
}
|
|
visible: !Controller.isOnline
|
|
Layout.fillWidth: true
|
|
QQC2.Label {
|
|
id: networkLabel
|
|
text: i18n("NeoChat is offline. Please check your network connection.")
|
|
}
|
|
}
|
|
|
|
Kirigami.Separator {
|
|
id: emojiPickerLoaderSeparator
|
|
visible: emojiPickerLoader.visible
|
|
Layout.fillWidth: true
|
|
height: visible ? implicitHeight : 0
|
|
}
|
|
|
|
Loader {
|
|
id: emojiPickerLoader
|
|
active: visible
|
|
visible: chatBar.emojiPaneOpened
|
|
Layout.fillWidth: true
|
|
sourceComponent: QQC2.Pane {
|
|
topPadding: 0
|
|
bottomPadding: 0
|
|
rightPadding: 0
|
|
leftPadding: 0
|
|
Kirigami.Theme.colorSet: Kirigami.Theme.View
|
|
contentItem: EmojiPicker {
|
|
textArea: chatBar.textField
|
|
onChosen: addText(emoji)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
Kirigami.Separator {
|
|
id: replySeparator
|
|
visible: replyPane.visible
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
ReplyPane {
|
|
id: replyPane
|
|
visible: currentRoom.chatBoxReplyId.length > 0 || currentRoom.chatBoxEditId.length > 0
|
|
Layout.fillWidth: true
|
|
|
|
onReplyCancelled: {
|
|
chatBox.focusInputField()
|
|
}
|
|
}
|
|
|
|
Kirigami.Separator {
|
|
id: attachmentSeparator
|
|
visible: attachmentPane.visible
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
AttachmentPane {
|
|
id: attachmentPane
|
|
visible: currentRoom.chatBoxAttachmentPath.length > 0
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Kirigami.Separator {
|
|
id: chatBarSeparator
|
|
visible: chatBar.visible
|
|
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
ChatBar {
|
|
id: chatBar
|
|
visible: currentRoom.canSendEvent("m.room.message")
|
|
|
|
Layout.fillWidth: true
|
|
|
|
onCloseAllTriggered: closeAll()
|
|
onMessageSent: {
|
|
closeAll()
|
|
chatBox.messageSent();
|
|
}
|
|
|
|
Behavior on implicitHeight {
|
|
NumberAnimation {
|
|
property: "implicitHeight"
|
|
duration: Kirigami.Units.shortDuration
|
|
easing.type: Easing.OutCubic
|
|
}
|
|
}
|
|
}
|
|
|
|
function addText(text) {
|
|
chatBox.inputFieldText = inputFieldText + text
|
|
}
|
|
|
|
function insertText(str) {
|
|
chatBox.inputFieldText = inputFieldText.substr(0, inputField.cursorPosition) + str + inputFieldText.substr(inputField.cursorPosition)
|
|
}
|
|
|
|
function focusInputField() {
|
|
chatBar.inputFieldForceActiveFocusTriggered()
|
|
}
|
|
|
|
function closeAll() {
|
|
// TODO clear();
|
|
chatBar.emojiPaneOpened = false;
|
|
}
|
|
}
|