Format & put mentions in reply targets

This commit is contained in:
Andrew Ferrazzutti 2022-04-06 14:11:15 -04:00
parent 84e6a5829d
commit 26d212fd45

View File

@ -72,10 +72,14 @@ async def _get_id_from_mxid(mxid: UserID) -> Long | None:
async def matrix_to_kakaotalk(
content: MessageEventContent, room_id: RoomID, log: TraceLogger, intent: IntentAPI
content: MessageEventContent,
room_id: RoomID,
log: TraceLogger,
intent: IntentAPI,
skip_reply: bool = False
) -> SendParams:
# NOTE By design, this *throws* if user intent can't be matched (i.e. if a reply can't be created)
if content.relates_to.rel_type == RelationType.REPLY:
if content.relates_to.rel_type == RelationType.REPLY and not skip_reply:
message = await DBMessage.get_by_mxid(content.relates_to.event_id, room_id)
if not message:
raise ValueError(
@ -83,33 +87,29 @@ async def matrix_to_kakaotalk(
" to bridge text message reply metadata to KakaoTalk"
)
try:
mx_event = await intent.get_event(room_id, message.mxid)
src_event = await intent.get_event(room_id, message.mxid)
except:
log.exception(f"Failed to find Matrix event for reply target {message.mxid}")
raise
kt_sender = await _get_id_from_mxid(mx_event.sender)
if kt_sender is None:
src_kt_sender = await _get_id_from_mxid(src_event.sender)
if src_kt_sender is None:
raise ValueError(
f"Found no KakaoTalk user ID for reply target sender {mx_event.sender}"
f"Found no KakaoTalk user ID for reply target sender {src_event.sender}"
)
content.trim_reply_fallback()
src_converted = await matrix_to_kakaotalk(src_event.content, room_id, log, intent, skip_reply=True)
reply_to = ReplyAttachment(
# TODO
#mentions=[],
# TODO What are reply URLs for?
#urls=[],
# TODO Set this for emoticon reply, but must first support those
# NOTE mentions will be merged into this later
# TODO Set this for emoticon reply, but must first support them
attach_only=False,
# TODO If replying with media works, must set type AND all attachment properties
# But then, the reply object must be an intersection of a ReplyAttachment and something else
#attach_type=TO_MSGTYPE_MAP.get(content.msgtype),
src_logId=message.ktid,
# TODO
src_mentions=[],
# TODO Check if source message needs to be formatted
src_message=mx_event.content.body,
src_type=TO_MSGTYPE_MAP[mx_event.content.msgtype],
src_userId=kt_sender,
src_mentions=src_converted.mentions or [],
src_message=src_converted.text,
src_type=TO_MSGTYPE_MAP[src_event.content.msgtype],
src_userId=src_kt_sender,
)
else:
reply_to = None