Redaction local echo for our other accounts
This commit is contained in:
parent
5cb013838b
commit
0e04eafebd
|
@ -877,12 +877,19 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
|
|
||||||
async def get_redacted_event_content(
|
async def get_redacted_event_content(
|
||||||
self, m_type: str, redacter: str, sender: str, reason: str = "",
|
self,
|
||||||
|
nio_type: Type[nio.Event],
|
||||||
|
redacter: str,
|
||||||
|
sender: str,
|
||||||
|
reason: str = "",
|
||||||
) -> str:
|
) -> str:
|
||||||
kind = m_type.split(".")[-1].replace("_", " ")
|
"""Get content to be displayed in place of a redacted event."""
|
||||||
|
|
||||||
if kind != "message":
|
kind = (
|
||||||
kind = f"{kind} event"
|
"message" if issubclass(nio_type, nio.RoomMessage) else
|
||||||
|
"media" if issubclass(nio_type, nio.RoomMessageMedia) else
|
||||||
|
"event"
|
||||||
|
)
|
||||||
|
|
||||||
content = f"%1 removed this {kind}" if redacter == sender else \
|
content = f"%1 removed this {kind}" if redacter == sender else \
|
||||||
f"%1's {kind} was removed by %2"
|
f"%1's {kind} was removed by %2"
|
||||||
|
@ -894,29 +901,33 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
|
|
||||||
async def room_mass_redact(
|
async def room_mass_redact(
|
||||||
self, room_id: str, reason: str, *event_ids: str,
|
self, room_id: str, reason: str, *event_client_ids: str,
|
||||||
) -> List[nio.RoomRedactResponse]:
|
) -> List[nio.RoomRedactResponse]:
|
||||||
"""Redact events from a room in parallel."""
|
"""Redact events from a room in parallel."""
|
||||||
|
|
||||||
model = self.models[self.user_id, room_id, "events"]
|
|
||||||
tasks = []
|
tasks = []
|
||||||
|
|
||||||
for event in model._sorted_data:
|
for user_id in self.backend.clients:
|
||||||
m_type = event.source.source["type"]
|
for client_id in event_client_ids:
|
||||||
|
|
||||||
|
event = self.models[user_id, room_id, "events"].get(client_id)
|
||||||
|
|
||||||
|
if not event:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if user_id == self.user_id:
|
||||||
|
tasks.append(
|
||||||
|
self.room_redact(room_id, event.event_id, reason),
|
||||||
|
)
|
||||||
|
|
||||||
if event.event_id in event_ids:
|
|
||||||
event.is_local_echo = True
|
event.is_local_echo = True
|
||||||
|
|
||||||
event.content = await self.get_redacted_event_content(
|
event.content = await self.get_redacted_event_content(
|
||||||
m_type, self.user_id, event.sender_id, reason,
|
event.event_type, self.user_id, event.sender_id, reason,
|
||||||
)
|
)
|
||||||
|
|
||||||
event.event_type = nio.RedactedEvent
|
event.event_type = nio.RedactedEvent
|
||||||
|
|
||||||
tasks.append(
|
|
||||||
self.room_redact(room_id, event.event_id, reason),
|
|
||||||
)
|
|
||||||
|
|
||||||
return await asyncio.gather(*tasks)
|
return await asyncio.gather(*tasks)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,7 @@ class NioCallbacks:
|
||||||
reason = ev.reason or "",
|
reason = ev.reason or "",
|
||||||
|
|
||||||
content = await self.client.get_redacted_event_content(
|
content = await self.client.get_redacted_event_content(
|
||||||
ev.source["type"], ev.redacter, ev.sender, ev.reason,
|
type(ev), ev.redacter, ev.sender, ev.reason,
|
||||||
),
|
),
|
||||||
|
|
||||||
redacter_id = ev.redacter or "",
|
redacter_id = ev.redacter or "",
|
||||||
|
|
|
@ -229,9 +229,7 @@ HColumnLayout {
|
||||||
properties: ({
|
properties: ({
|
||||||
preferUserId: chat.userId,
|
preferUserId: chat.userId,
|
||||||
roomId: chat.roomId,
|
roomId: chat.roomId,
|
||||||
|
eventSenderAndIds: events.map(ev => [ev.sender_id, ev.id]),
|
||||||
eventSenderAndIds:
|
|
||||||
events.map(ev => [ev.sender_id, ev.event_id]),
|
|
||||||
|
|
||||||
onlyOwnMessageWarning:
|
onlyOwnMessageWarning:
|
||||||
! chat.roomInfo.can_redact_all &&
|
! chat.roomInfo.can_redact_all &&
|
||||||
|
|
|
@ -61,7 +61,7 @@ Rectangle {
|
||||||
|
|
||||||
eventSenderAndIds:
|
eventSenderAndIds:
|
||||||
(events || findLastRemovableDelegate()).map(
|
(events || findLastRemovableDelegate()).map(
|
||||||
ev => [ev.sender_id, ev.event_id],
|
ev => [ev.sender_id, ev.id],
|
||||||
),
|
),
|
||||||
|
|
||||||
isLast: ! events,
|
isLast: ! events,
|
||||||
|
|
|
@ -24,22 +24,20 @@ BoxPopup {
|
||||||
box.focusButton: "ok"
|
box.focusButton: "ok"
|
||||||
|
|
||||||
onOk: {
|
onOk: {
|
||||||
const idsForSender = {} // {senderId: [eventId, ...]}
|
const idsForSender = {} // {senderId: [event.id, ...]}
|
||||||
|
|
||||||
for (const [senderId, eventId] of eventSenderAndIds) {
|
for (const [senderId, eventClientId] of eventSenderAndIds) {
|
||||||
if (! idsForSender[senderId])
|
if (! idsForSender[senderId])
|
||||||
idsForSender[senderId] = []
|
idsForSender[senderId] = []
|
||||||
|
|
||||||
idsForSender[senderId].push(eventId)
|
idsForSender[senderId].push(eventClientId)
|
||||||
}
|
}
|
||||||
|
|
||||||
print( JSON.stringify( idsForSender, null, 4))
|
for (const [senderId, eventClientIds] of Object.entries(idsForSender))
|
||||||
|
|
||||||
for (const [senderId, eventIds] of Object.entries(idsForSender))
|
|
||||||
py.callClientCoro(
|
py.callClientCoro(
|
||||||
mainUI.accountIds.includes(senderId) ? senderId : preferUserId,
|
mainUI.accountIds.includes(senderId) ? senderId : preferUserId,
|
||||||
"room_mass_redact",
|
"room_mass_redact",
|
||||||
[roomId, reasonField.field.text, ...eventIds]
|
[roomId, reasonField.field.text, ...eventClientIds]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +45,7 @@ BoxPopup {
|
||||||
property string preferUserId: ""
|
property string preferUserId: ""
|
||||||
property string roomId: ""
|
property string roomId: ""
|
||||||
|
|
||||||
property var eventSenderAndIds: [] // [[senderId, eventId], ...]
|
property var eventSenderAndIds: [] // [[senderId, event.id], ...]
|
||||||
property bool onlyOwnMessageWarning: false
|
property bool onlyOwnMessageWarning: false
|
||||||
property bool isLast: false
|
property bool isLast: false
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user