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