mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 02:36:16 +01:00
Updates to allow better chats integration
- Removed unused .createTagsInput method - Firing action:chat.loaded client-side hook in all cases of chat now - New chat window (modal) - New chat page load - Chat switch event
This commit is contained in:
@@ -27,7 +27,6 @@ define('forum/chats', [
|
||||
recentChats.init();
|
||||
|
||||
Chats.addEventListeners();
|
||||
Chats.createTagsInput($('[component="chat/messages"] .users-tag-input'), ajaxify.data);
|
||||
Chats.createAutoComplete($('[component="chat/input"]'));
|
||||
Chats.resizeMainWindow();
|
||||
|
||||
@@ -35,9 +34,12 @@ define('forum/chats', [
|
||||
Chats.addHotkeys();
|
||||
}
|
||||
|
||||
messages.scrollToBottom($('.expanded-chat ul.chat-content'));
|
||||
$(document).ready(function () {
|
||||
$(window).trigger('action:chat.loaded', $('.chats-full'));
|
||||
});
|
||||
|
||||
Chats.initialised = true;
|
||||
messages.scrollToBottom($('.expanded-chat ul.chat-content'));
|
||||
|
||||
search.init();
|
||||
|
||||
@@ -331,75 +333,6 @@ define('forum/chats', [
|
||||
}
|
||||
};
|
||||
|
||||
Chats.createTagsInput = function (tagEl, data) {
|
||||
tagEl.tagsinput({
|
||||
confirmKeys: [13, 44],
|
||||
trimValue: true,
|
||||
});
|
||||
|
||||
if (data.users && data.users.length) {
|
||||
data.users.forEach(function (user) {
|
||||
tagEl.tagsinput('add', $('<div/>').html(user.username).text());
|
||||
});
|
||||
}
|
||||
|
||||
tagEl.on('beforeItemAdd', function (event) {
|
||||
event.cancel = event.item === app.user.username;
|
||||
});
|
||||
|
||||
tagEl.on('itemAdded', function (event) {
|
||||
if (event.item === app.user.username) {
|
||||
return;
|
||||
}
|
||||
socket.emit('modules.chats.addUserToRoom', {
|
||||
roomId: data.roomId,
|
||||
username: event.item,
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
app.alertError(err.message);
|
||||
tagEl.tagsinput('remove', event.item, {
|
||||
nouser: true,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
tagEl.on('beforeItemRemove', function (event) {
|
||||
if (event.options && event.options.nouser) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.cancel = !data.isOwner || tagEl.tagsinput('items').length < 2;
|
||||
if (!data.owner) {
|
||||
return app.alertError('[[error:not-allowed]]');
|
||||
}
|
||||
|
||||
if (tagEl.tagsinput('items').length < 2) {
|
||||
return app.alertError('[[error:cant-remove-last-user]]');
|
||||
}
|
||||
});
|
||||
|
||||
tagEl.on('itemRemoved', function (event) {
|
||||
if (event.options && event.options.nouser) {
|
||||
return;
|
||||
}
|
||||
socket.emit('modules.chats.removeUserFromRoom', {
|
||||
roomId: data.roomId,
|
||||
username: event.item,
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var input = $('.users-tag-container').find('.bootstrap-tagsinput input');
|
||||
|
||||
require(['autocomplete'], function (autocomplete) {
|
||||
autocomplete.user(input);
|
||||
});
|
||||
};
|
||||
|
||||
Chats.leave = function (el) {
|
||||
var roomId = el.attr('data-roomid');
|
||||
socket.emit('modules.chats.leave', roomId, function (err) {
|
||||
@@ -434,6 +367,7 @@ define('forum/chats', [
|
||||
ajaxify.data = payload;
|
||||
Chats.setActive();
|
||||
Chats.addEventListeners();
|
||||
$(window).trigger('action:chat.loaded', $('.chats-full'));
|
||||
messages.scrollToBottom($('.expanded-chat ul.chat-content'));
|
||||
if (history.pushState) {
|
||||
history.pushState({
|
||||
|
||||
@@ -254,7 +254,6 @@ define('chat', [
|
||||
Chats.addLeaveHandler(chatModal.attr('data-roomid'), chatModal.find('[data-action="leave"]'));
|
||||
Chats.addSendHandlers(chatModal.attr('data-roomid'), chatModal.find('.chat-input'), chatModal.find('[data-action="send"]'));
|
||||
|
||||
Chats.createTagsInput(chatModal.find('.users-tag-input'), data);
|
||||
Chats.createAutoComplete(chatModal.find('[component="chat/input"]'));
|
||||
|
||||
Chats.addScrollHandler(chatModal.attr('data-roomid'), data.uid, chatModal.find('.chat-content'));
|
||||
|
||||
Reference in New Issue
Block a user