Minor improvements

This commit is contained in:
Andrew Ferrazzutti 2022-04-05 00:59:22 -04:00
parent d9adfe1550
commit 3dc1f2612e
2 changed files with 16 additions and 13 deletions

View File

@ -276,7 +276,7 @@ class Client:
async def send_message(self, channel_props: ChannelProps, text: str) -> Chatlog:
return await self._api_user_request_result(
Chatlog,
"send_message",
"send_chat",
channel_props=channel_props.serialize(),
text=text,
)

View File

@ -346,6 +346,14 @@ export default class PeerClient {
return this.userClients.get(mxid)
}
/**
* @param {string} mxid
* @param {Object} channel_props
*/
async #getUserChannel(mxid, channel_props) {
return await this.#getUser(mxid).getChannel(channel_props)
}
/**
* @param {Object} req
* @param {OAuthCredential} req.oauth_credential
@ -420,8 +428,7 @@ export default class PeerClient {
* @param {Object} req.channel_props
*/
getPortalChannelInfo = async (req) => {
const userClient = this.#getUser(req.mxid)
const talkChannel = await userClient.getChannel(req.channel_props)
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
const res = await talkChannel.updateAll()
if (!res.success) return res
@ -439,8 +446,7 @@ export default class PeerClient {
* @param {Object} req.channel_props
*/
getParticipants = async (req) => {
const userClient = this.#getUser(req.mxid)
const talkChannel = await userClient.getChannel(req.channel_props)
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
return await talkChannel.getAllLatestUserInfo()
}
@ -452,8 +458,7 @@ export default class PeerClient {
* @param {?Number} req.limit
*/
getChats = async (req) => {
const userClient = this.#getUser(req.mxid)
const talkChannel = await userClient.getChannel(req.channel_props)
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
const res = await talkChannel.getChatListFrom(req.sync_from)
if (res.success && 0 < req.limit && req.limit < res.result.length) {
@ -505,9 +510,8 @@ export default class PeerClient {
* @param {Object} req.channel_props
* @param {string} req.text
*/
sendMessage = async (req) => {
const userClient = this.#getUser(req.mxid)
const talkChannel = await userClient.getChannel(req.channel_props)
sendChat = async (req) => {
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
return await talkChannel.sendChat({
type: KnownChatType.TEXT,
@ -527,8 +531,7 @@ export default class PeerClient {
* @param {?string} req.ext
*/
sendMedia = async (req) => {
const userClient = this.#getUser(req.mxid)
const talkChannel = await userClient.getChannel(req.channel_props)
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
return await talkChannel.sendMedia(req.type, {
data: Uint8Array.from(req.data),
@ -620,7 +623,7 @@ export default class PeerClient {
list_friends: this.listFriends,
get_friend_dm_id: req => this.getFriendProperty(req, "directChatId"),
get_memo_ids: this.getMemoIds,
send_message: this.sendMessage,
send_chat: this.sendChat,
send_media: this.sendMedia,
}[req.command] || this.handleUnknownCommand
}