2020-03-27 07:31:57 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import "../Base"
|
2020-07-12 12:52:14 +10:00
|
|
|
import "../Base/Buttons"
|
2020-03-27 07:31:57 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
HFlickableColumnPopup {
|
|
|
|
id: popup
|
2020-04-03 01:19:43 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
property string preferUserId: ""
|
|
|
|
property string roomId: ""
|
2020-03-27 07:31:57 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
property var eventSenderAndIds: [] // [[senderId, event.id], ...]
|
|
|
|
property bool onlyOwnMessageWarning: false
|
|
|
|
property bool isLast: false
|
2020-04-02 04:33:19 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
function remove() {
|
2020-04-03 21:50:24 +11:00
|
|
|
const idsForSender = {} // {senderId: [event.id, ...]}
|
2020-03-27 07:31:57 +11:00
|
|
|
|
2020-04-03 21:50:24 +11:00
|
|
|
for (const [senderId, eventClientId] of eventSenderAndIds) {
|
2020-04-03 21:13:45 +11:00
|
|
|
if (! idsForSender[senderId])
|
|
|
|
idsForSender[senderId] = []
|
2020-04-03 01:19:43 +11:00
|
|
|
|
2020-04-03 21:50:24 +11:00
|
|
|
idsForSender[senderId].push(eventClientId)
|
2020-04-03 21:13:45 +11:00
|
|
|
}
|
|
|
|
|
2020-04-03 21:50:24 +11:00
|
|
|
for (const [senderId, eventClientIds] of Object.entries(idsForSender))
|
2020-04-03 21:13:45 +11:00
|
|
|
py.callClientCoro(
|
|
|
|
mainUI.accountIds.includes(senderId) ? senderId : preferUserId,
|
|
|
|
"room_mass_redact",
|
2020-06-03 10:14:55 +10:00
|
|
|
[roomId, reasonField.item.text, ...eventClientIds]
|
2020-04-03 21:13:45 +11:00
|
|
|
)
|
2020-06-25 22:32:08 +10:00
|
|
|
|
|
|
|
popup.close()
|
2020-04-03 21:13:45 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-12 12:52:14 +10:00
|
|
|
page.footer: AutoDirectionLayout {
|
2020-06-25 22:32:08 +10:00
|
|
|
ApplyButton {
|
|
|
|
text: qsTr("Remove")
|
|
|
|
icon.name: "remove-message"
|
|
|
|
onClicked: remove()
|
|
|
|
}
|
|
|
|
|
|
|
|
CancelButton {
|
|
|
|
onClicked: popup.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onOpened: reasonField.item.forceActiveFocus()
|
2020-06-26 00:27:24 +10:00
|
|
|
onKeyboardAccept: popup.remove()
|
2020-03-27 07:31:57 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
SummaryLabel {
|
|
|
|
text:
|
|
|
|
isLast ?
|
|
|
|
qsTr("Remove your last message?") :
|
|
|
|
|
|
|
|
eventSenderAndIds.length > 1 ?
|
|
|
|
qsTr("Remove %1 messages?").arg(eventSenderAndIds.length) :
|
|
|
|
|
|
|
|
qsTr("Remove this message?")
|
|
|
|
}
|
|
|
|
|
|
|
|
DetailsLabel {
|
|
|
|
color: theme.colors.warningText
|
|
|
|
text:
|
|
|
|
onlyOwnMessageWarning ?
|
|
|
|
qsTr("Only your messages can be removed") :
|
|
|
|
""
|
|
|
|
}
|
2020-04-03 01:19:43 +11:00
|
|
|
|
2020-06-03 10:14:55 +10:00
|
|
|
HLabeledItem {
|
2020-04-03 01:19:43 +11:00
|
|
|
id: reasonField
|
|
|
|
label.text: qsTr("Optional reason:")
|
2020-04-03 22:53:16 +11:00
|
|
|
|
2020-04-03 01:19:43 +11:00
|
|
|
Layout.fillWidth: true
|
2020-06-03 10:14:55 +10:00
|
|
|
|
|
|
|
HTextField {
|
|
|
|
width: parent.width
|
|
|
|
}
|
2020-04-03 01:19:43 +11:00
|
|
|
}
|
2020-03-27 07:31:57 +11:00
|
|
|
}
|