Thu, 18 Mar 2010 18:34:46 +0000
Add support for handling incoming messages to the MUC library
js/xmpp_muc.js | file | annotate | diff | comparison | revisions |
--- a/js/xmpp_muc.js Thu Mar 18 18:33:27 2010 +0000 +++ b/js/xmpp_muc.js Thu Mar 18 18:34:46 2010 +0000 @@ -12,6 +12,7 @@ /* Initialize stanza handlers */ conn.addHandler(recontext(this, this.handle_join), null, "presence", null, null, null); conn.addHandler(recontext(this, this.handle_error), null, "presence", "error", null, null); + conn.addHandler(recontext(this, this.handle_message), null, "message", "groupchat", null, null); /* Return newly-created object */ return this; @@ -96,5 +97,20 @@ } } return true; + }, + + handle_message: function (stanza) + { + if(!this.callbacks.message) + return true; + + if(stanza.getAttribute("type") == "groupchat" && Strophe.getBareJidFromJid(stanza.getAttribute("from")) == this.jid) + { + var body = stanza.getElementsByTagName("body"); + if(body.length > 0 && stanza.getElementsByTagName("delay").length == 0) + this.callbacks.message(stanza, this, Strophe.getResourceFromJid(stanza.getAttribute("from")), Strophe.getText(body[0])); + } + return true; } + };