From 04488a9a149b57feeebd7bd61e1b720190fcc066 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 15 Apr 2014 12:48:28 -0400 Subject: [PATCH] closes #1139 --- public/language/en_GB/modules.json | 3 +- public/src/modules/chat.js | 57 +++++++++++++++++++++++++----- public/src/modules/sounds.js | 4 ++- src/socket.io/modules.js | 17 +++++++++ 4 files changed, 70 insertions(+), 11 deletions(-) diff --git a/public/language/en_GB/modules.json b/public/language/en_GB/modules.json index 1ed406ce4a..8616bf0298 100644 --- a/public/language/en_GB/modules.json +++ b/public/language/en_GB/modules.json @@ -2,5 +2,6 @@ "chat.chatting_with": "Chat with ", "chat.placeholder": "type chat message here, press enter to send", "chat.send": "Send", - "chat.no_active": "You have no active chats." + "chat.no_active": "You have no active chats.", + "chat.user_typing": "%1 is typing ..." } \ No newline at end of file diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js index a7d6f91073..e7a9ea371a 100644 --- a/public/src/modules/chat.js +++ b/public/src/modules/chat.js @@ -84,6 +84,20 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) { sounds.play('chat-incoming'); } }); + + socket.on('event:chats.userStartTyping', function(withUid) { + var modal = module.getModal(withUid); + var chatContent = modal.find('#chat-content'); + modal.find('.user-typing') + .removeClass('hide') + .appendTo(chatContent); + scrollToBottom(chatContent); + }); + + socket.on('event:chats.userStopTyping', function(withUid) { + var modal = module.getModal(withUid); + modal.find('.user-typing').addClass('hide'); + }); }; module.bringModalToTop = function(chatModal) { @@ -152,12 +166,8 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) { chatModal.find('#chat-with-name').html(username); - chatModal.find('#chat-close-btn').on('click', function(e) { - clearInterval(chatModal.intervalId); - chatModal.intervalId = 0; - chatModal.remove(); - chatModal.data('modal', null); - taskbar.discard('chat', uuid); + chatModal.find('#chat-close-btn').on('click', function() { + module.close(chatModal); }); chatModal.on('click', function(e) { @@ -170,6 +180,11 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) { checkOnlineStatus(chatModal); }); + translator.translate('[[modules:chat.user_typing, ' + username + ']]', function(translated) { + chatModal.find('.user-typing').text(translated); + }); + + taskbar.push('chat', chatModal.attr('UUID'), { title:' ' + username, state: '' @@ -180,6 +195,15 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) { }); }; + module.close = function(chatModal) { + clearInterval(chatModal.intervalId); + chatModal.intervalId = 0; + chatModal.remove(); + chatModal.data('modal', null); + taskbar.discard('chat', chatModal.attr('UUID')); + notifyStopTyping(chatModal.touid); + }; + module.center = function(chatModal) { chatModal.css("left", Math.max(0, (($(window).width() - $(chatModal).outerWidth()) / 2) + $(window).scrollLeft()) + "px"); chatModal.css("top", "0px"); @@ -199,13 +223,18 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) { }; module.minimize = function(uuid) { - var chatModal = $('div[UUID="'+uuid+'"]'); + var chatModal = $('div[UUID="' + uuid + '"]'); chatModal.addClass('hide'); taskbar.minimize('chat', uuid); clearInterval(chatModal.intervalId); chatModal.intervalId = 0; + notifyStopTyping(chatModal.touid); }; + function notifyStopTyping(touid) { + socket.emit('modules.chats.userStopTyping', {touid:touid, fromUid: app.uid}); + } + function getChatMessages(chatModal, callback) { socket.emit('modules.chats.get', {touid:chatModal.touid}, function(err, messages) { for(var i = 0; i