Commit e4a0272e authored by JC Brand's avatar JC Brand

The user is now notified if the chat partner is typing.

parent 448eb73a
......@@ -135,32 +135,31 @@ var xmppchat = (function (jarnxmpp, $, console) {
};
ob.Messages.messageReceived = function (message) {
// FIXME: Requires refactor
var jid = $(message).attr('from'),
bare_jid = Strophe.getBareJidFromJid(jid),
resource = Strophe.getResourceFromJid(jid),
delayed = $(message).find('delay').length > 0;
ob.ChatPartners.add(bare_jid, resource);
var body = $(message).children('body').text();
if (body === "") {
// TODO:
return true; // This is a typing notification, we do not handle it here...
}
var xhtml_body = $(message).find('html > body').contents(),
delayed = $(message).find('delay').length > 0,
body = $(message).children('body').text(),
event = jQuery.Event('jarnxmpp.message');
if (body !== "") {
var xhtml_body = $(message).find('html > body').contents();
if (xhtml_body.length > 0) {
event.mtype = 'xhtml';
event.body = xhtml_body.html();
} else {
event.body = body;
event.mtype = 'text';
}
}
event.from = jid;
event.delayed = delayed;
if (xhtml_body.length > 0) {
event.mtype = 'xhtml';
event.body = xhtml_body.html();
} else {
event.body = body;
event.mtype = 'text';
event.message = message;
ob.ChatPartners.add(bare_jid, resource);
if (event.body) {
ob.Messages.ClientStorage.addMessage(jid, event.body, 'from');
}
ob.Messages.ClientStorage.addMessage(jid, event.body, 'from');
$(document).trigger(event);
return true;
};
......
......@@ -328,7 +328,6 @@ xmppchat.UI = (function (xmppUI, $, console) {
*/
var user_id = Strophe.getNodeFromJid(event.from),
jid = Strophe.getBareJidFromJid(event.from),
text = event.body.replace(/<br \/>/g, ""),
that = this;
xmppchat.Presence.getUserInfo(user_id, function (data) {
......@@ -336,26 +335,38 @@ xmppchat.UI = (function (xmppUI, $, console) {
var chat_content = $(chat).find(".chat-content"),
now = new Date(),
time = now.toLocaleTimeString().substring(0,5),
div = $('<div class="chat-message"></div>');
div = $('<div></div>'),
composing = $(event.message).find('composing'),
text;
if (event.delayed) {
div.addClass('delayed');
}
if (user_id == that.username) {
message_html = div.append(
'<span class="chat-message-me">'+time+' me:&nbsp;&nbsp;</span>' +
'<span class="chat-message-content">'+text+'</span>'
);
} else {
message_html = div.append(
'<span class="chat-message-them">'+time+' '+data.fullname+':&nbsp;&nbsp;</span>' +
'<span class="chat-message-content">'+text+'</span>'
);
if (event.body) {
text = event.body.replace(/<br \/>/g, "");
div.addClass('chat-message');
if (event.delayed) {
div.addClass('delayed');
}
if (user_id == that.username) {
message_html = div.append(
'<span class="chat-message-me">'+time+' me:&nbsp;&nbsp;</span>' +
'<span class="chat-message-content">'+text+'</span>'
);
} else {
message_html = div.append(
'<span class="chat-message-them">'+time+' '+data.fullname+':&nbsp;&nbsp;</span>' +
'<span class="chat-message-content">'+text+'</span>'
);
}
chat_content.find('div.chat-event').remove();
chat_content.append(message_html);
xmppchat.UI.msg_counter += 1;
xmppchat.UI.updateMsgCounter();
} else if (composing.length > 0) {
message_html = div.addClass('chat-event').text(data.fullname + ' is typing...');
chat_content.find('div.chat-event').remove().end().append(message_html);
}
chat_content.append(message_html);
chat_content.scrollTop(chat_content[0].scrollHeight);
xmppchat.UI.msg_counter += 1;
xmppchat.UI.updateMsgCounter();
});
});
};
......
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