mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-15 18:26:15 +01:00
the meat of #5862, making chat loading not require an ajaxification
This commit is contained in:
@@ -23,6 +23,8 @@ define('forum/chats', [
|
||||
Chats.addGlobalEventListeners();
|
||||
}
|
||||
|
||||
recentChats.init();
|
||||
|
||||
Chats.addEventListeners();
|
||||
Chats.createTagsInput($('[component="chat/messages"] .users-tag-input'), ajaxify.data);
|
||||
Chats.createAutoComplete($('[component="chat/input"]'));
|
||||
@@ -48,20 +50,6 @@ define('forum/chats', [
|
||||
};
|
||||
|
||||
Chats.addEventListeners = function () {
|
||||
$('[component="chat/recent"]').on('click', '[component="chat/leave"]', function () {
|
||||
Chats.leave($(this).parents('[data-roomid]'));
|
||||
return false;
|
||||
});
|
||||
|
||||
$('[component="chat/recent"]').on('click', '[component="chat/recent/room"]', function () {
|
||||
var env = utils.findBootstrapEnvironment();
|
||||
if (env === 'xs' || env === 'sm') {
|
||||
app.openChat($(this).attr('data-roomid'));
|
||||
} else {
|
||||
Chats.switchChat($(this).attr('data-roomid'));
|
||||
}
|
||||
});
|
||||
|
||||
Chats.addSendHandlers(ajaxify.data.roomId, $('.chat-input'), $('.expanded-chat button[data-action="send"]'));
|
||||
|
||||
$('[data-action="pop-out"]').on('click', function () {
|
||||
@@ -84,8 +72,6 @@ define('forum/chats', [
|
||||
|
||||
Chats.addEditDeleteHandler(components.get('chat/messages'), ajaxify.data.roomId);
|
||||
|
||||
recentChats.init();
|
||||
|
||||
Chats.addRenameHandler(ajaxify.data.roomId, $('[component="chat/room/name"]'));
|
||||
Chats.addScrollHandler(ajaxify.data.roomId, ajaxify.data.uid, $('.chat-content'));
|
||||
Chats.addCharactersLeftHandler(components.get('chat/input'));
|
||||
@@ -331,7 +317,17 @@ define('forum/chats', [
|
||||
if (response.ok) {
|
||||
response.json().then(function(payload) {
|
||||
app.parseAndTranslate('partials/chats/message-window', payload, function (html) {
|
||||
console.log(html);
|
||||
components.get('chat/main-wrapper').html(html);
|
||||
Chats.resizeMainWindow();
|
||||
ajaxify.data = payload;
|
||||
Chats.setActive();
|
||||
Chats.addEventListeners();
|
||||
|
||||
if (history.pushState) {
|
||||
history.pushState({
|
||||
url: 'user/' + payload.userslug + '/chats/' + payload.roomId,
|
||||
}, null, window.location.protocol + '//' + window.location.host + config.relative_path + '/user/' + payload.userslug + '/chats/' + payload.roomId);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -5,6 +5,21 @@ define('forum/chats/recent', function () {
|
||||
var recent = {};
|
||||
|
||||
recent.init = function () {
|
||||
require(['forum/chats'], function (Chats) {
|
||||
$('[component="chat/recent"]').on('click', '[component="chat/leave"]', function () {
|
||||
Chats.leave($(this).parents('[data-roomid]'));
|
||||
return false;
|
||||
});
|
||||
|
||||
$('[component="chat/recent"]').on('click', '[component="chat/recent/room"]', function () {
|
||||
var env = utils.findBootstrapEnvironment();
|
||||
if (env === 'xs' || env === 'sm') {
|
||||
app.openChat($(this).attr('data-roomid'));
|
||||
} else {
|
||||
Chats.switchChat($(this).attr('data-roomid'));
|
||||
}
|
||||
});
|
||||
|
||||
$('[component="chat/recent"]').on('scroll', function () {
|
||||
var $this = $(this);
|
||||
var bottom = ($this[0].scrollHeight - $this.height()) * 0.9;
|
||||
@@ -12,6 +27,7 @@ define('forum/chats/recent', function () {
|
||||
loadMoreRecentChats();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function loadMoreRecentChats() {
|
||||
|
||||
@@ -45,7 +45,6 @@ chatsController.get = function (req, res, callback) {
|
||||
nextStart: recentChats.nextStart,
|
||||
allowed: true,
|
||||
title: '[[pages:chats]]',
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{ text: username, url: '/user/' + req.params.userslug }, { text: '[[pages:chats]]' }]),
|
||||
});
|
||||
}
|
||||
messaging.isUserInRoom(req.uid, req.params.roomid, next);
|
||||
@@ -86,11 +85,6 @@ chatsController.get = function (req, res, callback) {
|
||||
room.nextStart = recentChats.nextStart;
|
||||
room.usernames = messaging.generateUsernames(room.users, req.uid);
|
||||
room.title = room.roomName || room.usernames || '[[pages:chats]]';
|
||||
room.breadcrumbs = helpers.buildBreadcrumbs([
|
||||
{ text: username, url: '/user/' + req.params.userslug },
|
||||
{ text: '[[pages:chats]]', url: '/user/' + req.params.userslug + '/chats' },
|
||||
{ text: room.roomName || room.usernames || '[[pages:chats]]' },
|
||||
]);
|
||||
room.maximumUsersInChatRoom = parseInt(meta.config.maximumUsersInChatRoom, 10) || 0;
|
||||
room.maximumChatMessageLength = parseInt(meta.config.maximumChatMessageLength, 10) || 1000;
|
||||
room.showUserInput = !room.maximumUsersInChatRoom || room.maximumUsersInChatRoom > 2;
|
||||
|
||||
Reference in New Issue
Block a user