Commit e06a34a9 authored by JC Brand's avatar JC Brand

Some initial work on show messages with type "error"

parent 9e8674ef
...@@ -366,6 +366,14 @@ ...@@ -366,6 +366,14 @@
} }
}, },
handleErrorMessage: function (message) {
var $message = $('[data-msgid='+message.get('msgid')+']');
if ($message.length) {
$message.after($('<div class="chat-error"></div>').text(message.get('message')));
this.scrollDown();
}
},
onMessageAdded: function (message) { onMessageAdded: function (message) {
/* Handler that gets called when a new message object is created. /* Handler that gets called when a new message object is created.
* *
...@@ -376,7 +384,9 @@ ...@@ -376,7 +384,9 @@
window.clearTimeout(this.clear_status_timeout); window.clearTimeout(this.clear_status_timeout);
delete this.clear_status_timeout; delete this.clear_status_timeout;
} }
if (!message.get('message')) { if (message.get('type') === 'error') {
this.handleErrorMessage(message);
} else if (!message.get('message')) {
this.handleChatStateMessage(message); this.handleChatStateMessage(message);
} else { } else {
this.handleTextMessage(message); this.handleTextMessage(message);
......
...@@ -1255,16 +1255,22 @@ ...@@ -1255,16 +1255,22 @@
getMessageAttributes: function ($message, $delay, original_stanza) { getMessageAttributes: function ($message, $delay, original_stanza) {
$delay = $delay || $message.find('delay'); $delay = $delay || $message.find('delay');
var body = $message.children('body').text(), var type = $message.attr('type'),
delayed = $delay.length > 0, body, stamp, time, sender, from;
if (type === 'error') {
body = $message.find('error').children('text').text();
} else {
body = $message.children('body').text();
}
var delayed = $delay.length > 0,
fullname = this.get('fullname'), fullname = this.get('fullname'),
is_groupchat = $message.attr('type') === 'groupchat', is_groupchat = type === 'groupchat',
chat_state = $message.find(converse.COMPOSING).length && converse.COMPOSING || chat_state = $message.find(converse.COMPOSING).length && converse.COMPOSING ||
$message.find(converse.PAUSED).length && converse.PAUSED || $message.find(converse.PAUSED).length && converse.PAUSED ||
$message.find(converse.INACTIVE).length && converse.INACTIVE || $message.find(converse.INACTIVE).length && converse.INACTIVE ||
$message.find(converse.ACTIVE).length && converse.ACTIVE || $message.find(converse.ACTIVE).length && converse.ACTIVE ||
$message.find(converse.GONE).length && converse.GONE, $message.find(converse.GONE).length && converse.GONE;
stamp, time, sender, from;
if (is_groupchat) { if (is_groupchat) {
from = Strophe.unescapeNode(Strophe.getResourceFromJid($message.attr('from'))); from = Strophe.unescapeNode(Strophe.getResourceFromJid($message.attr('from')));
...@@ -1286,13 +1292,14 @@ ...@@ -1286,13 +1292,14 @@
sender = 'them'; sender = 'them';
} }
return { return {
chat_state: chat_state, 'type': type,
delayed: delayed, 'chat_state': chat_state,
fullname: fullname, 'delayed': delayed,
message: body || undefined, 'fullname': fullname,
msgid: $message.attr('id'), 'message': body || undefined,
sender: sender, 'msgid': $message.attr('id'),
time: time 'sender': sender,
'time': time
}; };
}, },
...@@ -1306,11 +1313,8 @@ ...@@ -1306,11 +1313,8 @@
comparator: 'time_opened', comparator: 'time_opened',
registerMessageHandler: function () { registerMessageHandler: function () {
converse.connection.addHandler( converse.connection.addHandler(this.onMessage.bind(this), null, 'message', 'chat');
function (message) { converse.connection.addHandler(this.onErrorMessage.bind(this), null, 'message', 'error');
this.onMessage(message);
return true;
}.bind(this), null, 'message', 'chat');
}, },
chatBoxMayBeShown: function (chatbox) { chatBoxMayBeShown: function (chatbox) {
...@@ -1341,6 +1345,24 @@ ...@@ -1341,6 +1345,24 @@
}); });
}, },
onErrorMessage: function (message) {
/* Handler method for all incoming error message stanzas
*/
// TODO: we can likely just reuse "onMessage" below
var $message = $(message),
from_jid = Strophe.getBareJidFromJid($message.attr('from'));
if (from_jid === converse.bare_jid) {
return true;
}
// Get chat box, but only create a new one when the message has a body.
var chatbox = this.getChatBox(from_jid);
if (!chatbox) {
return true;
}
chatbox.createMessage($message, null, message);
return true;
},
onMessage: function (message) { onMessage: function (message) {
/* Handler method for all incoming single-user chat "message" /* Handler method for all incoming single-user chat "message"
* stanzas. * stanzas.
...@@ -1380,7 +1402,6 @@ ...@@ -1380,7 +1402,6 @@
from_resource = Strophe.getResourceFromJid(from_jid); from_resource = Strophe.getResourceFromJid(from_jid);
is_me = from_bare_jid === converse.bare_jid; is_me = from_bare_jid === converse.bare_jid;
msgid = $message.attr('id'); msgid = $message.attr('id');
if (is_me) { if (is_me) {
// I am the sender, so this must be a forwarded message... // I am the sender, so this must be a forwarded message...
contact_jid = Strophe.getBareJidFromJid(to_jid); contact_jid = Strophe.getBareJidFromJid(to_jid);
......
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