Minor improvements
This commit is contained in:
parent
d9adfe1550
commit
3dc1f2612e
@ -276,7 +276,7 @@ class Client:
|
|||||||
async def send_message(self, channel_props: ChannelProps, text: str) -> Chatlog:
|
async def send_message(self, channel_props: ChannelProps, text: str) -> Chatlog:
|
||||||
return await self._api_user_request_result(
|
return await self._api_user_request_result(
|
||||||
Chatlog,
|
Chatlog,
|
||||||
"send_message",
|
"send_chat",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
text=text,
|
text=text,
|
||||||
)
|
)
|
||||||
|
@ -346,6 +346,14 @@ export default class PeerClient {
|
|||||||
return this.userClients.get(mxid)
|
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 {Object} req
|
||||||
* @param {OAuthCredential} req.oauth_credential
|
* @param {OAuthCredential} req.oauth_credential
|
||||||
@ -420,8 +428,7 @@ export default class PeerClient {
|
|||||||
* @param {Object} req.channel_props
|
* @param {Object} req.channel_props
|
||||||
*/
|
*/
|
||||||
getPortalChannelInfo = async (req) => {
|
getPortalChannelInfo = async (req) => {
|
||||||
const userClient = this.#getUser(req.mxid)
|
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
|
||||||
const talkChannel = await userClient.getChannel(req.channel_props)
|
|
||||||
|
|
||||||
const res = await talkChannel.updateAll()
|
const res = await talkChannel.updateAll()
|
||||||
if (!res.success) return res
|
if (!res.success) return res
|
||||||
@ -439,8 +446,7 @@ export default class PeerClient {
|
|||||||
* @param {Object} req.channel_props
|
* @param {Object} req.channel_props
|
||||||
*/
|
*/
|
||||||
getParticipants = async (req) => {
|
getParticipants = async (req) => {
|
||||||
const userClient = this.#getUser(req.mxid)
|
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
|
||||||
const talkChannel = await userClient.getChannel(req.channel_props)
|
|
||||||
return await talkChannel.getAllLatestUserInfo()
|
return await talkChannel.getAllLatestUserInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,8 +458,7 @@ export default class PeerClient {
|
|||||||
* @param {?Number} req.limit
|
* @param {?Number} req.limit
|
||||||
*/
|
*/
|
||||||
getChats = async (req) => {
|
getChats = async (req) => {
|
||||||
const userClient = this.#getUser(req.mxid)
|
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
|
||||||
const talkChannel = await userClient.getChannel(req.channel_props)
|
|
||||||
|
|
||||||
const res = await talkChannel.getChatListFrom(req.sync_from)
|
const res = await talkChannel.getChatListFrom(req.sync_from)
|
||||||
if (res.success && 0 < req.limit && req.limit < res.result.length) {
|
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 {Object} req.channel_props
|
||||||
* @param {string} req.text
|
* @param {string} req.text
|
||||||
*/
|
*/
|
||||||
sendMessage = async (req) => {
|
sendChat = async (req) => {
|
||||||
const userClient = this.#getUser(req.mxid)
|
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
|
||||||
const talkChannel = await userClient.getChannel(req.channel_props)
|
|
||||||
|
|
||||||
return await talkChannel.sendChat({
|
return await talkChannel.sendChat({
|
||||||
type: KnownChatType.TEXT,
|
type: KnownChatType.TEXT,
|
||||||
@ -527,8 +531,7 @@ export default class PeerClient {
|
|||||||
* @param {?string} req.ext
|
* @param {?string} req.ext
|
||||||
*/
|
*/
|
||||||
sendMedia = async (req) => {
|
sendMedia = async (req) => {
|
||||||
const userClient = this.#getUser(req.mxid)
|
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
|
||||||
const talkChannel = await userClient.getChannel(req.channel_props)
|
|
||||||
|
|
||||||
return await talkChannel.sendMedia(req.type, {
|
return await talkChannel.sendMedia(req.type, {
|
||||||
data: Uint8Array.from(req.data),
|
data: Uint8Array.from(req.data),
|
||||||
@ -620,7 +623,7 @@ export default class PeerClient {
|
|||||||
list_friends: this.listFriends,
|
list_friends: this.listFriends,
|
||||||
get_friend_dm_id: req => this.getFriendProperty(req, "directChatId"),
|
get_friend_dm_id: req => this.getFriendProperty(req, "directChatId"),
|
||||||
get_memo_ids: this.getMemoIds,
|
get_memo_ids: this.getMemoIds,
|
||||||
send_message: this.sendMessage,
|
send_chat: this.sendChat,
|
||||||
send_media: this.sendMedia,
|
send_media: this.sendMedia,
|
||||||
}[req.command] || this.handleUnknownCommand
|
}[req.command] || this.handleUnknownCommand
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user