mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	various group chat fixes #3980
fix multiple modals using the same tagsinput fix online user getting chat notification fix owner not being able to remove users in the chat modal
This commit is contained in:
		| @@ -254,16 +254,17 @@ app.cacheBuster = null; | |||||||
| 			if (chat.modalExists(roomId)) { | 			if (chat.modalExists(roomId)) { | ||||||
| 				loadAndCenter(chat.getModal(roomId)); | 				loadAndCenter(chat.getModal(roomId)); | ||||||
| 			} else { | 			} else { | ||||||
| 				socket.emit('modules.chats.getUsersInRoom', {roomId: roomId}, function(err, users) { | 				socket.emit('modules.chats.loadRoom', {roomId: roomId}, function(err, roomData) { | ||||||
| 					if (err) { | 					if (err) { | ||||||
| 						return app.alertError(err.message); | 						return app.alertError(err.message); | ||||||
| 					} | 					} | ||||||
| 					users = users.filter(function(user) { | 					roomData.users = roomData.users.filter(function(user) { | ||||||
| 						return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10); | 						return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10); | ||||||
| 					}); | 					}); | ||||||
| 					chat.createModal({ | 					chat.createModal({ | ||||||
| 						roomId: roomId, | 						roomId: roomId, | ||||||
| 						users: users | 						users: roomData.users, | ||||||
|  | 						owner: roomData.owner | ||||||
| 					}, loadAndCenter); | 					}, loadAndCenter); | ||||||
| 				}); | 				}); | ||||||
| 			} | 			} | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		Chats.addEventListeners(); | 		Chats.addEventListeners(); | ||||||
| 		Chats.createTagsInput(ajaxify.data.roomId, ajaxify.data.users); | 		Chats.createTagsInput($('[component="chat/messages"] .users-tag-input'), ajaxify.data); | ||||||
|  |  | ||||||
| 		if (env === 'md' || env === 'lg') { | 		if (env === 'md' || env === 'lg') { | ||||||
| 			Chats.resizeMainWindow(); | 			Chats.resizeMainWindow(); | ||||||
| @@ -185,16 +185,14 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', | |||||||
| 		}); | 		}); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	Chats.createTagsInput = function(roomId, users) { | 	Chats.createTagsInput = function(tagEl, data) { | ||||||
| 		var tagEl = $('.users-tag-input'); |  | ||||||
|  |  | ||||||
| 		tagEl.tagsinput({ | 		tagEl.tagsinput({ | ||||||
| 			confirmKeys: [13, 44], | 			confirmKeys: [13, 44], | ||||||
| 			trimValue: true | 			trimValue: true | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		if (users && users.length) { | 		if (data.users && data.users.length) { | ||||||
| 			users.forEach(function(user) { | 			data.users.forEach(function(user) { | ||||||
| 				tagEl.tagsinput('add', user.username); | 				tagEl.tagsinput('add', user.username); | ||||||
| 			}); | 			}); | ||||||
| 		} | 		} | ||||||
| @@ -203,7 +201,7 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', | |||||||
| 			if (event.item === app.user.username) { | 			if (event.item === app.user.username) { | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 			socket.emit('modules.chats.addUserToRoom', {roomId: roomId, username: event.item}, function(err) { | 			socket.emit('modules.chats.addUserToRoom', {roomId: data.roomId, username: event.item}, function(err) { | ||||||
| 				if (err && err.message === '[[error:no-user]]') { | 				if (err && err.message === '[[error:no-user]]') { | ||||||
| 					tagEl.tagsinput('remove', event.item); | 					tagEl.tagsinput('remove', event.item); | ||||||
| 				} | 				} | ||||||
| @@ -211,11 +209,11 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', | |||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		tagEl.on('beforeItemRemove', function(event) { | 		tagEl.on('beforeItemRemove', function(event) { | ||||||
| 			event.cancel = !ajaxify.data.owner; | 			event.cancel = !data.owner; | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		tagEl.on('itemRemoved', function(event) { | 		tagEl.on('itemRemoved', function(event) { | ||||||
| 			socket.emit('modules.chats.removeUserFromRoom', {roomId: roomId, username: event.item}); | 			socket.emit('modules.chats.removeUserFromRoom', {roomId: data.roomId, username: event.item}); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		var input = $('.users-tag-container').find('.bootstrap-tagsinput input'); | 		var input = $('.users-tag-container').find('.bootstrap-tagsinput input'); | ||||||
|   | |||||||
| @@ -29,14 +29,14 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra | |||||||
|  |  | ||||||
| 				Chats.appendChatMessage(modal.find('.chat-content'), data.message); | 				Chats.appendChatMessage(modal.find('.chat-content'), data.message); | ||||||
|  |  | ||||||
| 				if (modal.is(":visible")) { | 				if (modal.is(':visible')) { | ||||||
| 					taskbar.updateActive(modal.attr('UUID')); | 					taskbar.updateActive(modal.attr('UUID')); | ||||||
| 					Chats.scrollToBottom(modal.find('.chat-content')); | 					Chats.scrollToBottom(modal.find('.chat-content')); | ||||||
| 				} else { | 				} else { | ||||||
| 					module.toggleNew(modal.attr('UUID'), true, true); | 					module.toggleNew(modal.attr('UUID'), true, true); | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 				if (!isSelf && (!modal.is(":visible") || !app.isFocused)) { | 				if (!isSelf && (!modal.is(':visible') || !app.isFocused)) { | ||||||
| 					app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]'); | 					app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]'); | ||||||
| 					sounds.play('chat-incoming'); | 					sounds.play('chat-incoming'); | ||||||
|  |  | ||||||
| @@ -46,15 +46,25 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra | |||||||
| 					}); | 					}); | ||||||
| 				} | 				} | ||||||
| 			} else { | 			} else { | ||||||
| 				module.createModal({ | 				socket.emit('modules.chats.loadRoom', {roomId: data.roomId}, function(err, roomData) { | ||||||
| 					roomId: data.roomId, | 					if (err) { | ||||||
| 					silent: true | 						return app.alertError(err.message); | ||||||
| 				}, function(modal) { |  | ||||||
| 					module.toggleNew(modal.attr('UUID'), true, true); |  | ||||||
| 					if (!isSelf) { |  | ||||||
| 						app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]'); |  | ||||||
| 						sounds.play('chat-incoming'); |  | ||||||
| 					} | 					} | ||||||
|  | 					roomData.users = roomData.users.filter(function(user) { | ||||||
|  | 						return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10); | ||||||
|  | 					}); | ||||||
|  | 					module.createModal({ | ||||||
|  | 						roomId: data.roomId, | ||||||
|  | 						users: roomData.users, | ||||||
|  | 						owner: roomData.owner, | ||||||
|  | 						silent: true | ||||||
|  | 					}, function(modal) { | ||||||
|  | 						module.toggleNew(modal.attr('UUID'), true, true); | ||||||
|  | 						if (!isSelf) { | ||||||
|  | 							app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]'); | ||||||
|  | 							sounds.play('chat-incoming'); | ||||||
|  | 						} | ||||||
|  | 					}); | ||||||
| 				}); | 				}); | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
| @@ -267,7 +277,7 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra | |||||||
|  |  | ||||||
| 				Chats.addSendHandlers(chatModal.attr('roomId'), chatModal.find('#chat-message-input'), chatModal.find('#chat-message-send-btn')); | 				Chats.addSendHandlers(chatModal.attr('roomId'), chatModal.find('#chat-message-input'), chatModal.find('#chat-message-send-btn')); | ||||||
|  |  | ||||||
| 				Chats.createTagsInput(data.roomId, data.users); | 				Chats.createTagsInput(chatModal.find('.users-tag-input'), data); | ||||||
|  |  | ||||||
| 				Chats.loadChatSince(chatModal.attr('roomId'), chatModal.find('.chat-content'), 'recent'); | 				Chats.loadChatSince(chatModal.attr('roomId'), chatModal.find('.chat-content'), 'recent'); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -59,7 +59,7 @@ module.exports = function(Messaging) { | |||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			uids = uids.filter(function(uid, index) { | 			uids = uids.filter(function(uid, index) { | ||||||
| 				return isOnline[index] && parseInt(fromuid, 10) !== parseInt(uid, 10); | 				return !isOnline[index] && parseInt(fromuid, 10) !== parseInt(uid, 10); | ||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
| 			if (!uids.length) { | 			if (!uids.length) { | ||||||
|   | |||||||
| @@ -101,20 +101,27 @@ SocketModules.chats.send = function(socket, data, callback) { | |||||||
| 	}); | 	}); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| SocketModules.chats.getUsersInRoom = function(socket, data, callback) { | SocketModules.chats.loadRoom = function(socket, data, callback) { | ||||||
| 	if (!data || !data.roomId) { | 	if (!data || !data.roomId) { | ||||||
| 		return callback(new Error('[[error:invalid-data]]')); | 		return callback(new Error('[[error:invalid-data]]')); | ||||||
| 	} | 	} | ||||||
|  | 	var isOwner = false; | ||||||
| 	async.waterfall([ | 	async.waterfall([ | ||||||
| 		function (next) { | 		function (next) { | ||||||
| 			Messaging.isUserInRoom(socket.uid, data.roomId, next); | 			async.parallel({ | ||||||
|  | 				inRoom: async.apply(Messaging.isUserInRoom, socket.uid, data.roomId), | ||||||
|  | 				isOwner: async.apply(Messaging.isRoomOwner, socket.uid, data.roomId) | ||||||
|  | 			}, next); | ||||||
| 		}, | 		}, | ||||||
| 		function (inRoom, next) { | 		function (results, next) { | ||||||
| 			if (!inRoom) { | 			if (!results.inRoom) { | ||||||
| 				return next(new Error('[[error:not-allowerd]]')); | 				return next(new Error('[[error:not-allowerd]]')); | ||||||
| 			} | 			} | ||||||
|  | 			isOwner = results.isOwner; | ||||||
| 			Messaging.getUsersInRoom(data.roomId, 0, -1, next); | 			Messaging.getUsersInRoom(data.roomId, 0, -1, next); | ||||||
|  | 		}, | ||||||
|  | 		function (users, next) { | ||||||
|  | 			next(null, {users: users, owner: isOwner}); | ||||||
| 		} | 		} | ||||||
| 	], callback); | 	], callback); | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user