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() {
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');
}

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

@ -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();

@ -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,

@ -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();

@ -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
});
});

Loading…
Cancel
Save