From 0a485a7ff6012fa2a3c90f6ec1eee4cd72f0b34a Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Mon, 26 Aug 2013 13:18:20 -0400 Subject: [PATCH] closes #109 --- public/src/forum/topic.js | 6 ++- public/src/modules/chat.js | 18 +++++++-- src/messaging.js | 77 ++++++++++++++++++++++++++++++++++++++ src/websockets.js | 19 +++++++++- 4 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 src/messaging.js diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index c2a0a30479..2edf4659e6 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -287,12 +287,14 @@ var username = $(this).parents('li').attr('data-username'); var touid = $(this).parents('li').attr('data-uid'); - require(['chat'], function(chat){ + if(username === app.username || !app.username) + return; + + require(['chat'], function(chat) { var chatModal = chat.createModalIfDoesntExist(username, touid); chatModal.show(); chat.bringModalToTop(chatModal); }); - }); ajaxify.register_events([ diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js index 7c866fcce4..3a5decb4bc 100644 --- a/public/src/modules/chat.js +++ b/public/src/modules/chat.js @@ -1,8 +1,7 @@ define(['taskbar'], function(taskbar) { - + var module = {}; - module.bringModalToTop = function(chatModal) { var topZ = 0; $('.modal').each(function() { @@ -11,7 +10,7 @@ define(['taskbar'], function(taskbar) { topZ = thisZ; } }); - chatModal.css('zIndex', topZ+1); + chatModal.css('zIndex', topZ + 1); } module.createModalIfDoesntExist = function(username, touid) { @@ -39,7 +38,9 @@ define(['taskbar'], function(taskbar) { module.bringModalToTop(chatModal); }); - addSendHandler(chatModal, touid); + addSendHandler(chatModal, touid); + + getChatMessages(chatModal, touid); } taskbar.push('chat', chatModal.attr('UUID'), {title:'chat with '+username}); @@ -58,6 +59,15 @@ define(['taskbar'], function(taskbar) { taskbar.minimize('chat', uuid); } + function getChatMessages(chatModal, touid) { + socket.emit('getChatMessages', {touid:touid}, function(messages) { + console.log(messages); + for(var i = 0; i