Node.js based forum software built for the modern web
marathon bugfixing with @barisusakli re: #1788
Julian Lam71916f0691ef
diff --git a/public/src/forum/chats.js b/public/src/forum/chats.jsindex 94034efe70..9449f50374 100644--- a/public/src/forum/chats.js+++ b/public/src/forum/chats.js@@ -63,10 +63,10 @@ define('forum/chats', ['string', 'sounds'], function(S, sounds) {};Chats.addSocketListeners = function() {- var typingNotifEl = $('.user-typing'),- containerEl = $('.expanded-chat ul');-socket.on('event:chats.receive', function(data) {+ var typingNotifEl = $('.user-typing'),+ containerEl = $('.expanded-chat ul');+if (Chats.isCurrentChat(data.withUid)) {Chats.parseMessage(data.message, function(html) {var newMessage = $(html);@@ -82,6 +82,8 @@ define('forum/chats', ['string', 'sounds'], function(S, sounds) {});socket.on('event:chats.userStartTyping', function(withUid) {+ var typingNotifEl = $('.user-typing');+if (Chats.isCurrentChat(withUid)) {typingNotifEl.removeClass('hide');}@@ -90,6 +92,8 @@ define('forum/chats', ['string', 'sounds'], function(S, sounds) {});socket.on('event:chats.userStopTyping', function(withUid) {+ var typingNotifEl = $('.user-typing');+if (Chats.isCurrentChat(withUid)) {typingNotifEl.addClass('hide');}diff --git a/public/src/helpers.js b/public/src/helpers.jsindex 7e8bd64280..1b0b05cb81 100644--- a/public/src/helpers.js+++ b/public/src/helpers.js@@ -17,10 +17,6 @@return '<meta ' + name + property + content + ' />';};----if ('undefined' !== typeof window) {$(document).ready(module.exports);}diff --git a/public/src/modules/chat.js b/public/src/modules/chat.jsindex 7362a9642c..717320cf48 100644--- a/public/src/modules/chat.js+++ b/public/src/modules/chat.js@@ -56,6 +56,10 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,});socket.on('event:chats.receive', function(data) {+ if (ajaxify.currentPage.slice(0, 6) === 'chats/') {+ // User is on the chats page, so do nothing (src/forum/chats.js will handle it)+ return;+ }var username = data.message.fromUser.username;var isSelf = parseInt(data.message.fromUser.uid, 10) === parseInt(app.uid, 10);@@ -78,19 +82,17 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,if (!isSelf && (!modal.is(":visible") || !app.isFocused)) {app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]');+ sounds.play('chat-incoming');}} else {module.createModal(username, data.withUid, function(modal) {module.toggleNew(modal.attr('UUID'), true);if (!isSelf) {app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]');+ sounds.play('chat-incoming');}});}-- if (!isSelf) {- sounds.play('chat-incoming');- }});socket.on('event:chats.userStartTyping', function(withUid) {@@ -101,7 +103,7 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,}var atBottom = chatContent[0].scrollHeight - chatContent.scrollTop() === chatContent.innerHeight();- modal.find('.user-typing').removeClass('hide').appendTo(chatContent);+ modal.find('.user-typing').removeClass('hide');if (atBottom) {Chats.scrollToBottom(chatContent);}@@ -263,7 +265,6 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,function getChatMessages(chatModal, callback) {socket.emit('modules.chats.get', {touid:chatModal.touid}, function(err, messages) {- console.log(messages);module.appendChatMessage(chatModal, messages, callback);});}@@ -291,13 +292,14 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,}module.appendChatMessage = function(chatModal, data, done) {- var chatContent = chatModal.find('#chat-content');+ var chatContent = chatModal.find('#chat-content'),+ typingNotif = chatModal.find('.user-typing');Chats.parseMessage(data, function(html) {var message = $(html);message.find('img:not(".chat-user-image")').addClass('img-responsive');message.find('span.timeago').timeago();- chatContent.append(message);+ message.insertBefore(typingNotif);Chats.scrollToBottom(chatContent);if (typeof done === 'function') done();diff --git a/src/controllers/accounts.js b/src/controllers/accounts.jsindex eec71b2bd2..885e6f2767 100644--- a/src/controllers/accounts.js+++ b/src/controllers/accounts.js@@ -502,7 +502,9 @@ accountsController.getChats = function(req, res, next) {}// Limit returned chats- chats.length = 20;+ if (chats.length > 20) {+ chats.length = 20;+ }res.render('chats', {meta: res.locals.chatData,diff --git a/src/middleware/middleware.js b/src/middleware/middleware.jsindex 94dfead43e..03d2b685d9 100644--- a/src/middleware/middleware.js+++ b/src/middleware/middleware.js@@ -26,7 +26,7 @@ middleware.authenticate = function(req, res, next) {if (res.locals.isAPI) {return res.json(403, 'not-allowed');} else {- return res.redirect('403');+ return res.redirect(nconf.get('url') + '/403');}} else {next();diff --git a/src/socket.io/modules.js b/src/socket.io/modules.jsindex 9a44ab1927..a4cab07963 100644--- a/src/socket.io/modules.js+++ b/src/socket.io/modules.js@@ -182,10 +182,13 @@ SocketModules.chats.send = function(socket, data, callback) {sendChatNotification(socket.uid, touid, message.fromUser.username, message);+ // After-the-fact fixing of the "self" property for the message that goes to the receipient+ var recipMessage = JSON.parse(JSON.stringify(message));+ recipMessage.self = 0;server.getUserSockets(touid).forEach(function(s) {s.emit('event:chats.receive', {withUid: socket.uid,- message: message+ message: recipMessage});});