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