Support for joining the question and team MUCs, and notifying team members of the question

Thu, 18 Mar 2010 18:02:41 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 18 Mar 2010 18:02:41 +0000
changeset 21
b691536ed125
parent 20
bd1d350ab61c
child 22
54574593fa89

Support for joining the question and team MUCs, and notifying team members of the question

js/supportchat.js file | annotate | diff | comparison | revisions
--- a/js/supportchat.js	Thu Mar 18 16:05:59 2010 +0000
+++ b/js/supportchat.js	Thu Mar 18 18:02:41 2010 +0000
@@ -3,6 +3,7 @@
 var support_config = {
 	login_domain: "anon.localhost",
 	bosh_url: "/http-bind",
+	muc_server: "support.localhost",
 	team_rooms: {
 		"Sales": "sales@support.localhost",
 		"Technical": "technical@support.localhost"
@@ -52,7 +53,56 @@
 	var question_name = $("#support-question-name").val();
 	var question_text = $("#support-question-text").val();
 	
-	alert(question_name + " submitted a " + question_type + " question:\n " + question_text);
+	var our_nick = question_name;
+	
+	// Create our question room
+	var question_muc = new MUC(conn, {
+		joined: function (stanza, muc, nick)
+		{
+			if(nick == our_nick)
+				team_muc.join(support_config.team_rooms[question_type], our_nick);
+		}
+	});
+
+	// Get a unique room name from the server and then join the question MUC
+	conn.sendIQ($iq({to: support_config.muc_server, type: "get"})
+		.c("query", { xmlns: "http://jabber.org/protocol/muc#unique" }),
+		function (result) // Success
+		{
+			var unique = Strophe.getText(result.getElementsByTagName("unique")[0]);
+			question_muc.join(unique + "@" + support_config.muc_server, our_nick);
+		},
+		function (result) // Failure
+		{
+			//FIXME
+		});
+	
+	// Create the team MUC object (it will be joined after we join the question MUC)
+	var team_muc = new MUC(conn, {
+		joined: function (stanza, muc, nick)
+		{
+			if(nick != our_nick)
+				return;
+			
+			for(var nick in team_muc.occupants)
+				team_muc.send_private_message(nick, question_text + "\n" + question_muc.jid);
+		},
+		
+		error: function (stanza, muc, error)
+		{
+			if(error == "conflict")
+			{
+				our_nick += "_";
+				muc.join(support_config.team_rooms[question_type], our_nick);
+			}
+			else
+				alert("unhandled error: " + error);
+		}
+	});
+	
+	// Switch to waiting screen
+	$("#support-question").hide();
+	$("#support-wait").show();
 }
 
 /* Update the UI according to whether we are

mercurial