diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 99d0db7e..7679208d 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -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: + + 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.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 - tasks.append( - self.room_redact(room_id, event.event_id, reason), - ) - return await asyncio.gather(*tasks) diff --git a/src/backend/nio_callbacks.py b/src/backend/nio_callbacks.py index 9d08679d..70153f6a 100644 --- a/src/backend/nio_callbacks.py +++ b/src/backend/nio_callbacks.py @@ -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 "", diff --git a/src/gui/Pages/Chat/Timeline/EventDelegate.qml b/src/gui/Pages/Chat/Timeline/EventDelegate.qml index 7528c220..e406e379 100644 --- a/src/gui/Pages/Chat/Timeline/EventDelegate.qml +++ b/src/gui/Pages/Chat/Timeline/EventDelegate.qml @@ -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 && diff --git a/src/gui/Pages/Chat/Timeline/EventList.qml b/src/gui/Pages/Chat/Timeline/EventList.qml index fb782c7c..270b86b5 100644 --- a/src/gui/Pages/Chat/Timeline/EventList.qml +++ b/src/gui/Pages/Chat/Timeline/EventList.qml @@ -61,7 +61,7 @@ Rectangle { eventSenderAndIds: (events || findLastRemovableDelegate()).map( - ev => [ev.sender_id, ev.event_id], + ev => [ev.sender_id, ev.id], ), isLast: ! events, diff --git a/src/gui/Popups/RedactPopup.qml b/src/gui/Popups/RedactPopup.qml index 657582bb..c7af4268 100644 --- a/src/gui/Popups/RedactPopup.qml +++ b/src/gui/Popups/RedactPopup.qml @@ -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