Skip to content

Node.js based forum software built for the modern web

fix: #10006, dont allow new rooms or adding to a room if target is blocked

Barış Soner Uşaklı047f031dd7d2
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);
};