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)
|
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(
|
async def room_mass_redact(
|
||||||
self, room_id: str, reason: str, *event_ids: str,
|
self, room_id: str, reason: str, *event_ids: str,
|
||||||
) -> List[nio.responses.RoomRedactResponse]:
|
) -> List[nio.RoomRedactResponse]:
|
||||||
"""Redact events from a room in parallel.
|
"""Redact events from a room in parallel."""
|
||||||
|
|
||||||
Returns a list of sucessful redacts.
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = self.models[self.user_id, room_id, "events"]
|
model = self.models[self.user_id, room_id, "events"]
|
||||||
gather_list = []
|
tasks = []
|
||||||
|
|
||||||
for event in model._sorted_data:
|
for event in model._sorted_data:
|
||||||
|
m_type = event.source.source["type"]
|
||||||
|
|
||||||
if event.event_id in event_ids:
|
if event.event_id in event_ids:
|
||||||
event.is_local_echo = True
|
event.is_local_echo = True
|
||||||
event.content = "Removing..."
|
|
||||||
event.event_type = nio.RedactedEvent
|
event.content = await self.get_redacted_event_content(
|
||||||
gather_list.append(
|
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),
|
self.room_redact(room_id, event.event_id, reason),
|
||||||
)
|
)
|
||||||
|
|
||||||
return await asyncio.gather(*gather_list)
|
return await asyncio.gather(*tasks)
|
||||||
|
|
||||||
|
|
||||||
async def generate_thumbnail(
|
async def generate_thumbnail(
|
||||||
|
|
|
@ -192,23 +192,16 @@ class NioCallbacks:
|
||||||
|
|
||||||
|
|
||||||
async def onRedactedEvent(self, room, ev, event_id: str = "") -> None:
|
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(
|
await self.client.register_nio_event(
|
||||||
room,
|
room,
|
||||||
ev,
|
ev,
|
||||||
event_id = event_id,
|
event_id = event_id,
|
||||||
reason = ev.reason or "",
|
reason = ev.reason or "",
|
||||||
content = co,
|
|
||||||
|
content = await self.client.get_redacted_event_content(
|
||||||
|
ev.source["type"], ev.redacter, ev.sender, ev.reason,
|
||||||
|
),
|
||||||
|
|
||||||
redacter_id = ev.redacter or "",
|
redacter_id = ev.redacter or "",
|
||||||
redacter_name =
|
redacter_name =
|
||||||
(await self.client.get_member_name_avatar(
|
(await self.client.get_member_name_avatar(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user