Return IDs of bridged outgoing messages instead of the chats themselves
And set an optional property in AudioAttachment to be safe
This commit is contained in:
parent
aa5c066552
commit
fe6df88a4b
|
@ -326,9 +326,9 @@ class Client:
|
||||||
text: str,
|
text: str,
|
||||||
reply_to: ReplyAttachment | None,
|
reply_to: ReplyAttachment | None,
|
||||||
mentions: list[MentionStruct] | None,
|
mentions: list[MentionStruct] | None,
|
||||||
) -> Chatlog:
|
) -> Long:
|
||||||
return await self._api_user_request_result(
|
return await self._api_user_request_result(
|
||||||
Chatlog,
|
Long,
|
||||||
"send_chat",
|
"send_chat",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
text=text,
|
text=text,
|
||||||
|
@ -346,9 +346,9 @@ class Client:
|
||||||
width: int | None = None,
|
width: int | None = None,
|
||||||
height: int | None = None,
|
height: int | None = None,
|
||||||
ext: str | None = None,
|
ext: str | None = None,
|
||||||
) -> Chatlog:
|
) -> Long:
|
||||||
return await self._api_user_request_result(
|
return await self._api_user_request_result(
|
||||||
Chatlog,
|
Long,
|
||||||
"send_media",
|
"send_media",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
type=media_type,
|
type=media_type,
|
||||||
|
|
|
@ -78,10 +78,11 @@ class FileAttachment(MediaKeyAttachment):
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AudioAttachment(MediaKeyAttachment):
|
class AudioAttachment(Attachment):
|
||||||
# NOTE Changed superclass from Attachment
|
url: str
|
||||||
d: int
|
d: int
|
||||||
expire: Optional[int] = None
|
expire: Optional[int] = None
|
||||||
|
s: Optional[int] = None # NOTE Optional for inbound
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
|
@ -808,7 +808,7 @@ class Portal(DBPortal, BasePortal):
|
||||||
|
|
||||||
async def _send_chat(
|
async def _send_chat(
|
||||||
self, sender: u.User, message: TextMessageEventContent, event_id: EventID | None = None
|
self, sender: u.User, message: TextMessageEventContent, event_id: EventID | None = None
|
||||||
) -> Chatlog:
|
) -> Long:
|
||||||
converted = await matrix_to_kakaotalk(message, self.mxid, self.log, self.main_intent)
|
converted = await matrix_to_kakaotalk(message, self.mxid, self.log, self.main_intent)
|
||||||
try:
|
try:
|
||||||
return await sender.client.send_chat(
|
return await sender.client.send_chat(
|
||||||
|
@ -837,9 +837,9 @@ 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:
|
||||||
chatlog = await self._send_chat(sender, message, event_id)
|
log_id = await self._send_chat(sender, message, event_id)
|
||||||
await self._make_dbm(event_id, chatlog.logId)
|
await self._make_dbm(event_id, log_id)
|
||||||
self.log.debug(f"Handled Matrix message {event_id} -> {chatlog.logId}")
|
self.log.debug(f"Handled Matrix message {event_id} -> {log_id}")
|
||||||
sender.send_remote_checkpoint(
|
sender.send_remote_checkpoint(
|
||||||
MessageSendCheckpointStatus.SUCCESS,
|
MessageSendCheckpointStatus.SUCCESS,
|
||||||
event_id,
|
event_id,
|
||||||
|
@ -867,7 +867,7 @@ class Portal(DBPortal, BasePortal):
|
||||||
width = message.info.width
|
width = message.info.width
|
||||||
height = message.info.height
|
height = message.info.height
|
||||||
try:
|
try:
|
||||||
chatlog = await sender.client.send_media(
|
log_id = await sender.client.send_media(
|
||||||
self.channel_props,
|
self.channel_props,
|
||||||
TO_MSGTYPE_MAP[message.msgtype],
|
TO_MSGTYPE_MAP[message.msgtype],
|
||||||
data,
|
data,
|
||||||
|
@ -879,8 +879,8 @@ class Portal(DBPortal, BasePortal):
|
||||||
except CommandException as e:
|
except CommandException as e:
|
||||||
self.log.debug(f"Error uploading media for Matrix message {event_id}: {e!s}")
|
self.log.debug(f"Error uploading media for Matrix message {event_id}: {e!s}")
|
||||||
raise
|
raise
|
||||||
await self._make_dbm(event_id, chatlog.logId)
|
await self._make_dbm(event_id, log_id)
|
||||||
self.log.debug(f"Handled Matrix message {event_id} -> {chatlog.logId}")
|
self.log.debug(f"Handled Matrix message {event_id} -> {log_id}")
|
||||||
sender.send_remote_checkpoint(
|
sender.send_remote_checkpoint(
|
||||||
MessageSendCheckpointStatus.SUCCESS,
|
MessageSendCheckpointStatus.SUCCESS,
|
||||||
event_id,
|
event_id,
|
||||||
|
|
|
@ -634,12 +634,13 @@ export default class PeerClient {
|
||||||
*/
|
*/
|
||||||
sendChat = async (req) => {
|
sendChat = async (req) => {
|
||||||
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
|
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
|
||||||
|
const res = await talkChannel.sendChat({
|
||||||
return await talkChannel.sendChat({
|
|
||||||
text: req.text,
|
text: req.text,
|
||||||
type: !!req.reply_to ? KnownChatType.REPLY : KnownChatType.TEXT,
|
type: !!req.reply_to ? KnownChatType.REPLY : KnownChatType.TEXT,
|
||||||
attachment: !req.mentions ? req.reply_to : {...req.reply_to, mentions: req.mentions},
|
attachment: !req.mentions ? req.reply_to : {...req.reply_to, mentions: req.mentions},
|
||||||
})
|
})
|
||||||
|
if (res.success) res.result = res.result.logId
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -655,14 +656,15 @@ export default class PeerClient {
|
||||||
*/
|
*/
|
||||||
sendMedia = async (req) => {
|
sendMedia = async (req) => {
|
||||||
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
|
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
|
||||||
|
const res = await talkChannel.sendMedia(req.type, {
|
||||||
return await talkChannel.sendMedia(req.type, {
|
|
||||||
data: Uint8Array.from(req.data),
|
data: Uint8Array.from(req.data),
|
||||||
name: req.name,
|
name: req.name,
|
||||||
width: req.width,
|
width: req.width,
|
||||||
height: req.height,
|
height: req.height,
|
||||||
ext: req.ext,
|
ext: req.ext,
|
||||||
})
|
})
|
||||||
|
if (res.success) res.result = res.result.logId
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue