Node.js based forum software built for the modern web
closes #1139
barisusakli04488a9a149b
diff --git a/public/language/en_GB/modules.json b/public/language/en_GB/modules.jsonindex 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 <span id=\"chat-with-name\"></span>","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 filediff --git a/public/src/modules/chat.js b/public/src/modules/chat.jsindex 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:'<i class="fa fa-comment"></i> ' + 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<messages.length; ++i) {@@ -216,12 +245,21 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {}function addSendHandler(chatModal) {- chatModal.find('#chat-message-input').off('keypress').on('keypress', function(e) {+ var input = chatModal.find('#chat-message-input');+ input.off('keypress').on('keypress', function(e) {if(e.which === 13) {sendMessage(chatModal);}});+ input.off('keyup').on('keyup', function() {+ if ($(this).val()) {+ socket.emit('modules.chats.userStartTyping', {touid:chatModal.touid, fromUid: app.uid});+ } else {+ notifyStopTyping(chatModal.touid);+ }+ });+chatModal.find('#chat-message-send-btn').off('click').on('click', function(e){sendMessage(chatModal);return false;@@ -230,11 +268,12 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {function sendMessage(chatModal) {var msg = S(chatModal.find('#chat-message-input').val()).stripTags().s;- if(msg.length) {+ if (msg.length) {msg = msg +'\n';socket.emit('modules.chats.send', {touid:chatModal.touid, message:msg});chatModal.find('#chat-message-input').val('');sounds.play('chat-outgoing');+ notifyStopTyping(chatModal.touid);}}diff --git a/public/src/modules/sounds.js b/public/src/modules/sounds.jsindex f12c86ed49..c4c8262abe 100644--- a/public/src/modules/sounds.js+++ b/public/src/modules/sounds.js@@ -42,7 +42,9 @@ define(['buzz'], function(buzz) {return callback();}- loadedSounds[fileName] = new buzz.sound(files[fileName]);+ if (files && files[fileName]) {+ loadedSounds[fileName] = new buzz.sound(files[fileName]);+ }callback();}diff --git a/src/socket.io/modules.js b/src/socket.io/modules.jsindex 384343dcd6..401d09a8e9 100644--- a/src/socket.io/modules.js+++ b/src/socket.io/modules.js@@ -208,6 +208,23 @@ function sendChatNotification(fromuid, touid, username) {}}+SocketModules.chats.userStartTyping = function(socket, data, callback) {+ sendTypingNotification('event:chats.userStartTyping', socket, data, callback);+};++SocketModules.chats.userStopTyping = function(socket, data, callback) {+ sendTypingNotification('event:chats.userStopTyping', socket, data, callback);+};++function sendTypingNotification(event, socket, data, callback) {+ if (!socket.uid || !data) {+ return;+ }+ server.getUserSockets(data.touid).forEach(function(socket) {+ socket.emit(event, data.fromUid);+ });+}+SocketModules.chats.list = function(socket, data, callback) {Messaging.getRecentChats(socket.uid, callback);};