Add keybinds for message removal

This commit is contained in:
miruka 2020-04-02 10:19:43 -04:00
parent 379a7232df
commit 5ea339ea33
5 changed files with 87 additions and 31 deletions

View File

@ -2,6 +2,9 @@
- redact local echo effect
- being able to redact local echos
- message removed by *display name*
- do action on last msg if none selected
- unselect before unfocusing
## Refactoring

View File

@ -287,6 +287,7 @@ class UISettings(JSONDataFile):
"focusNextMessage": ["Ctrl+Down", "Ctrl+J"],
"toggleSelectMessage": ["Ctrl+Space"],
"selectMessagesUntilHere": ["Ctrl+Shift+Space"],
"removeFocusedOrSelectedMessages": ["Ctrl+R", "Ctrl+Del"],
"debugFocusedMessage": ["Ctrl+D"],
"clearRoomMessages": ["Ctrl+L"],

View File

@ -229,26 +229,22 @@ HColumnLayout {
properties: ({
userId: chat.userId,
roomId: chat.roomId,
eventIds:
redactableEvents
.filter(ev => ev.event_type !== "RedactedEvent")
.map(ev => ev.event_id),
eventIds: events.map(ev => ev.event_id),
onlyOwnMessageWarning:
! chat.roomInfo.can_redact_all &&
redactableEvents.length < eventList.selectedCount
events.length < eventList.selectedCount
})
readonly property var redactableEvents:
(
readonly property var events: {
eventList.selectedCount ?
eventList.getSortedChecked() :
[model]
).filter(ev =>
ev.sender_id === chat.userId ||
chat.roomInfo.can_redact_all
)
eventList.redactableCheckedEvents :
eventList.canRedact(currentModel) ?
[model] :
[]
}
}
HMenuItem {

View File

@ -50,6 +50,45 @@ Rectangle {
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 {
active: eventList.currentItem
sequences: window.settings.keys.debugFocusedMessage
@ -140,6 +179,9 @@ Rectangle {
property string delegateWithSelectedText: ""
property string selectedText: ""
readonly property var redactableCheckedEvents:
getSortedChecked().filter(ev => eventList.canRedact(ev))
function copySelectedDelegates() {
if (eventList.selectedText) {
@ -174,6 +216,13 @@ Rectangle {
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) {
if (! item || ! itemAfter) return false

View File

@ -6,22 +6,20 @@ import "../Base"
BoxPopup {
summary.text:
isLast ?
qsTr("Remove your last message?") :
eventIds.length > 1 ?
qsTr("Remove selected messages?") :
qsTr("Remove selected message?")
qsTr("Remove %1 messages?").arg(eventIds.length) :
qsTr("Remove this message?")
details.color: theme.colors.warningText
details.text:
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")
box.focusButton: "ok"
@ -31,9 +29,18 @@ BoxPopup {
[roomId, reasonField.field.text, ...eventIds]
)
property string roomId: ""
property string userId: ""
property var eventIds: []
property bool onlyOwnMessageWarning: false
property bool isLast: false
HLabeledTextField {
id: reasonField
label.text: qsTr("Optional reason:")
Layout.fillWidth: true
}
}