xmpp_muc.js: Support for callback on occupant leave

Fri, 16 Apr 2010 18:43:48 +0100

author
matthew@heavyhorse.vm.bytemark.co.uk
date
Fri, 16 Apr 2010 18:43:48 +0100
changeset 57
42f5669be677
parent 56
5dd3b23da0ae
child 58
c775513a5d78

xmpp_muc.js: Support for callback on occupant leave

support-chat/js/xmpp_muc.js file | annotate | diff | comparison | revisions
--- a/support-chat/js/xmpp_muc.js	Fri Apr 16 18:38:43 2010 +0100
+++ b/support-chat/js/xmpp_muc.js	Fri Apr 16 18:43:48 2010 +0100
@@ -25,6 +25,7 @@
 
 	/* Initialize stanza handlers */
 	conn.addHandler(recontext(this, this.handle_join), null, "presence", null, null, null);
+	conn.addHandler(recontext(this, this.handle_leave), null, "presence", "unavailable", 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);
 
@@ -108,6 +109,29 @@
 		return true;
 	},
 
+	handle_leave: function (stanza)
+	{
+		var nick = Strophe.getResourceFromJid(stanza.getAttribute("from"));
+		if(Strophe.getBareJidFromJid(stanza.getAttribute("from")) == this.jid)
+			if(this.occupants[nick])
+			{
+				var text = stanza.getElementsByTagName("status")[0];
+				if(text)
+				{
+					text = Strophe.getText(text);
+					this.occupants[nick].status = text;
+				}
+				if(this.callbacks.left)
+					this.callbacks.left(stanza, this, this.occupants[nick]);
+				if(this.status_handler)
+				{
+					this.status_handler(stanza);
+				}
+				delete this.occupants[nick];
+			}
+		return true;
+	},
+
 	handle_error: function (stanza)
 	{
 		if(this.callbacks.error

mercurial