Commit 448eb73a authored by JC Brand's avatar JC Brand

Refactored keyPressed to send 'composing' chatstate

parent 8c35e9f5
...@@ -394,20 +394,23 @@ xmppchat.UI = (function (xmppUI, $, console) { ...@@ -394,20 +394,23 @@ xmppchat.UI = (function (xmppUI, $, console) {
}; };
ob.keyPressed = function (ev, textarea) { ob.keyPressed = function (ev, textarea) {
if(ev.keyCode == 13 && !ev.shiftKey) {
var $textarea = jQuery(textarea), var $textarea = jQuery(textarea),
message = $textarea.val(), jid = $textarea.attr('data-recipient'), // FIXME: bare jid
jid = $textarea.attr('data-recipient'), $chat = $textarea.parent().parent(),
form = $textarea.parent(), message,
now, notify,
minutes, composing;
time,
chat_content; if(ev.keyCode == 13) {
message = $textarea.val();
message = message.replace(/^\s+|\s+jQuery/g,""); message = message.replace(/^\s+|\s+jQuery/g,"");
$textarea.val('').focus(); $textarea.val('').focus();
if (message !== '') { if (message !== '') {
xmppchat.Messages.sendMessage(jid, message, function () { xmppchat.Messages.sendMessage(jid, message, function () {
var time,
minutes,
now,
$chat_content;
message = message.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;"); message = message.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");
list = message.match(/\b(http:\/\/www\.\S+\.\w+|www\.\S+\.\w+|http:\/\/(?=[^w]){3}\S+[\.:]\S+)[^ ]+\b/g); list = message.match(/\b(http:\/\/www\.\S+\.\w+|www\.\S+\.\w+|http:\/\/(?=[^w]){3}\S+[\.:]\S+)[^ ]+\b/g);
...@@ -420,15 +423,24 @@ xmppchat.UI = (function (xmppUI, $, console) { ...@@ -420,15 +423,24 @@ xmppchat.UI = (function (xmppUI, $, console) {
minutes = now.getMinutes().toString(); minutes = now.getMinutes().toString();
if (minutes.length==1) {minutes = '0'+minutes;} if (minutes.length==1) {minutes = '0'+minutes;}
time = now.toLocaleTimeString().substring(0,5); time = now.toLocaleTimeString().substring(0,5);
chat_content = jQuery('#'+helpers.hash(jid)+' .chat-content'); $chat_content = $chat.find('.chat-content');
chat_content.append( $chat_content.append(
'<div class="chat-message">' + '<div class="chat-message">' +
'<span class="chat-message-me">'+time+' me:&nbsp;&nbsp;</span>' + '<span class="chat-message-me">'+time+' me:&nbsp;&nbsp;</span>' +
'<span class="chat-message-content">'+message+'</span>' + '<span class="chat-message-content">'+message+'</span>' +
'</div>'); '</div>');
chat_content.scrollTop(chat_content[0].scrollHeight); $chat_content.scrollTop($chat_content[0].scrollHeight);
$chat.data('composing', false);
}); });
} }
} else {
composing = $chat.data('composing');
if (!composing) {
notify = $msg({'to':jid, 'type': 'chat'})
.c('composing', {'xmlns':'http://jabber.org/protocol/chatstates'});
xmppchat.connection.send(notify);
$chat.data('composing', true);
}
} }
}; };
return ob; return ob;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment