the meat of #5862, making chat loading not require an ajaxification

v1.18.x
Julian Lam 8 years ago
parent 902b823f4d
commit d9ad26c7c5

@ -22,6 +22,8 @@ define('forum/chats', [
Chats.addSocketListeners();
Chats.addGlobalEventListeners();
}
recentChats.init();
Chats.addEventListeners();
Chats.createTagsInput($('[component="chat/messages"] .users-tag-input'), ajaxify.data);
@ -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,12 +5,28 @@ define('forum/chats/recent', function () {
var recent = {};
recent.init = function () {
$('[component="chat/recent"]').on('scroll', function () {
var $this = $(this);
var bottom = ($this[0].scrollHeight - $this.height()) * 0.9;
if ($this.scrollTop() > bottom) {
loadMoreRecentChats();
}
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;
if ($this.scrollTop() > bottom) {
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;

Loading…
Cancel
Save