v1.18.x
Julian Lam 10 years ago
parent 28f87cc776
commit adfb89a2ad

@ -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,6 +314,8 @@ var socket,
}
require(['chat'], function (chat) {
chat.canMessage(touid, function(err) {
if (!err) {
if (!chat.modalExists(touid)) {
chat.createModal(username, touid, loadAndCenter);
} else {
@ -324,6 +326,10 @@ var socket,
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);
});
}
};

@ -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,6 +146,8 @@ SocketModules.chats.send = function(socket, data, callback) {
return callback(new Error('[[error:user-banned]]'));
}
Messaging.canMessage(socket.uid, touid, function(err, allowed) {
if (allowed) {
Messaging.addMessage(socket.uid, touid, msg, function(err, message) {
if (err) {
return callback(err);
@ -168,7 +170,19 @@ SocketModules.chats.send = function(socket, data, callback) {
message: message,
self: 1
});
callback();
});
} else {
callback(new Error('[[error:chat-restricted]]'))
}
})
});
};
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);
};

Loading…
Cancel
Save