Redact local echo: same text as redaction event
This commit is contained in:
parent
d991d04a8c
commit
8af63a304f
|
@ -876,27 +876,48 @@ class MatrixClient(nio.AsyncClient):
|
|||
return (successes, errors)
|
||||
|
||||
|
||||
async def get_redacted_event_content(
|
||||
self, m_type: str, redacter: str, sender: str, reason: str = "",
|
||||
) -> str:
|
||||
kind = m_type.split(".")[-1].replace("_", " ")
|
||||
|
||||
if kind != "message":
|
||||
kind = f"{kind} event"
|
||||
|
||||
content = f"%1 removed this {kind}" if redacter == sender else \
|
||||
f"%1's {kind} was removed by %2"
|
||||
|
||||
if reason:
|
||||
content = f"{content}, reason: {reason}"
|
||||
|
||||
return content
|
||||
|
||||
|
||||
async def room_mass_redact(
|
||||
self, room_id: str, reason: str, *event_ids: str,
|
||||
) -> List[nio.responses.RoomRedactResponse]:
|
||||
"""Redact events from a room in parallel.
|
||||
|
||||
Returns a list of sucessful redacts.
|
||||
"""
|
||||
) -> List[nio.RoomRedactResponse]:
|
||||
"""Redact events from a room in parallel."""
|
||||
|
||||
model = self.models[self.user_id, room_id, "events"]
|
||||
gather_list = []
|
||||
tasks = []
|
||||
|
||||
for event in model._sorted_data:
|
||||
m_type = event.source.source["type"]
|
||||
|
||||
if event.event_id in event_ids:
|
||||
event.is_local_echo = True
|
||||
event.content = "Removing..."
|
||||
event.event_type = nio.RedactedEvent
|
||||
gather_list.append(
|
||||
|
||||
event.content = await self.get_redacted_event_content(
|
||||
m_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(*gather_list)
|
||||
return await asyncio.gather(*tasks)
|
||||
|
||||
|
||||
async def generate_thumbnail(
|
||||
|
|
|
@ -192,23 +192,16 @@ class NioCallbacks:
|
|||
|
||||
|
||||
async def onRedactedEvent(self, room, ev, event_id: str = "") -> None:
|
||||
kind = ev.source["type"].split(".")[-1].replace("_", " ")
|
||||
|
||||
if kind != "message":
|
||||
kind = f"{kind} event"
|
||||
|
||||
co = f"%1 removed this {kind}" if ev.redacter == ev.sender else \
|
||||
f"%1's {kind} was removed by %2"
|
||||
|
||||
if ev.reason:
|
||||
co = f"{co}, reason: {ev.reason}"
|
||||
|
||||
await self.client.register_nio_event(
|
||||
room,
|
||||
ev,
|
||||
event_id = event_id,
|
||||
reason = ev.reason or "",
|
||||
content = co,
|
||||
event_id = event_id,
|
||||
reason = ev.reason or "",
|
||||
|
||||
content = await self.client.get_redacted_event_content(
|
||||
ev.source["type"], ev.redacter, ev.sender, ev.reason,
|
||||
),
|
||||
|
||||
redacter_id = ev.redacter or "",
|
||||
redacter_name =
|
||||
(await self.client.get_member_name_avatar(
|
||||
|
|
Loading…
Reference in New Issue
Block a user