Be able to redact our other account's events
This commit is contained in:
parent
8af63a304f
commit
5cb013838b
|
@ -222,14 +222,16 @@ HColumnLayout {
|
||||||
HMenuItemPopupSpawner {
|
HMenuItemPopupSpawner {
|
||||||
icon.name: "remove-message"
|
icon.name: "remove-message"
|
||||||
text: qsTr("Remove")
|
text: qsTr("Remove")
|
||||||
enabled: properties.eventIds.length
|
enabled: properties.eventSenderAndIds.length
|
||||||
|
|
||||||
popup: "Popups/RedactPopup.qml"
|
popup: "Popups/RedactPopup.qml"
|
||||||
popupParent: chat
|
popupParent: chat
|
||||||
properties: ({
|
properties: ({
|
||||||
userId: chat.userId,
|
preferUserId: chat.userId,
|
||||||
roomId: chat.roomId,
|
roomId: chat.roomId,
|
||||||
eventIds: events.map(ev => ev.event_id),
|
|
||||||
|
eventSenderAndIds:
|
||||||
|
events.map(ev => [ev.sender_id, ev.event_id]),
|
||||||
|
|
||||||
onlyOwnMessageWarning:
|
onlyOwnMessageWarning:
|
||||||
! chat.roomInfo.can_redact_all &&
|
! chat.roomInfo.can_redact_all &&
|
||||||
|
|
|
@ -56,13 +56,16 @@ Rectangle {
|
||||||
"Popups/RedactPopup.qml",
|
"Popups/RedactPopup.qml",
|
||||||
chat,
|
chat,
|
||||||
{
|
{
|
||||||
userId: chat.userId,
|
preferUserId: chat.userId,
|
||||||
roomId: chat.roomId,
|
roomId: chat.roomId,
|
||||||
eventIds:
|
|
||||||
|
eventSenderAndIds:
|
||||||
(events || findLastRemovableDelegate()).map(
|
(events || findLastRemovableDelegate()).map(
|
||||||
ev => ev.event_id,
|
ev => [ev.sender_id, ev.event_id],
|
||||||
),
|
),
|
||||||
|
|
||||||
isLast: ! events,
|
isLast: ! events,
|
||||||
|
|
||||||
onlyOwnMessageWarning:
|
onlyOwnMessageWarning:
|
||||||
! chat.roomInfo.can_redact_all &&
|
! chat.roomInfo.can_redact_all &&
|
||||||
events &&
|
events &&
|
||||||
|
@ -84,7 +87,7 @@ Rectangle {
|
||||||
for (let i = 0; i < eventList.model.count && i <= 1000; i++) {
|
for (let i = 0; i < eventList.model.count && i <= 1000; i++) {
|
||||||
const event = eventList.model.get(i)
|
const event = eventList.model.get(i)
|
||||||
if (eventList.canRedact(event) &&
|
if (eventList.canRedact(event) &&
|
||||||
event.sender_id === chat.userId) return [event]
|
mainUI.accountIds.includes(event.sender_id)) return [event]
|
||||||
}
|
}
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
@ -220,7 +223,7 @@ Rectangle {
|
||||||
function canRedact(eventModel) {
|
function canRedact(eventModel) {
|
||||||
return eventModel.event_type !== "RedactedEvent" &&
|
return eventModel.event_type !== "RedactedEvent" &&
|
||||||
(chat.roomInfo.can_redact_all ||
|
(chat.roomInfo.can_redact_all ||
|
||||||
eventModel.sender_id === chat.userId)
|
mainUI.accountIds.includes(eventModel.sender_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
function canCombine(item, itemAfter) {
|
function canCombine(item, itemAfter) {
|
||||||
|
|
|
@ -9,8 +9,8 @@ BoxPopup {
|
||||||
isLast ?
|
isLast ?
|
||||||
qsTr("Remove your last message?") :
|
qsTr("Remove your last message?") :
|
||||||
|
|
||||||
eventIds.length > 1 ?
|
eventSenderAndIds.length > 1 ?
|
||||||
qsTr("Remove %1 messages?").arg(eventIds.length) :
|
qsTr("Remove %1 messages?").arg(eventSenderAndIds.length) :
|
||||||
|
|
||||||
qsTr("Remove this message?")
|
qsTr("Remove this message?")
|
||||||
|
|
||||||
|
@ -23,17 +23,31 @@ BoxPopup {
|
||||||
okText: qsTr("Remove")
|
okText: qsTr("Remove")
|
||||||
box.focusButton: "ok"
|
box.focusButton: "ok"
|
||||||
|
|
||||||
onOk: py.callClientCoro(
|
onOk: {
|
||||||
userId,
|
const idsForSender = {} // {senderId: [eventId, ...]}
|
||||||
|
|
||||||
|
for (const [senderId, eventId] of eventSenderAndIds) {
|
||||||
|
if (! idsForSender[senderId])
|
||||||
|
idsForSender[senderId] = []
|
||||||
|
|
||||||
|
idsForSender[senderId].push(eventId)
|
||||||
|
}
|
||||||
|
|
||||||
|
print( JSON.stringify( idsForSender, null, 4))
|
||||||
|
|
||||||
|
for (const [senderId, eventIds] of Object.entries(idsForSender))
|
||||||
|
py.callClientCoro(
|
||||||
|
mainUI.accountIds.includes(senderId) ? senderId : preferUserId,
|
||||||
"room_mass_redact",
|
"room_mass_redact",
|
||||||
[roomId, reasonField.field.text, ...eventIds]
|
[roomId, reasonField.field.text, ...eventIds]
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
property string preferUserId: ""
|
||||||
property string roomId: ""
|
property string roomId: ""
|
||||||
property string userId: ""
|
|
||||||
|
|
||||||
property var eventIds: []
|
property var eventSenderAndIds: [] // [[senderId, eventId], ...]
|
||||||
property bool onlyOwnMessageWarning: false
|
property bool onlyOwnMessageWarning: false
|
||||||
property bool isLast: false
|
property bool isLast: false
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,16 @@ Item {
|
||||||
property bool accountsPresent:
|
property bool accountsPresent:
|
||||||
ModelStore.get("accounts").count > 0 || py.startupAnyAccountsSaved
|
ModelStore.get("accounts").count > 0 || py.startupAnyAccountsSaved
|
||||||
|
|
||||||
|
readonly property var accountIds: {
|
||||||
|
const ids = []
|
||||||
|
const model = ModelStore.get("accounts")
|
||||||
|
|
||||||
|
for (let i = 0; i < model.count; i++)
|
||||||
|
ids.push(model.get(i).id)
|
||||||
|
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
readonly property alias debugConsole: debugConsole
|
readonly property alias debugConsole: debugConsole
|
||||||
readonly property alias mainPane: mainPane
|
readonly property alias mainPane: mainPane
|
||||||
readonly property alias pageLoader: pageLoader
|
readonly property alias pageLoader: pageLoader
|
||||||
|
|
Loading…
Reference in New Issue
Block a user