v1.18.x
barisusakli 11 years ago
parent 549f87132d
commit 04488a9a14

@ -2,5 +2,6 @@
"chat.chatting_with": "Chat with <span id=\"chat-with-name\"></span>", "chat.chatting_with": "Chat with <span id=\"chat-with-name\"></span>",
"chat.placeholder": "type chat message here, press enter to send", "chat.placeholder": "type chat message here, press enter to send",
"chat.send": "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 ..."
} }

@ -84,6 +84,20 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
sounds.play('chat-incoming'); 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) { 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-with-name').html(username);
chatModal.find('#chat-close-btn').on('click', function(e) { chatModal.find('#chat-close-btn').on('click', function() {
clearInterval(chatModal.intervalId); module.close(chatModal);
chatModal.intervalId = 0;
chatModal.remove();
chatModal.data('modal', null);
taskbar.discard('chat', uuid);
}); });
chatModal.on('click', function(e) { chatModal.on('click', function(e) {
@ -170,6 +180,11 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
checkOnlineStatus(chatModal); checkOnlineStatus(chatModal);
}); });
translator.translate('[[modules:chat.user_typing, ' + username + ']]', function(translated) {
chatModal.find('.user-typing').text(translated);
});
taskbar.push('chat', chatModal.attr('UUID'), { taskbar.push('chat', chatModal.attr('UUID'), {
title:'<i class="fa fa-comment"></i> ' + username, title:'<i class="fa fa-comment"></i> ' + username,
state: '' 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) { module.center = function(chatModal) {
chatModal.css("left", Math.max(0, (($(window).width() - $(chatModal).outerWidth()) / 2) + $(window).scrollLeft()) + "px"); chatModal.css("left", Math.max(0, (($(window).width() - $(chatModal).outerWidth()) / 2) + $(window).scrollLeft()) + "px");
chatModal.css("top", "0px"); chatModal.css("top", "0px");
@ -199,13 +223,18 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
}; };
module.minimize = function(uuid) { module.minimize = function(uuid) {
var chatModal = $('div[UUID="'+uuid+'"]'); var chatModal = $('div[UUID="' + uuid + '"]');
chatModal.addClass('hide'); chatModal.addClass('hide');
taskbar.minimize('chat', uuid); taskbar.minimize('chat', uuid);
clearInterval(chatModal.intervalId); clearInterval(chatModal.intervalId);
chatModal.intervalId = 0; chatModal.intervalId = 0;
notifyStopTyping(chatModal.touid);
}; };
function notifyStopTyping(touid) {
socket.emit('modules.chats.userStopTyping', {touid:touid, fromUid: app.uid});
}
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) {
for(var i = 0; i<messages.length; ++i) { for(var i = 0; i<messages.length; ++i) {
@ -216,12 +245,21 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
} }
function addSendHandler(chatModal) { 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) { if(e.which === 13) {
sendMessage(chatModal); 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){ chatModal.find('#chat-message-send-btn').off('click').on('click', function(e){
sendMessage(chatModal); sendMessage(chatModal);
return false; return false;
@ -230,11 +268,12 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
function sendMessage(chatModal) { function sendMessage(chatModal) {
var msg = S(chatModal.find('#chat-message-input').val()).stripTags().s; var msg = S(chatModal.find('#chat-message-input').val()).stripTags().s;
if(msg.length) { if (msg.length) {
msg = msg +'\n'; msg = msg +'\n';
socket.emit('modules.chats.send', {touid:chatModal.touid, message:msg}); socket.emit('modules.chats.send', {touid:chatModal.touid, message:msg});
chatModal.find('#chat-message-input').val(''); chatModal.find('#chat-message-input').val('');
sounds.play('chat-outgoing'); sounds.play('chat-outgoing');
notifyStopTyping(chatModal.touid);
} }
} }

@ -42,7 +42,9 @@ define(['buzz'], function(buzz) {
return callback(); return callback();
} }
if (files && files[fileName]) {
loadedSounds[fileName] = new buzz.sound(files[fileName]); loadedSounds[fileName] = new buzz.sound(files[fileName]);
}
callback(); callback();
} }

@ -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) { SocketModules.chats.list = function(socket, data, callback) {
Messaging.getRecentChats(socket.uid, callback); Messaging.getRecentChats(socket.uid, callback);
}; };

Loading…
Cancel
Save