From 047f031dd7d20f2033682e4bfde6235c6c46d864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 16 Nov 2021 11:57:00 -0500 Subject: [PATCH] fix: #10006, dont allow new rooms or adding to a room if target is blocked --- src/messaging/index.js | 25 ++++++++++++++----------- src/socket.io/modules.js | 14 +------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/messaging/index.js b/src/messaging/index.js index 2f90270b60..c5cf1d46cd 100644 --- a/src/messaging/index.js +++ b/src/messaging/index.js @@ -187,32 +187,35 @@ Messaging.getLatestUndeletedMessage = async (uid, roomId) => { }; Messaging.canMessageUser = async (uid, toUid) => { - if (meta.config.disableChat || uid <= 0 || uid === toUid) { + if (meta.config.disableChat || uid <= 0) { throw new Error('[[error:chat-disabled]]'); } if (parseInt(uid, 10) === parseInt(toUid, 10)) { - throw new Error('[[error:cant-chat-with-yourself'); + throw new Error('[[error:cant-chat-with-yourself]]'); } + const [exists, canChat] = await Promise.all([ + user.exists(toUid), + privileges.global.can('chat', uid), + ]); - const exists = await user.exists(toUid); if (!exists) { throw new Error('[[error:no-user]]'); } - const canChat = await privileges.global.can('chat', uid); if (!canChat) { throw new Error('[[error:no-privileges]]'); } - const results = await utils.promiseParallel({ - settings: user.getSettings(toUid), - isAdmin: user.isAdministrator(uid), - isModerator: user.isModeratorOfAnyCategory(uid), - isFollowing: user.isFollowing(toUid, uid), - }); + const [settings, isAdmin, isModerator, isFollowing, isBlocked] = await Promise.all([ + user.getSettings(toUid), + user.isAdministrator(uid), + user.isModeratorOfAnyCategory(uid), + user.isFollowing(toUid, uid), + user.blocks.is(uid, toUid), + ]); - if (results.settings.restrictChat && !results.isAdmin && !results.isModerator && !results.isFollowing) { + if (isBlocked || (settings.restrictChat && !isAdmin && !isModerator && !isFollowing)) { throw new Error('[[error:chat-restricted]]'); } diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js index 20c20b2e8e..f2804af9a4 100644 --- a/src/socket.io/modules.js +++ b/src/socket.io/modules.js @@ -146,19 +146,7 @@ SocketModules.chats.addUserToRoom = async function (socket, data) { if (!uid) { throw new Error('[[error:no-user]]'); } - if (socket.uid === parseInt(uid, 10)) { - throw new Error('[[error:cant-chat-with-yourself]]'); - } - const [settings, isAdminOrGlobalMod, isFollowing] = await Promise.all([ - user.getSettings(uid), - user.isAdminOrGlobalMod(socket.uid), - user.isFollowing(uid, socket.uid), - ]); - - if (settings.restrictChat && !isAdminOrGlobalMod && !isFollowing) { - throw new Error('[[error:chat-restricted]]'); - } - + await Messaging.canMessageUser(socket.uid, uid); await Messaging.addUsersToRoom(socket.uid, [uid], data.roomId); };