mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +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.", | 	"signature-too-long" : "Sorry, your signature cannot be longer than %1 characters.", | ||||||
|  |  | ||||||
| 	"cant-chat-with-yourself": "You can't chat with yourself!", | 	"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.", | 	"reputation-system-disabled": "Reputation system is disabled.", | ||||||
| 	"downvoting-disabled": "Downvoting is disabled", | 	"downvoting-disabled": "Downvoting is disabled", | ||||||
|   | |||||||
| @@ -53,6 +53,7 @@ | |||||||
| 	"settings": "Settings", | 	"settings": "Settings", | ||||||
| 	"show_email": "Show My Email", | 	"show_email": "Show My Email", | ||||||
| 	"show_fullname": "Show My Full Name", | 	"show_fullname": "Show My Full Name", | ||||||
|  | 	"restrict_chats": "Only allow chat messages from users I follow", | ||||||
| 	"digest_label": "Subscribe to Digest", | 	"digest_label": "Subscribe to Digest", | ||||||
| 	"digest_description": "Subscribe to email updates for this forum (new notifications and topics) according to a set schedule", | 	"digest_description": "Subscribe to email updates for this forum (new notifications and topics) according to a set schedule", | ||||||
| 	"digest_off": "Off", | 	"digest_off": "Off", | ||||||
|   | |||||||
| @@ -314,16 +314,22 @@ var socket, | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		require(['chat'], function (chat) { | 		require(['chat'], function (chat) { | ||||||
| 			if (!chat.modalExists(touid)) { | 			chat.canMessage(touid, function(err) { | ||||||
| 				chat.createModal(username, touid, loadAndCenter); | 				if (!err) { | ||||||
| 			} else { | 					if (!chat.modalExists(touid)) { | ||||||
| 				loadAndCenter(chat.getModal(touid)); | 						chat.createModal(username, touid, loadAndCenter); | ||||||
| 			} | 					} else { | ||||||
|  | 						loadAndCenter(chat.getModal(touid)); | ||||||
|  | 					} | ||||||
|  |  | ||||||
| 			function loadAndCenter(chatModal) { | 					function loadAndCenter(chatModal) { | ||||||
| 				chat.load(chatModal.attr('UUID')); | 						chat.load(chatModal.attr('UUID')); | ||||||
| 				chat.center(chatModal); | 						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', { | 			socket.emit('modules.chats.send', { | ||||||
| 				touid:toUid, | 				touid:toUid, | ||||||
| 				message:msg | 				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); | 		taskbar.toggleNew(uuid, state); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|  | 	module.canMessage = function(toUid, callback) { | ||||||
|  | 		socket.emit('modules.chats.canMessage', toUid, callback); | ||||||
|  | 	}; | ||||||
|  |  | ||||||
| 	return module; | 	return module; | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -292,6 +292,34 @@ var db = require('./database'), | |||||||
| 		}, 1000*60);	// wait 60s before sending | 		}, 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) { | 	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);` | 		// todo #1798 -- this should check if the user is in room `chat_{uidA}_{uidB}` instead, see `Sockets.uidInRoom(uid, room);` | ||||||
| 		if (!websockets.isUserOnline(touid)) { | 		if (!websockets.isUserOnline(touid)) { | ||||||
|   | |||||||
| @@ -146,29 +146,43 @@ SocketModules.chats.send = function(socket, data, callback) { | |||||||
| 			return callback(new Error('[[error:user-banned]]')); | 			return callback(new Error('[[error:user-banned]]')); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		Messaging.addMessage(socket.uid, touid, msg, function(err, message) { | 		Messaging.canMessage(socket.uid, touid, function(err, allowed) { | ||||||
| 			if (err) { | 			if (allowed) { | ||||||
| 				return callback(err); | 				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); | SocketModules.chats.canMessage = function(socket, toUid, callback) { | ||||||
|  | 	Messaging.canMessage(socket.uid, toUid, function(err, allowed) { | ||||||
| 			// Recipient | 		callback(!allowed ? new Error('[[error:chat-restricted]]') : undefined); | ||||||
| 			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 |  | ||||||
| 			}); |  | ||||||
| 		}); |  | ||||||
| 	}); | 	}); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -37,6 +37,7 @@ module.exports = function(User) { | |||||||
| 				settings.followTopicsOnCreate = (settings.followTopicsOnCreate === null || settings.followTopicsOnCreate === undefined) ? true : parseInt(settings.followTopicsOnCreate, 10) === 1; | 				settings.followTopicsOnCreate = (settings.followTopicsOnCreate === null || settings.followTopicsOnCreate === undefined) ? true : parseInt(settings.followTopicsOnCreate, 10) === 1; | ||||||
| 				settings.followTopicsOnReply = parseInt(settings.followTopicsOnReply, 10) === 1; | 				settings.followTopicsOnReply = parseInt(settings.followTopicsOnReply, 10) === 1; | ||||||
| 				settings.sendChatNotifications = parseInt(settings.sendChatNotifications, 10) === 1; | 				settings.sendChatNotifications = parseInt(settings.sendChatNotifications, 10) === 1; | ||||||
|  | 				settings.restrictChat = parseInt(settings.restrictChat, 10) === 1; | ||||||
|  |  | ||||||
| 				callback(null, settings); | 				callback(null, settings); | ||||||
| 			}); | 			}); | ||||||
| @@ -88,7 +89,8 @@ module.exports = function(User) { | |||||||
| 			language: data.language || meta.config.defaultLang, | 			language: data.language || meta.config.defaultLang, | ||||||
| 			followTopicsOnCreate: data.followTopicsOnCreate, | 			followTopicsOnCreate: data.followTopicsOnCreate, | ||||||
| 			followTopicsOnReply: data.followTopicsOnReply, | 			followTopicsOnReply: data.followTopicsOnReply, | ||||||
| 			sendChatNotifications: data.sendChatNotifications | 			sendChatNotifications: data.sendChatNotifications, | ||||||
|  | 			restrictChat: data.restrictChat | ||||||
| 		}, callback); | 		}, callback); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user