Redaction local echo for our other accounts

This commit is contained in:
miruka 2020-04-03 06:50:24 -04:00
parent 5cb013838b
commit 0e04eafebd
5 changed files with 34 additions and 27 deletions

View File

@ -877,12 +877,19 @@ class MatrixClient(nio.AsyncClient):
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:
kind = m_type.split(".")[-1].replace("_", " ")
"""Get content to be displayed in place of a redacted event."""
if kind != "message":
kind = f"{kind} event"
kind = (
"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 \
f"%1's {kind} was removed by %2"
@ -894,29 +901,33 @@ class MatrixClient(nio.AsyncClient):
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]:
"""Redact events from a room in parallel."""
model = self.models[self.user_id, room_id, "events"]
tasks = []
for event in model._sorted_data:
m_type = event.source.source["type"]
for user_id in self.backend.clients:
for client_id in event_client_ids:
if event.event_id in event_ids:
event.is_local_echo = True
event = self.models[user_id, room_id, "events"].get(client_id)
event.content = await self.get_redacted_event_content(
m_type, self.user_id, event.sender_id, reason,
)
event.event_type = nio.RedactedEvent
if not event:
continue
if user_id == self.user_id:
tasks.append(
self.room_redact(room_id, event.event_id, reason),
)
event.is_local_echo = True
event.content = await self.get_redacted_event_content(
event.event_type, self.user_id, event.sender_id, reason,
)
event.event_type = nio.RedactedEvent
return await asyncio.gather(*tasks)

View File

@ -199,7 +199,7 @@ class NioCallbacks:
reason = ev.reason or "",
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 "",

View File

@ -229,9 +229,7 @@ HColumnLayout {
properties: ({
preferUserId: chat.userId,
roomId: chat.roomId,
eventSenderAndIds:
events.map(ev => [ev.sender_id, ev.event_id]),
eventSenderAndIds: events.map(ev => [ev.sender_id, ev.id]),
onlyOwnMessageWarning:
! chat.roomInfo.can_redact_all &&

View File

@ -61,7 +61,7 @@ Rectangle {
eventSenderAndIds:
(events || findLastRemovableDelegate()).map(
ev => [ev.sender_id, ev.event_id],
ev => [ev.sender_id, ev.id],
),
isLast: ! events,

View File

@ -24,22 +24,20 @@ BoxPopup {
box.focusButton: "ok"
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])
idsForSender[senderId] = []
idsForSender[senderId].push(eventId)
idsForSender[senderId].push(eventClientId)
}
print( JSON.stringify( idsForSender, null, 4))
for (const [senderId, eventIds] of Object.entries(idsForSender))
for (const [senderId, eventClientIds] of Object.entries(idsForSender))
py.callClientCoro(
mainUI.accountIds.includes(senderId) ? senderId : preferUserId,
"room_mass_redact",
[roomId, reasonField.field.text, ...eventIds]
[roomId, reasonField.field.text, ...eventClientIds]
)
}
@ -47,7 +45,7 @@ BoxPopup {
property string preferUserId: ""
property string roomId: ""
property var eventSenderAndIds: [] // [[senderId, eventId], ...]
property var eventSenderAndIds: [] // [[senderId, event.id], ...]
property bool onlyOwnMessageWarning: false
property bool isLast: false