mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 09:36:16 +01:00
closed #2321
This commit is contained in:
@@ -77,6 +77,7 @@
|
||||
"signature-too-long" : "Sorry, your signature cannot be longer than %1 characters.",
|
||||
|
||||
"cant-chat-with-yourself": "You can't chat with yourself!",
|
||||
"chat-restricted": "This user has restricted their chat messages. They must follow you before you can chat with them",
|
||||
|
||||
"reputation-system-disabled": "Reputation system is disabled.",
|
||||
"downvoting-disabled": "Downvoting is disabled",
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
"settings": "Settings",
|
||||
"show_email": "Show My Email",
|
||||
"show_fullname": "Show My Full Name",
|
||||
"restrict_chats": "Only allow chat messages from users I follow",
|
||||
"digest_label": "Subscribe to Digest",
|
||||
"digest_description": "Subscribe to email updates for this forum (new notifications and topics) according to a set schedule",
|
||||
"digest_off": "Off",
|
||||
|
||||
@@ -314,16 +314,22 @@ var socket,
|
||||
}
|
||||
|
||||
require(['chat'], function (chat) {
|
||||
if (!chat.modalExists(touid)) {
|
||||
chat.createModal(username, touid, loadAndCenter);
|
||||
} else {
|
||||
loadAndCenter(chat.getModal(touid));
|
||||
}
|
||||
chat.canMessage(touid, function(err) {
|
||||
if (!err) {
|
||||
if (!chat.modalExists(touid)) {
|
||||
chat.createModal(username, touid, loadAndCenter);
|
||||
} else {
|
||||
loadAndCenter(chat.getModal(touid));
|
||||
}
|
||||
|
||||
function loadAndCenter(chatModal) {
|
||||
chat.load(chatModal.attr('UUID'));
|
||||
chat.center(chatModal);
|
||||
}
|
||||
function loadAndCenter(chatModal) {
|
||||
chat.load(chatModal.attr('UUID'));
|
||||
chat.center(chatModal);
|
||||
}
|
||||
} else {
|
||||
app.alertError(err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -201,10 +201,15 @@ define('forum/chats', ['string', 'sounds', 'forum/infinitescroll'], function(S,
|
||||
socket.emit('modules.chats.send', {
|
||||
touid:toUid,
|
||||
message:msg
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
inputEl.val('');
|
||||
sounds.play('chat-outgoing');
|
||||
Chats.notifyTyping(toUid, false);
|
||||
});
|
||||
inputEl.val('');
|
||||
sounds.play('chat-outgoing');
|
||||
Chats.notifyTyping(toUid, false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -353,5 +353,9 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,
|
||||
taskbar.toggleNew(uuid, state);
|
||||
};
|
||||
|
||||
module.canMessage = function(toUid, callback) {
|
||||
socket.emit('modules.chats.canMessage', toUid, callback);
|
||||
};
|
||||
|
||||
return module;
|
||||
});
|
||||
|
||||
@@ -292,6 +292,34 @@ var db = require('./database'),
|
||||
}, 1000*60); // wait 60s before sending
|
||||
};
|
||||
|
||||
Messaging.canMessage = function(fromUid, toUid, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
// Check if the sending user is an admin
|
||||
user.isAdministrator(fromUid, function(err, isAdmin) {
|
||||
next(err || isAdmin);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
// Retrieve the recipient's user setting
|
||||
user.getSettings(toUid, function(err, settings) {
|
||||
next(err || !settings.restrictChat);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
// Does toUid follow fromUid?
|
||||
user.isFollowing(toUid, fromUid, next);
|
||||
}
|
||||
], function(err, allowed) {
|
||||
// Handle premature returns
|
||||
if (err === true) {
|
||||
return callback(undefined, true);
|
||||
}
|
||||
|
||||
callback.apply(this, arguments);
|
||||
});
|
||||
}
|
||||
|
||||
function sendNotifications(fromuid, touid, messageObj, callback) {
|
||||
// todo #1798 -- this should check if the user is in room `chat_{uidA}_{uidB}` instead, see `Sockets.uidInRoom(uid, room);`
|
||||
if (!websockets.isUserOnline(touid)) {
|
||||
|
||||
@@ -146,29 +146,43 @@ SocketModules.chats.send = function(socket, data, callback) {
|
||||
return callback(new Error('[[error:user-banned]]'));
|
||||
}
|
||||
|
||||
Messaging.addMessage(socket.uid, touid, msg, function(err, message) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
Messaging.canMessage(socket.uid, touid, function(err, allowed) {
|
||||
if (allowed) {
|
||||
Messaging.addMessage(socket.uid, touid, msg, function(err, message) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
Messaging.notifyUser(socket.uid, touid, message);
|
||||
|
||||
// Recipient
|
||||
SocketModules.chats.pushUnreadCount(touid);
|
||||
server.in('uid_' + touid).emit('event:chats.receive', {
|
||||
withUid: socket.uid,
|
||||
message: message,
|
||||
self: 0
|
||||
});
|
||||
|
||||
// Sender
|
||||
SocketModules.chats.pushUnreadCount(socket.uid);
|
||||
server.in('uid_' + socket.uid).emit('event:chats.receive', {
|
||||
withUid: touid,
|
||||
message: message,
|
||||
self: 1
|
||||
});
|
||||
|
||||
callback();
|
||||
});
|
||||
} else {
|
||||
callback(new Error('[[error:chat-restricted]]'))
|
||||
}
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
Messaging.notifyUser(socket.uid, touid, message);
|
||||
|
||||
// Recipient
|
||||
SocketModules.chats.pushUnreadCount(touid);
|
||||
server.in('uid_' + touid).emit('event:chats.receive', {
|
||||
withUid: socket.uid,
|
||||
message: message,
|
||||
self: 0
|
||||
});
|
||||
|
||||
// Sender
|
||||
SocketModules.chats.pushUnreadCount(socket.uid);
|
||||
server.in('uid_' + socket.uid).emit('event:chats.receive', {
|
||||
withUid: touid,
|
||||
message: message,
|
||||
self: 1
|
||||
});
|
||||
});
|
||||
SocketModules.chats.canMessage = function(socket, toUid, callback) {
|
||||
Messaging.canMessage(socket.uid, toUid, function(err, allowed) {
|
||||
callback(!allowed ? new Error('[[error:chat-restricted]]') : undefined);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ module.exports = function(User) {
|
||||
settings.followTopicsOnCreate = (settings.followTopicsOnCreate === null || settings.followTopicsOnCreate === undefined) ? true : parseInt(settings.followTopicsOnCreate, 10) === 1;
|
||||
settings.followTopicsOnReply = parseInt(settings.followTopicsOnReply, 10) === 1;
|
||||
settings.sendChatNotifications = parseInt(settings.sendChatNotifications, 10) === 1;
|
||||
settings.restrictChat = parseInt(settings.restrictChat, 10) === 1;
|
||||
|
||||
callback(null, settings);
|
||||
});
|
||||
@@ -88,7 +89,8 @@ module.exports = function(User) {
|
||||
language: data.language || meta.config.defaultLang,
|
||||
followTopicsOnCreate: data.followTopicsOnCreate,
|
||||
followTopicsOnReply: data.followTopicsOnReply,
|
||||
sendChatNotifications: data.sendChatNotifications
|
||||
sendChatNotifications: data.sendChatNotifications,
|
||||
restrictChat: data.restrictChat
|
||||
}, callback);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user