mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 12:36:02 +01:00
more chat refactors
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
"use strict";
|
||||
/* globals app, define, socket, templates, utils, ajaxify */
|
||||
|
||||
define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'translator'], function(components, taskbar, S, sounds, Chats, translator) {
|
||||
define('chat', [
|
||||
'components',
|
||||
'taskbar',
|
||||
'string',
|
||||
'sounds',
|
||||
'forum/chats',
|
||||
'forum/chats/messages',
|
||||
'translator'
|
||||
], function(components, taskbar, S, sounds, Chats, ChatsMessages, translator) {
|
||||
|
||||
var module = {};
|
||||
var newMessage = false;
|
||||
@@ -35,11 +43,11 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra
|
||||
if (module.modalExists(data.roomId)) {
|
||||
var modal = module.getModal(data.roomId);
|
||||
|
||||
Chats.appendChatMessage(modal.find('.chat-content'), data.message);
|
||||
ChatsMessages.appendChatMessage(modal.find('.chat-content'), data.message);
|
||||
|
||||
if (modal.is(':visible')) {
|
||||
taskbar.updateActive(modal.attr('UUID'));
|
||||
Chats.scrollToBottom(modal.find('.chat-content'));
|
||||
ChatsMessages.scrollToBottom(modal.find('.chat-content'));
|
||||
} else {
|
||||
module.toggleNew(modal.attr('UUID'), true, true);
|
||||
}
|
||||
@@ -83,7 +91,7 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra
|
||||
module.getModal(data.roomId).find('[component="chat/room/name"]').val($('<div/>').html(data.newName).text());
|
||||
});
|
||||
|
||||
Chats.onChatEdit();
|
||||
ChatsMessages.onChatMessageEdit();
|
||||
};
|
||||
|
||||
module.loadChatsDropdown = function(chatsListEl) {
|
||||
@@ -258,16 +266,7 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra
|
||||
}
|
||||
});
|
||||
|
||||
chatModal.find('[component="chat/messages"]')
|
||||
.on('click', '[data-action="edit"]', function() {
|
||||
var messageId = $(this).parents('[data-mid]').attr('data-mid');
|
||||
var inputEl = chatModal.find('[component="chat/input"]');
|
||||
Chats.prepEdit(inputEl, messageId, data.roomId);
|
||||
})
|
||||
.on('click', '[data-action="delete"]', function() {
|
||||
var messageId = $(this).parents('[data-mid]').attr('data-mid');
|
||||
Chats.delete(messageId, data.roomId);
|
||||
});
|
||||
Chats.addEditDeleteHandler(chatModal.find('[component="chat/messages"]'), data.roomId);
|
||||
|
||||
chatModal.find('[component="chat/controlsToggle"]').on('click', function() {
|
||||
var messagesEl = chatModal.find('[component="chat/messages"]');
|
||||
@@ -308,7 +307,7 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra
|
||||
chatModal.find('#chat-message-input').focus();
|
||||
};
|
||||
|
||||
module.close = function(chatModal, silent) {
|
||||
module.close = function(chatModal) {
|
||||
clearInterval(chatModal.attr('intervalId'));
|
||||
chatModal.attr('intervalId', 0);
|
||||
chatModal.remove();
|
||||
@@ -340,7 +339,7 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra
|
||||
chatModal.removeClass('hide');
|
||||
checkStatus(chatModal);
|
||||
taskbar.updateActive(uuid);
|
||||
Chats.scrollToBottom(chatModal.find('.chat-content'));
|
||||
ChatsMessages.scrollToBottom(chatModal.find('.chat-content'));
|
||||
module.bringModalToTop(chatModal);
|
||||
module.focusInput(chatModal);
|
||||
socket.emit('modules.chats.markRead', chatModal.attr('roomId'));
|
||||
@@ -367,11 +366,11 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra
|
||||
};
|
||||
|
||||
module.calculateChatListHeight = function(modalEl) {
|
||||
var totalHeight = modalEl.find('.modal-content').outerHeight() - modalEl.find('.modal-header').outerHeight(),
|
||||
padding = parseInt(modalEl.find('.modal-body').css('padding-top'), 10) + parseInt(modalEl.find('.modal-body').css('padding-bottom'), 10),
|
||||
contentMargin = parseInt(modalEl.find('.chat-content').css('margin-top'), 10) + parseInt(modalEl.find('.chat-content').css('margin-bottom'), 10),
|
||||
sinceHeight = modalEl.find('.since-bar').outerHeight(true),
|
||||
inputGroupHeight = modalEl.find('.input-group').outerHeight();
|
||||
var totalHeight = modalEl.find('.modal-content').outerHeight() - modalEl.find('.modal-header').outerHeight();
|
||||
var padding = parseInt(modalEl.find('.modal-body').css('padding-top'), 10) + parseInt(modalEl.find('.modal-body').css('padding-bottom'), 10);
|
||||
var contentMargin = parseInt(modalEl.find('.chat-content').css('margin-top'), 10) + parseInt(modalEl.find('.chat-content').css('margin-bottom'), 10);
|
||||
var sinceHeight = modalEl.find('.since-bar').outerHeight(true);
|
||||
var inputGroupHeight = modalEl.find('.input-group').outerHeight();
|
||||
|
||||
return totalHeight - padding - contentMargin - inputGroupHeight;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user