mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	closes #4335
This commit is contained in:
		| @@ -6,6 +6,7 @@ | |||||||
| 	"chat.user_typing": "%1 is typing ...", | 	"chat.user_typing": "%1 is typing ...", | ||||||
| 	"chat.user_has_messaged_you": "%1 has messaged you.", | 	"chat.user_has_messaged_you": "%1 has messaged you.", | ||||||
| 	"chat.see_all": "See all chats", | 	"chat.see_all": "See all chats", | ||||||
|  | 	"chat.mark_all_read": "Mark all chats read", | ||||||
| 	"chat.no-messages": "Please select a recipient to view chat message history", | 	"chat.no-messages": "Please select a recipient to view chat message history", | ||||||
| 	"chat.no-users-in-room": "No users in this room", | 	"chat.no-users-in-room": "No users in this room", | ||||||
| 	"chat.recent-chats": "Recent Chats", | 	"chat.recent-chats": "Recent Chats", | ||||||
|   | |||||||
| @@ -7,8 +7,8 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra | |||||||
| 	var newMessage = false; | 	var newMessage = false; | ||||||
|  |  | ||||||
| 	module.prepareDOM = function() { | 	module.prepareDOM = function() { | ||||||
| 		var	chatsToggleEl = components.get('chat/dropdown'), | 		var	chatsToggleEl = components.get('chat/dropdown'); | ||||||
| 			chatsListEl = components.get('chat/list'); | 		var chatsListEl = components.get('chat/list'); | ||||||
|  |  | ||||||
| 		chatsToggleEl.on('click', function() { | 		chatsToggleEl.on('click', function() { | ||||||
| 			if (chatsToggleEl.parent().hasClass('open')) { | 			if (chatsToggleEl.parent().hasClass('open')) { | ||||||
| @@ -18,6 +18,14 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra | |||||||
| 			module.loadChatsDropdown(chatsListEl); | 			module.loadChatsDropdown(chatsListEl); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|  | 		$('[component="chats/mark-all-read"]').on('click', function() { | ||||||
|  | 			socket.emit('modules.chats.markAllRead', function(err) { | ||||||
|  | 				if (err) { | ||||||
|  | 					return app.alertError(err); | ||||||
|  | 				} | ||||||
|  | 			}); | ||||||
|  | 		}); | ||||||
|  |  | ||||||
| 		socket.on('event:chats.receive', function(data) { | 		socket.on('event:chats.receive', function(data) { | ||||||
| 			var username = data.message.fromUser.username; | 			var username = data.message.fromUser.username; | ||||||
| 			var isSelf = data.self === 1; | 			var isSelf = data.self === 1; | ||||||
|   | |||||||
| @@ -8,10 +8,16 @@ var sockets = require('../socket.io'); | |||||||
| module.exports = function(Messaging) { | module.exports = function(Messaging) { | ||||||
|  |  | ||||||
| 	Messaging.getUnreadCount = function(uid, callback) { | 	Messaging.getUnreadCount = function(uid, callback) { | ||||||
|  | 		if (!parseInt(uid, 10)) { | ||||||
|  | 			return callback(null, 0); | ||||||
|  | 		} | ||||||
| 		db.sortedSetCard('uid:' + uid + ':chat:rooms:unread', callback); | 		db.sortedSetCard('uid:' + uid + ':chat:rooms:unread', callback); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	Messaging.pushUnreadCount = function(uid) { | 	Messaging.pushUnreadCount = function(uid) { | ||||||
|  | 		if (!parseInt(uid, 10)) { | ||||||
|  | 			return callback(null, 0); | ||||||
|  | 		} | ||||||
| 		Messaging.getUnreadCount(uid, function(err, unreadCount) { | 		Messaging.getUnreadCount(uid, function(err, unreadCount) { | ||||||
| 			if (err) { | 			if (err) { | ||||||
| 				return; | 				return; | ||||||
| @@ -24,6 +30,10 @@ module.exports = function(Messaging) { | |||||||
| 		db.sortedSetRemove('uid:' + uid + ':chat:rooms:unread', roomId, callback); | 		db.sortedSetRemove('uid:' + uid + ':chat:rooms:unread', roomId, callback); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|  | 	Messaging.markAllRead = function(uid, callback) { | ||||||
|  | 		db.delete('uid:' + uid + ':chat:rooms:unread', callback); | ||||||
|  | 	}; | ||||||
|  |  | ||||||
| 	Messaging.markUnread = function(uids, roomId, callback) { | 	Messaging.markUnread = function(uids, roomId, callback) { | ||||||
| 		async.waterfall([ | 		async.waterfall([ | ||||||
| 			function (next) { | 			function (next) { | ||||||
|   | |||||||
| @@ -61,7 +61,7 @@ SocketModules.chats.newRoom = function(socket, data, callback) { | |||||||
| 		socket.lastChatMessageTime = now; | 		socket.lastChatMessageTime = now; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	Messaging.canMessageUser(socket.uid, data.touid, function(err, allowed) { | 	Messaging.canMessageUser(socket.uid, data.touid, function(err) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return callback(err); | 			return callback(err); | ||||||
| 		} | 		} | ||||||
| @@ -244,6 +244,18 @@ SocketModules.chats.markRead = function(socket, roomId, callback) { | |||||||
| 	}); | 	}); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | SocketModules.chats.markAllRead = function(socket, data, callback) { | ||||||
|  | 	async.waterfall([ | ||||||
|  | 		function (next) { | ||||||
|  | 			Messaging.markAllRead(socket.uid, next); | ||||||
|  | 		}, | ||||||
|  | 		function (next) { | ||||||
|  | 			Messaging.pushUnreadCount(socket.uid); | ||||||
|  | 			next(); | ||||||
|  | 		} | ||||||
|  | 	], callback); | ||||||
|  | }; | ||||||
|  |  | ||||||
| SocketModules.chats.renameRoom = function(socket, data, callback) { | SocketModules.chats.renameRoom = function(socket, data, callback) { | ||||||
| 	if (!data) { | 	if (!data) { | ||||||
| 		return callback(new Error('[[error:invalid-name]]')); | 		return callback(new Error('[[error:invalid-name]]')); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user