From d452735691006acc0ba093757e9d434ad3e56203 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Wed, 6 Apr 2022 14:57:06 -0400 Subject: [PATCH] Set body of media replies to what official client sets them to --- .../formatter/from_matrix.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/matrix_appservice_kakaotalk/formatter/from_matrix.py b/matrix_appservice_kakaotalk/formatter/from_matrix.py index a49aa7a..db87083 100644 --- a/matrix_appservice_kakaotalk/formatter/from_matrix.py +++ b/matrix_appservice_kakaotalk/formatter/from_matrix.py @@ -101,8 +101,13 @@ async def matrix_to_kakaotalk( src_converted = await matrix_to_kakaotalk(src_event.content, room_id, log, intent, skip_reply=True) if src_event.content.relates_to.rel_type == RelationType.REPLY: src_type = KnownChatType.REPLY + src_message = src_converted.text else: src_type = TO_MSGTYPE_MAP[src_event.content.msgtype] + if src_type == KnownChatType.FILE: + src_message = _media_type_reply_body_map[KnownChatType.FILE] + src_converted.text + else: + src_message = _media_type_reply_body_map.get(src_type, src_converted.text) reply_to = ReplyAttachment( # NOTE mentions will be merged into this later # TODO Set this for emoticon reply, but must first support them @@ -114,13 +119,13 @@ async def matrix_to_kakaotalk( attach_type=0, src_logId=message.ktid, src_mentions=src_converted.mentions or [], - src_message=src_converted.text, + src_message=src_message, src_type=src_type, src_userId=src_kt_sender, ) else: reply_to = None - if content.get("format", None) == Format.HTML and content["formatted_body"]: + if content.get("format", None) == Format.HTML and content["formatted_body"] and content.msgtype.is_text: parsed = await ToKakaoTalkParser().parse(content["formatted_body"]) text = parsed.text mentions_by_user: dict[Long, MentionStruct] = {} @@ -149,3 +154,11 @@ async def matrix_to_kakaotalk( text = content.body mentions = None return SendParams(text=text, mentions=mentions, reply_to=reply_to) + + +_media_type_reply_body_map: dict[KnownChatType, str] = { + KnownChatType.PHOTO: "Photo", + KnownChatType.VIDEO: "Video", + KnownChatType.AUDIO: "Voice Note", + KnownChatType.FILE: "File: ", +}