# HG changeset patch # User Matthew Wild # Date 1268935361 0 # Node ID b691536ed125cededb1d45eda639229173d2973d # Parent bd1d350ab61c9cf8895420bec208dc221071d34a Support for joining the question and team MUCs, and notifying team members of the question diff -r bd1d350ab61c -r b691536ed125 js/supportchat.js --- 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