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

isekai-main
Barış Soner Uşaklı 3 years ago
parent c16dad40cf
commit 047f031dd7

@ -187,32 +187,35 @@ Messaging.getLatestUndeletedMessage = async (uid, roomId) => {
}; };
Messaging.canMessageUser = async (uid, toUid) => { 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]]'); throw new Error('[[error:chat-disabled]]');
} }
if (parseInt(uid, 10) === parseInt(toUid, 10)) { 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) { if (!exists) {
throw new Error('[[error:no-user]]'); throw new Error('[[error:no-user]]');
} }
const canChat = await privileges.global.can('chat', uid);
if (!canChat) { if (!canChat) {
throw new Error('[[error:no-privileges]]'); throw new Error('[[error:no-privileges]]');
} }
const results = await utils.promiseParallel({ const [settings, isAdmin, isModerator, isFollowing, isBlocked] = await Promise.all([
settings: user.getSettings(toUid), user.getSettings(toUid),
isAdmin: user.isAdministrator(uid), user.isAdministrator(uid),
isModerator: user.isModeratorOfAnyCategory(uid), user.isModeratorOfAnyCategory(uid),
isFollowing: user.isFollowing(toUid, 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]]'); throw new Error('[[error:chat-restricted]]');
} }

@ -146,19 +146,7 @@ SocketModules.chats.addUserToRoom = async function (socket, data) {
if (!uid) { if (!uid) {
throw new Error('[[error:no-user]]'); throw new Error('[[error:no-user]]');
} }
if (socket.uid === parseInt(uid, 10)) { await Messaging.canMessageUser(socket.uid, uid);
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.addUsersToRoom(socket.uid, [uid], data.roomId); await Messaging.addUsersToRoom(socket.uid, [uid], data.roomId);
}; };

Loading…
Cancel
Save