Outgoing message redactions
This commit is contained in:
parent
01a89508f6
commit
61d9a60704
@ -343,6 +343,17 @@ class Client:
|
||||
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
|
||||
|
||||
|
@ -879,24 +879,61 @@ class Portal(DBPortal, BasePortal):
|
||||
self, sender: u.User, event_id: EventID, redaction_event_id: EventID
|
||||
) -> None:
|
||||
try:
|
||||
await self._handle_matrix_redaction(sender, event_id, redaction_event_id)
|
||||
await self._handle_matrix_redaction(sender, event_id)
|
||||
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(
|
||||
self._status_from_exception(e),
|
||||
event_id,
|
||||
redaction_event_id,
|
||||
self.mxid,
|
||||
EventType.ROOM_REDACTION,
|
||||
error=e,
|
||||
)
|
||||
await self._send_bridge_error(str(e))
|
||||
if not isinstance(e, NotImplementedError):
|
||||
await self._send_bridge_error(str(e), thing="redaction")
|
||||
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(
|
||||
self, sender: u.User, event_id: EventID, redaction_event_id: EventID
|
||||
) -> None:
|
||||
self.log.info("TODO: _handle_matrix_redaction")
|
||||
async def _handle_matrix_redaction(self, sender: u.User, event_id: EventID) -> None:
|
||||
sender, _ = await self.get_relay_sender(sender, f"redaction {event_id}")
|
||||
if not sender:
|
||||
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(
|
||||
self, sender: u.User, event_id: EventID, reacting_to: EventID, reaction: str
|
||||
|
@ -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) {
|
||||
return {
|
||||
success: true,
|
||||
@ -653,6 +667,7 @@ export default class PeerClient {
|
||||
get_memo_ids: this.getMemoIds,
|
||||
send_chat: this.sendChat,
|
||||
send_media: this.sendMedia,
|
||||
delete_chat: this.deleteChat,
|
||||
}[req.command] || this.handleUnknownCommand
|
||||
}
|
||||
const resp = { id: req.id }
|
||||
|
Loading…
Reference in New Issue
Block a user