Outgoing message redactions

This commit is contained in:
Andrew Ferrazzutti 2022-04-09 04:02:51 -04:00
parent 01a89508f6
commit 61d9a60704
3 changed files with 72 additions and 9 deletions

View File

@ -343,6 +343,17 @@ class Client:
is_secret=True is_secret=True
) )
async def delete_chat(
self,
channel_props: ChannelProps,
chat_id: Long,
) -> None:
return await self._api_user_request_void(
"delete_chat",
channel_props=channel_props.serialize(),
chat_id=chat_id.serialize(),
)
# TODO Combine these into one # TODO Combine these into one

View File

@ -879,24 +879,61 @@ class Portal(DBPortal, BasePortal):
self, sender: u.User, event_id: EventID, redaction_event_id: EventID self, sender: u.User, event_id: EventID, redaction_event_id: EventID
) -> None: ) -> None:
try: try:
await self._handle_matrix_redaction(sender, event_id, redaction_event_id) await self._handle_matrix_redaction(sender, event_id)
except Exception as e: except Exception as e:
self.log.exception(f"Failed to handle Matrix event {event_id}: {e}") self.log.error(
f"Failed to handle Matrix redaction {redaction_event_id}: {e}",
exc_info=not isinstance(e, NotImplementedError),
)
sender.send_remote_checkpoint( sender.send_remote_checkpoint(
self._status_from_exception(e), self._status_from_exception(e),
event_id, redaction_event_id,
self.mxid, self.mxid,
EventType.ROOM_REDACTION, EventType.ROOM_REDACTION,
error=e, error=e,
) )
await self._send_bridge_error(str(e)) if not isinstance(e, NotImplementedError):
await self._send_bridge_error(str(e), thing="redaction")
else: else:
await self._send_delivery_receipt(event_id) await self._send_delivery_receipt(redaction_event_id)
sender.send_remote_checkpoint(
MessageSendCheckpointStatus.SUCCESS,
redaction_event_id,
self.mxid,
EventType.ROOM_REDACTION,
)
async def _handle_matrix_redaction( async def _handle_matrix_redaction(self, sender: u.User, event_id: EventID) -> None:
self, sender: u.User, event_id: EventID, redaction_event_id: EventID sender, _ = await self.get_relay_sender(sender, f"redaction {event_id}")
) -> None: if not sender:
self.log.info("TODO: _handle_matrix_redaction") raise Exception("not logged in")
message = await DBMessage.get_by_mxid(event_id, self.mxid)
if message:
if not message.ktid:
raise NotImplementedError("Tried to redact message whose ktid is unknown")
try:
await message.delete()
await sender.client.delete_chat(self.channel_props, message.ktid)
except Exception as e:
self.log.exception(f"Unsend failed: {e}")
raise
return
raise NotImplementedError("Only message redactions are supported")
""" TODO
reaction = await DBReaction.get_by_mxid(event_id, self.mxid)
if reaction:
try:
await reaction.delete()
await sender.client.react(reaction.kt_msgid, None)
except Exception as e:
self.log.exception(f"Removing reaction failed: {e}")
raise
return
raise NotImplementedError("Only message and reaction redactions are supported")
"""
async def handle_matrix_reaction( async def handle_matrix_reaction(
self, sender: u.User, event_id: EventID, reacting_to: EventID, reaction: str self, sender: u.User, event_id: EventID, reacting_to: EventID, reaction: str

View File

@ -570,6 +570,20 @@ export default class PeerClient {
}) })
} }
/**
* @param {Object} req
* @param {string} req.mxid
* @param {ChannelProps} req.channel_props
* @param {Long} req.chat_id
*/
deleteChat = async (req) => {
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
return await talkChannel.deleteChat({
logId: req.chat_id,
})
}
#makeCommandResult(result) { #makeCommandResult(result) {
return { return {
success: true, success: true,
@ -653,6 +667,7 @@ export default class PeerClient {
get_memo_ids: this.getMemoIds, get_memo_ids: this.getMemoIds,
send_chat: this.sendChat, send_chat: this.sendChat,
send_media: this.sendMedia, send_media: this.sendMedia,
delete_chat: this.deleteChat,
}[req.command] || this.handleUnknownCommand }[req.command] || this.handleUnknownCommand
} }
const resp = { id: req.id } const resp = { id: req.id }