marathon bugfixing with @barisusakli re: #1788

v1.18.x
Julian Lam 11 years ago
parent d9cdd2f165
commit 71916f0691

@ -63,10 +63,10 @@ define('forum/chats', ['string', 'sounds'], function(S, sounds) {
}; };
Chats.addSocketListeners = function() { Chats.addSocketListeners = function() {
socket.on('event:chats.receive', function(data) {
var typingNotifEl = $('.user-typing'), var typingNotifEl = $('.user-typing'),
containerEl = $('.expanded-chat ul'); containerEl = $('.expanded-chat ul');
socket.on('event:chats.receive', function(data) {
if (Chats.isCurrentChat(data.withUid)) { if (Chats.isCurrentChat(data.withUid)) {
Chats.parseMessage(data.message, function(html) { Chats.parseMessage(data.message, function(html) {
var newMessage = $(html); var newMessage = $(html);
@ -82,6 +82,8 @@ define('forum/chats', ['string', 'sounds'], function(S, sounds) {
}); });
socket.on('event:chats.userStartTyping', function(withUid) { socket.on('event:chats.userStartTyping', function(withUid) {
var typingNotifEl = $('.user-typing');
if (Chats.isCurrentChat(withUid)) { if (Chats.isCurrentChat(withUid)) {
typingNotifEl.removeClass('hide'); typingNotifEl.removeClass('hide');
} }
@ -90,6 +92,8 @@ define('forum/chats', ['string', 'sounds'], function(S, sounds) {
}); });
socket.on('event:chats.userStopTyping', function(withUid) { socket.on('event:chats.userStopTyping', function(withUid) {
var typingNotifEl = $('.user-typing');
if (Chats.isCurrentChat(withUid)) { if (Chats.isCurrentChat(withUid)) {
typingNotifEl.addClass('hide'); typingNotifEl.addClass('hide');
} }

@ -17,10 +17,6 @@
return '<meta ' + name + property + content + ' />'; return '<meta ' + name + property + content + ' />';
}; };
if ('undefined' !== typeof window) { if ('undefined' !== typeof window) {
$(document).ready(module.exports); $(document).ready(module.exports);
} }

@ -56,6 +56,10 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,
}); });
socket.on('event:chats.receive', function(data) { 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 username = data.message.fromUser.username;
var isSelf = parseInt(data.message.fromUser.uid, 10) === parseInt(app.uid, 10); 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)) { if (!isSelf && (!modal.is(":visible") || !app.isFocused)) {
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]'); app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]');
sounds.play('chat-incoming');
} }
} else { } else {
module.createModal(username, data.withUid, function(modal) { module.createModal(username, data.withUid, function(modal) {
module.toggleNew(modal.attr('UUID'), true); module.toggleNew(modal.attr('UUID'), true);
if (!isSelf) { if (!isSelf) {
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]'); 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) { 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(); 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) { if (atBottom) {
Chats.scrollToBottom(chatContent); Chats.scrollToBottom(chatContent);
} }
@ -263,7 +265,6 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,
function getChatMessages(chatModal, callback) { function getChatMessages(chatModal, callback) {
socket.emit('modules.chats.get', {touid:chatModal.touid}, function(err, messages) { socket.emit('modules.chats.get', {touid:chatModal.touid}, function(err, messages) {
console.log(messages);
module.appendChatMessage(chatModal, messages, callback); module.appendChatMessage(chatModal, messages, callback);
}); });
} }
@ -291,13 +292,14 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,
} }
module.appendChatMessage = function(chatModal, data, done) { 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) { Chats.parseMessage(data, function(html) {
var message = $(html); var message = $(html);
message.find('img:not(".chat-user-image")').addClass('img-responsive'); message.find('img:not(".chat-user-image")').addClass('img-responsive');
message.find('span.timeago').timeago(); message.find('span.timeago').timeago();
chatContent.append(message); message.insertBefore(typingNotif);
Chats.scrollToBottom(chatContent); Chats.scrollToBottom(chatContent);
if (typeof done === 'function') done(); if (typeof done === 'function') done();

@ -502,7 +502,9 @@ accountsController.getChats = function(req, res, next) {
} }
// Limit returned chats // Limit returned chats
if (chats.length > 20) {
chats.length = 20; chats.length = 20;
}
res.render('chats', { res.render('chats', {
meta: res.locals.chatData, meta: res.locals.chatData,

@ -26,7 +26,7 @@ middleware.authenticate = function(req, res, next) {
if (res.locals.isAPI) { if (res.locals.isAPI) {
return res.json(403, 'not-allowed'); return res.json(403, 'not-allowed');
} else { } else {
return res.redirect('403'); return res.redirect(nconf.get('url') + '/403');
} }
} else { } else {
next(); next();

@ -182,10 +182,13 @@ SocketModules.chats.send = function(socket, data, callback) {
sendChatNotification(socket.uid, touid, message.fromUser.username, message); 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) { server.getUserSockets(touid).forEach(function(s) {
s.emit('event:chats.receive', { s.emit('event:chats.receive', {
withUid: socket.uid, withUid: socket.uid,
message: message message: recipMessage
}); });
}); });

Loading…
Cancel
Save