|
|
@ -199,6 +199,7 @@ Messaging.canMessageUser = async (uid, toUid) => {
|
|
|
|
const [exists, canChat] = await Promise.all([
|
|
|
|
const [exists, canChat] = await Promise.all([
|
|
|
|
user.exists(toUid),
|
|
|
|
user.exists(toUid),
|
|
|
|
privileges.global.can('chat', uid),
|
|
|
|
privileges.global.can('chat', uid),
|
|
|
|
|
|
|
|
checkReputation(uid),
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
if (!exists) {
|
|
|
|
if (!exists) {
|
|
|
@ -232,12 +233,16 @@ Messaging.canMessageRoom = async (uid, roomId) => {
|
|
|
|
throw new Error('[[error:chat-disabled]]');
|
|
|
|
throw new Error('[[error:chat-disabled]]');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const inRoom = await Messaging.isUserInRoom(uid, roomId);
|
|
|
|
const [inRoom, canChat] = await Promise.all([
|
|
|
|
|
|
|
|
Messaging.isUserInRoom(uid, roomId),
|
|
|
|
|
|
|
|
privileges.global.can('chat', uid),
|
|
|
|
|
|
|
|
checkReputation(uid),
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
if (!inRoom) {
|
|
|
|
if (!inRoom) {
|
|
|
|
throw new Error('[[error:not-in-room]]');
|
|
|
|
throw new Error('[[error:not-in-room]]');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const canChat = await privileges.global.can('chat', uid);
|
|
|
|
|
|
|
|
if (!canChat) {
|
|
|
|
if (!canChat) {
|
|
|
|
throw new Error('[[error:no-privileges]]');
|
|
|
|
throw new Error('[[error:no-privileges]]');
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -248,6 +253,15 @@ Messaging.canMessageRoom = async (uid, roomId) => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function checkReputation(uid) {
|
|
|
|
|
|
|
|
if (meta.config['min:rep:chat'] > 0) {
|
|
|
|
|
|
|
|
const reputation = await user.getUserField(uid, 'reputation');
|
|
|
|
|
|
|
|
if (meta.config['min:rep:chat'] > reputation) {
|
|
|
|
|
|
|
|
throw new Error(`[[error:not-enough-reputation-to-chat, ${meta.config['min:rep:chat']}]]`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Messaging.hasPrivateChat = async (uid, withUid) => {
|
|
|
|
Messaging.hasPrivateChat = async (uid, withUid) => {
|
|
|
|
if (parseInt(uid, 10) === parseInt(withUid, 10)) {
|
|
|
|
if (parseInt(uid, 10) === parseInt(withUid, 10)) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|