Add keybinds for message removal
This commit is contained in:
parent
379a7232df
commit
5ea339ea33
3
TODO.md
3
TODO.md
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
- redact local echo effect
|
- redact local echo effect
|
||||||
- being able to redact local echos
|
- being able to redact local echos
|
||||||
|
- message removed by *display name*
|
||||||
|
- do action on last msg if none selected
|
||||||
|
- unselect before unfocusing
|
||||||
|
|
||||||
## Refactoring
|
## Refactoring
|
||||||
|
|
||||||
|
|
|
@ -287,6 +287,7 @@ class UISettings(JSONDataFile):
|
||||||
"focusNextMessage": ["Ctrl+Down", "Ctrl+J"],
|
"focusNextMessage": ["Ctrl+Down", "Ctrl+J"],
|
||||||
"toggleSelectMessage": ["Ctrl+Space"],
|
"toggleSelectMessage": ["Ctrl+Space"],
|
||||||
"selectMessagesUntilHere": ["Ctrl+Shift+Space"],
|
"selectMessagesUntilHere": ["Ctrl+Shift+Space"],
|
||||||
|
"removeFocusedOrSelectedMessages": ["Ctrl+R", "Ctrl+Del"],
|
||||||
"debugFocusedMessage": ["Ctrl+D"],
|
"debugFocusedMessage": ["Ctrl+D"],
|
||||||
"clearRoomMessages": ["Ctrl+L"],
|
"clearRoomMessages": ["Ctrl+L"],
|
||||||
|
|
||||||
|
|
|
@ -229,26 +229,22 @@ HColumnLayout {
|
||||||
properties: ({
|
properties: ({
|
||||||
userId: chat.userId,
|
userId: chat.userId,
|
||||||
roomId: chat.roomId,
|
roomId: chat.roomId,
|
||||||
|
eventIds: events.map(ev => ev.event_id),
|
||||||
eventIds:
|
|
||||||
redactableEvents
|
|
||||||
.filter(ev => ev.event_type !== "RedactedEvent")
|
|
||||||
.map(ev => ev.event_id),
|
|
||||||
|
|
||||||
onlyOwnMessageWarning:
|
onlyOwnMessageWarning:
|
||||||
! chat.roomInfo.can_redact_all &&
|
! chat.roomInfo.can_redact_all &&
|
||||||
redactableEvents.length < eventList.selectedCount
|
events.length < eventList.selectedCount
|
||||||
})
|
})
|
||||||
|
|
||||||
readonly property var redactableEvents:
|
readonly property var events: {
|
||||||
(
|
|
||||||
eventList.selectedCount ?
|
eventList.selectedCount ?
|
||||||
eventList.getSortedChecked() :
|
eventList.redactableCheckedEvents :
|
||||||
[model]
|
|
||||||
).filter(ev =>
|
eventList.canRedact(currentModel) ?
|
||||||
ev.sender_id === chat.userId ||
|
[model] :
|
||||||
chat.roomInfo.can_redact_all
|
|
||||||
)
|
[]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HMenuItem {
|
HMenuItem {
|
||||||
|
|
|
@ -50,6 +50,45 @@ Rectangle {
|
||||||
eventList.checkFromLastToHere(eventList.currentIndex)
|
eventList.checkFromLastToHere(eventList.currentIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HShortcut {
|
||||||
|
sequences: window.settings.keys.removeFocusedOrSelectedMessages
|
||||||
|
onActivated: utils.makePopup(
|
||||||
|
"Popups/RedactPopup.qml",
|
||||||
|
chat,
|
||||||
|
{
|
||||||
|
userId: chat.userId,
|
||||||
|
roomId: chat.roomId,
|
||||||
|
eventIds:
|
||||||
|
(events || findLastRemovableDelegate()).map(
|
||||||
|
ev => ev.event_id,
|
||||||
|
),
|
||||||
|
isLast: ! events,
|
||||||
|
onlyOwnMessageWarning:
|
||||||
|
! chat.roomInfo.can_redact_all &&
|
||||||
|
events &&
|
||||||
|
events.length < eventList.selectedCount
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
readonly property var events:
|
||||||
|
eventList.selectedCount ?
|
||||||
|
eventList.redactableCheckedEvents :
|
||||||
|
|
||||||
|
eventList.currentItem &&
|
||||||
|
eventList.canRedact(eventList.currentItem.currentModel) ?
|
||||||
|
[eventList.currentItem.currentModel] :
|
||||||
|
|
||||||
|
null
|
||||||
|
|
||||||
|
function findLastRemovableDelegate() {
|
||||||
|
for (let i = 0; i < eventList.model.count && i <= 1000; i++) {
|
||||||
|
const event = eventList.model.get(i)
|
||||||
|
if (eventList.canRedact(event)) return [event]
|
||||||
|
}
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HShortcut {
|
HShortcut {
|
||||||
active: eventList.currentItem
|
active: eventList.currentItem
|
||||||
sequences: window.settings.keys.debugFocusedMessage
|
sequences: window.settings.keys.debugFocusedMessage
|
||||||
|
@ -140,6 +179,9 @@ Rectangle {
|
||||||
property string delegateWithSelectedText: ""
|
property string delegateWithSelectedText: ""
|
||||||
property string selectedText: ""
|
property string selectedText: ""
|
||||||
|
|
||||||
|
readonly property var redactableCheckedEvents:
|
||||||
|
getSortedChecked().filter(ev => eventList.canRedact(ev))
|
||||||
|
|
||||||
|
|
||||||
function copySelectedDelegates() {
|
function copySelectedDelegates() {
|
||||||
if (eventList.selectedText) {
|
if (eventList.selectedText) {
|
||||||
|
@ -174,6 +216,13 @@ Rectangle {
|
||||||
Clipboard.text = contents.join("\n\n")
|
Clipboard.text = contents.join("\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function canRedact(eventModel) {
|
||||||
|
print(eventModel)
|
||||||
|
return eventModel.event_type !== "RedactedEvent" &&
|
||||||
|
(chat.roomInfo.can_redact_all ||
|
||||||
|
eventModel.sender_id === chat.userId)
|
||||||
|
}
|
||||||
|
|
||||||
function canCombine(item, itemAfter) {
|
function canCombine(item, itemAfter) {
|
||||||
if (! item || ! itemAfter) return false
|
if (! item || ! itemAfter) return false
|
||||||
|
|
||||||
|
|
|
@ -6,22 +6,20 @@ import "../Base"
|
||||||
|
|
||||||
BoxPopup {
|
BoxPopup {
|
||||||
summary.text:
|
summary.text:
|
||||||
|
isLast ?
|
||||||
|
qsTr("Remove your last message?") :
|
||||||
|
|
||||||
eventIds.length > 1 ?
|
eventIds.length > 1 ?
|
||||||
qsTr("Remove selected messages?") :
|
qsTr("Remove %1 messages?").arg(eventIds.length) :
|
||||||
qsTr("Remove selected message?")
|
|
||||||
|
qsTr("Remove this message?")
|
||||||
|
|
||||||
details.color: theme.colors.warningText
|
details.color: theme.colors.warningText
|
||||||
details.text:
|
details.text:
|
||||||
onlyOwnMessageWarning ?
|
onlyOwnMessageWarning ?
|
||||||
qsTr("Only your messages will be removed") :
|
qsTr("Only your messages can be removed") :
|
||||||
""
|
""
|
||||||
|
|
||||||
HLabeledTextField {
|
|
||||||
id: reasonField
|
|
||||||
label.text: qsTr("Reason (optional):")
|
|
||||||
Layout.fillWidth: true
|
|
||||||
}
|
|
||||||
|
|
||||||
okText: qsTr("Remove")
|
okText: qsTr("Remove")
|
||||||
box.focusButton: "ok"
|
box.focusButton: "ok"
|
||||||
|
|
||||||
|
@ -31,9 +29,18 @@ BoxPopup {
|
||||||
[roomId, reasonField.field.text, ...eventIds]
|
[roomId, reasonField.field.text, ...eventIds]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
property string roomId: ""
|
property string roomId: ""
|
||||||
property string userId: ""
|
property string userId: ""
|
||||||
|
|
||||||
property var eventIds: []
|
property var eventIds: []
|
||||||
property bool onlyOwnMessageWarning: false
|
property bool onlyOwnMessageWarning: false
|
||||||
|
property bool isLast: false
|
||||||
|
|
||||||
|
|
||||||
|
HLabeledTextField {
|
||||||
|
id: reasonField
|
||||||
|
label.text: qsTr("Optional reason:")
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user