mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
closes #1139
This commit is contained in:
@@ -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 ..."
|
||||
}
|
||||
@@ -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");
|
||||
@@ -204,8 +228,13 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
|
||||
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;
|
||||
@@ -235,6 +273,7 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
|
||||
socket.emit('modules.chats.send', {touid:chatModal.touid, message:msg});
|
||||
chatModal.find('#chat-message-input').val('');
|
||||
sounds.play('chat-outgoing');
|
||||
notifyStopTyping(chatModal.touid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,9 @@ define(['buzz'], function(buzz) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
if (files && files[fileName]) {
|
||||
loadedSounds[fileName] = new buzz.sound(files[fileName]);
|
||||
}
|
||||
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) {
|
||||
Messaging.getRecentChats(socket.uid, callback);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user