diff --git a/node/src/client.js b/node/src/client.js index 622c51a..15b71f5 100644 --- a/node/src/client.js +++ b/node/src/client.js @@ -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