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:
Andrew Ferrazzutti 2022-04-12 04:34:16 -04:00
parent aa5c066552
commit fe6df88a4b
4 changed files with 20 additions and 17 deletions

View File

@ -326,9 +326,9 @@ class Client:
text: str,
reply_to: ReplyAttachment | None,
mentions: list[MentionStruct] | None,
) -> Chatlog:
) -> Long:
return await self._api_user_request_result(
Chatlog,
Long,
"send_chat",
channel_props=channel_props.serialize(),
text=text,
@ -346,9 +346,9 @@ class Client:
width: int | None = None,
height: int | None = None,
ext: str | None = None,
) -> Chatlog:
) -> Long:
return await self._api_user_request_result(
Chatlog,
Long,
"send_media",
channel_props=channel_props.serialize(),
type=media_type,

View File

@ -78,10 +78,11 @@ class FileAttachment(MediaKeyAttachment):
@dataclass
class AudioAttachment(MediaKeyAttachment):
# NOTE Changed superclass from Attachment
class AudioAttachment(Attachment):
url: str
d: int
expire: Optional[int] = None
s: Optional[int] = None # NOTE Optional for inbound
@dataclass

View File

@ -808,7 +808,7 @@ class Portal(DBPortal, BasePortal):
async def _send_chat(
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)
try:
return await sender.client.send_chat(
@ -837,9 +837,9 @@ class Portal(DBPortal, BasePortal):
async def _handle_matrix_text(
self, event_id: EventID, sender: u.User, message: TextMessageEventContent
) -> None:
chatlog = await self._send_chat(sender, message, event_id)
await self._make_dbm(event_id, chatlog.logId)
self.log.debug(f"Handled Matrix message {event_id} -> {chatlog.logId}")
log_id = await self._send_chat(sender, message, event_id)
await self._make_dbm(event_id, log_id)
self.log.debug(f"Handled Matrix message {event_id} -> {log_id}")
sender.send_remote_checkpoint(
MessageSendCheckpointStatus.SUCCESS,
event_id,
@ -867,7 +867,7 @@ class Portal(DBPortal, BasePortal):
width = message.info.width
height = message.info.height
try:
chatlog = await sender.client.send_media(
log_id = await sender.client.send_media(
self.channel_props,
TO_MSGTYPE_MAP[message.msgtype],
data,
@ -879,8 +879,8 @@ class Portal(DBPortal, BasePortal):
except CommandException as e:
self.log.debug(f"Error uploading media for Matrix message {event_id}: {e!s}")
raise
await self._make_dbm(event_id, chatlog.logId)
self.log.debug(f"Handled Matrix message {event_id} -> {chatlog.logId}")
await self._make_dbm(event_id, log_id)
self.log.debug(f"Handled Matrix message {event_id} -> {log_id}")
sender.send_remote_checkpoint(
MessageSendCheckpointStatus.SUCCESS,
event_id,

View File

@ -634,12 +634,13 @@ export default class PeerClient {
*/
sendChat = async (req) => {
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
return await talkChannel.sendChat({
const res = await talkChannel.sendChat({
text: req.text,
type: !!req.reply_to ? KnownChatType.REPLY : KnownChatType.TEXT,
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) => {
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
return await talkChannel.sendMedia(req.type, {
const res = await talkChannel.sendMedia(req.type, {
data: Uint8Array.from(req.data),
name: req.name,
width: req.width,
height: req.height,
ext: req.ext,
})
if (res.success) res.result = res.result.logId
return res
}
/**