Fast-fail when trying to create a DM with a non-friend user
This commit is contained in:
parent
1541732d0b
commit
47b9623446
|
@ -1212,8 +1212,9 @@ export default class PeerClient {
|
||||||
*/
|
*/
|
||||||
createDirectChat = async (req) => {
|
createDirectChat = async (req) => {
|
||||||
const userClient = this.#getUser(req.mxid)
|
const userClient = this.#getUser(req.mxid)
|
||||||
const channelList = userClient.talkClient.channelList.normal
|
await this.#requireInFriendsList(userClient.serviceClient, req.user_id)
|
||||||
|
|
||||||
|
const channelList = userClient.talkClient.channelList.normal
|
||||||
const createChannel =
|
const createChannel =
|
||||||
!req.user_id.equals(userClient.userId)
|
!req.user_id.equals(userClient.userId)
|
||||||
? channelList.createChannel.bind(channelList, {
|
? channelList.createChannel.bind(channelList, {
|
||||||
|
@ -1237,6 +1238,22 @@ export default class PeerClient {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ServiceApiClient} serviceClient
|
||||||
|
* @param {Long} id
|
||||||
|
*/
|
||||||
|
async #requireInFriendsList(serviceClient, id) {
|
||||||
|
let listRes = await serviceClient.requestFriendList()
|
||||||
|
if (!listRes.success) {
|
||||||
|
this.error("Failed to check friends list")
|
||||||
|
throw listRes
|
||||||
|
}
|
||||||
|
const isFriend = -1 != listRes.result.friends.findIndex(friend => id.equals(friend.userId))
|
||||||
|
if (!isFriend) {
|
||||||
|
throw new ProtocolError("This user is not in your friends list")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {object} req
|
* @param {object} req
|
||||||
* @param {string} req.mxid
|
* @param {string} req.mxid
|
||||||
|
|
Loading…
Reference in New Issue