mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	send messages
This commit is contained in:
		| @@ -34,14 +34,6 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
| 	Chats.getRecipientUid = function() { | ||||
| 		return parseInt($('.expanded-chat').attr('data-uid'), 10); | ||||
| 	}; | ||||
|  | ||||
| 	Chats.isCurrentChat = function(uid) { | ||||
| 		return Chats.getRecipientUid() === parseInt(uid, 10); | ||||
| 	}; | ||||
|  | ||||
| 	Chats.addEventListeners = function() { | ||||
| 		$('[component="chat/recent"]').on('click', '[component="chat/recent/room"]', function() { | ||||
| 			Chats.switchChat($(this).attr('data-roomid')); | ||||
| @@ -280,42 +272,11 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', | ||||
|  | ||||
| 	Chats.addSocketListeners = function() { | ||||
| 		socket.on('event:chats.receive', function(data) { | ||||
| 			if (Chats.isCurrentChat(data.withUid)) { | ||||
| 			if (parseInt(data.roomId, 10) === parseInt(ajaxify.data.roomId, 10)) { | ||||
| 				newMessage = data.self === 0; | ||||
| 				data.message.self = data.self; | ||||
|  | ||||
| 				Chats.appendChatMessage($('.expanded-chat .chat-content'), data.message); | ||||
| 			} else { | ||||
| 				var contactEl = $('[component="chat/recent"] li[data-uid="' + data.withUid + '"]'), | ||||
| 					userKey = parseInt(data.withUid, 10) === parseInt(data.message.fromuid, 10) ? 'fromUser' : 'toUser'; | ||||
|  | ||||
| 				// Spawn a new contact if required | ||||
| 				templates.parse('partials/chat_contacts', { | ||||
| 					contacts: [{ | ||||
| 						uid: data.message[userKey].uid, | ||||
| 						username: data.message[userKey].username, | ||||
| 						status: data.message[userKey].status, | ||||
| 						picture: data.message[userKey].picture, | ||||
| 						'icon:text': data.message[userKey]['icon:text'], | ||||
| 						'icon:bgColor': data.message[userKey]['icon:bgColor'], | ||||
| 						teaser: { | ||||
| 							content: data.message.cleanedContent, | ||||
| 							timestampISO: new Date(Date.now()).toISOString() | ||||
| 						} | ||||
| 					}] | ||||
| 				}, function(html) { | ||||
| 					translator.translate(html, function(translatedHTML) { | ||||
| 						if (contactEl.length) { | ||||
| 							contactEl.replaceWith(translatedHTML); | ||||
| 						} else { | ||||
| 							$('[component="chat/recent"]').prepend(translatedHTML); | ||||
| 						} | ||||
|  | ||||
| 						// Mark that contact list entry unread | ||||
| 						$('.chats-list li[data-uid="' + data.withUid + '"]').addClass('unread').find('.timeago').timeago(); | ||||
| 						app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + data.message.fromUser.username + ']]'); | ||||
| 					}); | ||||
| 				}); | ||||
| 			} | ||||
| 		}); | ||||
|  | ||||
|   | ||||
| @@ -20,14 +20,12 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra | ||||
|  | ||||
| 		socket.on('event:chats.receive', function(data) { | ||||
| 			var username = data.message.fromUser.username; | ||||
| 			var isSelf = parseInt(data.message.fromUser.uid, 10) === parseInt(app.user.uid, 10); | ||||
| 			var isSelf = data.self === 1; | ||||
| 			data.message.self = data.self; | ||||
| 			if (isSelf) { | ||||
| 				username = data.message.toUser.username; | ||||
| 			} | ||||
|  | ||||
| 			newMessage = data.self === 0; | ||||
| 			if (module.modalExists(data.withUid)) { | ||||
| 				var modal = module.getModal(data.withUid); | ||||
| 			if (module.modalExists(data.roomId)) { | ||||
| 				var modal = module.getModal(data.roomId); | ||||
|  | ||||
| 				Chats.appendChatMessage(modal.find('.chat-content'), data.message); | ||||
|  | ||||
| @@ -49,8 +47,7 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra | ||||
| 				} | ||||
| 			} else { | ||||
| 				module.createModal({ | ||||
| 					username: username, | ||||
| 					touid: data.withUid, | ||||
| 					roomId: data.roomId, | ||||
| 					silent: true | ||||
| 				}, function(modal) { | ||||
| 					module.toggleNew(modal.attr('UUID'), true, true); | ||||
|   | ||||
| @@ -21,6 +21,7 @@ module.exports = function(Messaging) { | ||||
| 				if (!inRoom) { | ||||
| 					return next(new Error('[[error:not-allowed]]')); | ||||
| 				} | ||||
|  | ||||
| 				Messaging.addMessage(uid, roomId, content, timestamp, next); | ||||
| 			} | ||||
| 		], callback); | ||||
| @@ -34,11 +35,13 @@ module.exports = function(Messaging) { | ||||
| 		if (content.length > (meta.config.maximumChatMessageLength || 1000)) { | ||||
| 			return callback(new Error('[[error:chat-message-too-long]]')); | ||||
| 		} | ||||
| 		callback(); | ||||
| 	}; | ||||
|  | ||||
| 	Messaging.addMessage = function(fromuid, roomId, content, timestamp, callback) { | ||||
| 		var mid; | ||||
| 		var message; | ||||
|  | ||||
| 		async.waterfall([ | ||||
| 			function (next) { | ||||
| 				Messaging.checkContent(content, next); | ||||
|   | ||||
| @@ -5,7 +5,7 @@ var nconf = require('nconf'); | ||||
|  | ||||
| var user = require('../user'); | ||||
| var emailer = require('../emailer'); | ||||
| var notifications = require('./notifications'); | ||||
| var notifications = require('../notifications'); | ||||
| var meta = require('../meta'); | ||||
| var utils = require('../../public/src/utils'); | ||||
| var sockets = require('../socket.io'); | ||||
| @@ -99,7 +99,6 @@ module.exports = function(Messaging) { | ||||
| 						fromUserslug: utils.slugify(messageObj.fromUser.username) | ||||
| 					}, next); | ||||
| 				}, callback); | ||||
|  | ||||
| 			}); | ||||
| 		}); | ||||
| 	} | ||||
|   | ||||
| @@ -36,7 +36,8 @@ module.exports = function(Messaging) { | ||||
| 				var keys = uids.map(function(uid) { | ||||
| 					return 'uid:' + uid + ':chat:rooms:unread'; | ||||
| 				}); | ||||
| 				db.sortedSetAdd(keys, Date.now(), roomId, next); | ||||
|  | ||||
| 				db.sortedSetsAdd(keys, Date.now(), roomId, next); | ||||
| 			} | ||||
| 		], callback); | ||||
| 	}; | ||||
|   | ||||
| @@ -197,10 +197,20 @@ SocketModules.chats.userStopTyping = function(socket, data, callback) { | ||||
| }; | ||||
|  | ||||
| function sendTypingNotification(event, socket, data, callback) { | ||||
| 	if (!socket.uid || !data) { | ||||
| 	if (!socket.uid || !data || !data.roomId) { | ||||
| 		return; | ||||
| 	} | ||||
| 	server.in('uid_' + data.touid).emit(event, data.fromUid); | ||||
|  | ||||
| 	Messaging.getUidsInRoom(data.roomId, 0, -1, function(err, uids) { | ||||
| 		if (err) { | ||||
| 			return callback(err); | ||||
| 		} | ||||
| 		uids.forEach(function(uid) { | ||||
| 			if (socket.uid !== parseInt(uid, 10)) { | ||||
| 				server.in('uid_' + uid).emit(event, data.fromUid); | ||||
| 			} | ||||
| 		}); | ||||
| 	}); | ||||
| } | ||||
|  | ||||
| SocketModules.chats.getRecentChats = function(socket, data, callback) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user