Prepend relayed media messages with a new message of who sent it
And keep its body text unchanged from its original
This commit is contained in:
parent
587ec98f3e
commit
aa5c066552
@ -246,10 +246,10 @@ bridge:
|
|||||||
m.text: '<b>$sender_displayname</b>: $message'
|
m.text: '<b>$sender_displayname</b>: $message'
|
||||||
m.notice: '<b>$sender_displayname<b>: $message'
|
m.notice: '<b>$sender_displayname<b>: $message'
|
||||||
m.emote: '* <b>$sender_displayname<b> $message'
|
m.emote: '* <b>$sender_displayname<b> $message'
|
||||||
m.file: '<b>$sender_displayname</b> sent a file'
|
m.file: 'File from <b>$sender_displayname</b>: $message'
|
||||||
m.image: '<b>$sender_displayname</b> sent an image'
|
m.image: 'Image from <b>$sender_displayname</b>: $message'
|
||||||
m.audio: '<b>$sender_displayname</b> sent an audio file'
|
m.audio: 'Audio from <b>$sender_displayname</b>: $message'
|
||||||
m.video: '<b>$sender_displayname</b> sent a video'
|
m.video: 'Video from <b>$sender_displayname</b>: $message'
|
||||||
m.location: '<b>$sender_displayname</b> sent a location'
|
m.location: '<b>$sender_displayname</b> sent a location'
|
||||||
|
|
||||||
rpc:
|
rpc:
|
||||||
|
@ -791,7 +791,12 @@ class Portal(DBPortal, BasePortal):
|
|||||||
elif not sender.is_connected:
|
elif not sender.is_connected:
|
||||||
raise Exception("not connected to KakaoTalk chats")
|
raise Exception("not connected to KakaoTalk chats")
|
||||||
elif is_relay:
|
elif is_relay:
|
||||||
await self.apply_relay_message_format(orig_sender, message)
|
if not message.msgtype.is_text:
|
||||||
|
intro_message = TextMessageEventContent(msgtype=MessageType.TEXT, body=message.body)
|
||||||
|
await self.apply_relay_message_format(orig_sender, intro_message)
|
||||||
|
await self._send_chat(sender, intro_message)
|
||||||
|
else:
|
||||||
|
await self.apply_relay_message_format(orig_sender, message)
|
||||||
if message.msgtype == MessageType.TEXT or message.msgtype == MessageType.NOTICE:
|
if message.msgtype == MessageType.TEXT or message.msgtype == MessageType.NOTICE:
|
||||||
await self._handle_matrix_text(event_id, sender, message)
|
await self._handle_matrix_text(event_id, sender, message)
|
||||||
elif message.msgtype.is_media:
|
elif message.msgtype.is_media:
|
||||||
@ -801,6 +806,21 @@ class Portal(DBPortal, BasePortal):
|
|||||||
else:
|
else:
|
||||||
raise NotImplementedError(f"Unsupported message type {message.msgtype}")
|
raise NotImplementedError(f"Unsupported message type {message.msgtype}")
|
||||||
|
|
||||||
|
async def _send_chat(
|
||||||
|
self, sender: u.User, message: TextMessageEventContent, event_id: EventID | None = None
|
||||||
|
) -> Chatlog:
|
||||||
|
converted = await matrix_to_kakaotalk(message, self.mxid, self.log, self.main_intent)
|
||||||
|
try:
|
||||||
|
return await sender.client.send_chat(
|
||||||
|
self.channel_props,
|
||||||
|
text=converted.text,
|
||||||
|
reply_to=converted.reply_to,
|
||||||
|
mentions=converted.mentions,
|
||||||
|
)
|
||||||
|
except CommandException as e:
|
||||||
|
self.log.debug(f"Error handling Matrix message {event_id if event_id else '<extra>'}: {e!s}")
|
||||||
|
raise
|
||||||
|
|
||||||
async def _make_dbm(self, event_id: EventID, ktid: Long | None = None) -> DBMessage:
|
async def _make_dbm(self, event_id: EventID, ktid: Long | None = None) -> DBMessage:
|
||||||
dbm = DBMessage(
|
dbm = DBMessage(
|
||||||
mxid=event_id,
|
mxid=event_id,
|
||||||
@ -817,17 +837,7 @@ class Portal(DBPortal, BasePortal):
|
|||||||
async def _handle_matrix_text(
|
async def _handle_matrix_text(
|
||||||
self, event_id: EventID, sender: u.User, message: TextMessageEventContent
|
self, event_id: EventID, sender: u.User, message: TextMessageEventContent
|
||||||
) -> None:
|
) -> None:
|
||||||
converted = await matrix_to_kakaotalk(message, self.mxid, self.log, self.main_intent)
|
chatlog = await self._send_chat(sender, message, event_id)
|
||||||
try:
|
|
||||||
chatlog = await sender.client.send_chat(
|
|
||||||
self.channel_props,
|
|
||||||
text=converted.text,
|
|
||||||
reply_to=converted.reply_to,
|
|
||||||
mentions=converted.mentions,
|
|
||||||
)
|
|
||||||
except CommandException as e:
|
|
||||||
self.log.debug(f"Error handling Matrix message {event_id}: {e!s}")
|
|
||||||
raise
|
|
||||||
await self._make_dbm(event_id, chatlog.logId)
|
await self._make_dbm(event_id, chatlog.logId)
|
||||||
self.log.debug(f"Handled Matrix message {event_id} -> {chatlog.logId}")
|
self.log.debug(f"Handled Matrix message {event_id} -> {chatlog.logId}")
|
||||||
sender.send_remote_checkpoint(
|
sender.send_remote_checkpoint(
|
||||||
|
Loading…
Reference in New Issue
Block a user