mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 15:05:46 +01:00
ability to add/remove users from chat rooms, tagsinput
This commit is contained in:
@@ -18,6 +18,7 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
|
||||
}
|
||||
|
||||
Chats.addEventListeners();
|
||||
Chats.createTagsInput(ajaxify.data.roomId, ajaxify.data.users);
|
||||
|
||||
if (env === 'md' || env === 'lg') {
|
||||
Chats.resizeMainWindow();
|
||||
@@ -191,6 +192,42 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
|
||||
});
|
||||
};
|
||||
|
||||
Chats.createTagsInput = function(roomId, users) {
|
||||
var tagEl = $('.users-tag-input');
|
||||
|
||||
tagEl.tagsinput({
|
||||
confirmKeys: [13, 44],
|
||||
trimValue: true
|
||||
});
|
||||
|
||||
if (users && users.length) {
|
||||
users.forEach(function(user) {
|
||||
tagEl.tagsinput('add', user.username);
|
||||
});
|
||||
}
|
||||
|
||||
tagEl.on('itemAdded', function(event) {
|
||||
if (event.item === app.user.username) {
|
||||
return;
|
||||
}
|
||||
socket.emit('modules.chats.addUserToRoom', {roomId: roomId, username: event.item}, function(err) {
|
||||
if (err && err.message === '[[error:no-user]]') {
|
||||
tagEl.tagsinput('remove', event.item);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
tagEl.on('itemRemoved', function(event) {
|
||||
socket.emit('modules.chats.removeUserFromRoom', {roomId: roomId, username: event.item});
|
||||
});
|
||||
|
||||
var input = $('.users-tag-container').find('.bootstrap-tagsinput input');
|
||||
|
||||
require(['autocomplete'], function(autocomplete) {
|
||||
autocomplete.user(input);
|
||||
});
|
||||
};
|
||||
|
||||
Chats.switchChat = function(roomid) {
|
||||
ajaxify.go('chats/' + roomid);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user