Set body of media replies to what official client sets them to

This commit is contained in:
Andrew Ferrazzutti 2022-04-06 14:57:06 -04:00
parent ae9fd46bc8
commit d452735691
1 changed files with 15 additions and 2 deletions

View File

@ -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) 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: if src_event.content.relates_to.rel_type == RelationType.REPLY:
src_type = KnownChatType.REPLY src_type = KnownChatType.REPLY
src_message = src_converted.text
else: else:
src_type = TO_MSGTYPE_MAP[src_event.content.msgtype] 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( reply_to = ReplyAttachment(
# NOTE mentions will be merged into this later # NOTE mentions will be merged into this later
# TODO Set this for emoticon reply, but must first support them # TODO Set this for emoticon reply, but must first support them
@ -114,13 +119,13 @@ async def matrix_to_kakaotalk(
attach_type=0, attach_type=0,
src_logId=message.ktid, src_logId=message.ktid,
src_mentions=src_converted.mentions or [], src_mentions=src_converted.mentions or [],
src_message=src_converted.text, src_message=src_message,
src_type=src_type, src_type=src_type,
src_userId=src_kt_sender, src_userId=src_kt_sender,
) )
else: else:
reply_to = None 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"]) parsed = await ToKakaoTalkParser().parse(content["formatted_body"])
text = parsed.text text = parsed.text
mentions_by_user: dict[Long, MentionStruct] = {} mentions_by_user: dict[Long, MentionStruct] = {}
@ -149,3 +154,11 @@ async def matrix_to_kakaotalk(
text = content.body text = content.body
mentions = None mentions = None
return SendParams(text=text, mentions=mentions, reply_to=reply_to) 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: ",
}