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) => {
|
||||
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 =
|
||||
!req.user_id.equals(userClient.userId)
|
||||
? channelList.createChannel.bind(channelList, {
|
||||
@ -1237,6 +1238,22 @@ export default class PeerClient {
|
||||
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 {string} req.mxid
|
||||
|
Loading…
Reference in New Issue
Block a user