Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.

Fri, 16 Apr 2010 18:38:05 +0100

author
matthew@heavyhorse.vm.bytemark.co.uk
date
Fri, 16 Apr 2010 18:38:05 +0100
changeset 55
6f0822a428b7
parent 54
e5e70a46ace8
child 56
5dd3b23da0ae

Remove hacky our_nick global, use the relevant MUC's nick property, or question_name as appropriate.

support-chat/js/supportchat.js file | annotate | diff | comparison | revisions
--- a/support-chat/js/supportchat.js	Fri Apr 16 18:35:33 2010 +0100
+++ b/support-chat/js/supportchat.js	Fri Apr 16 18:38:05 2010 +0100
@@ -101,8 +101,6 @@
 	question_name = $("#support-question-name").val();
 	question_text = $("#support-question-text").val();
 	
-	var our_nick = question_name;
-	
 	set_ui_state("wait");
 	
 	// Create our question room
@@ -110,20 +108,26 @@
 		// Handle room joins
 		joined: function (stanza, muc, occupant)
 		{
-			if(occupant.nick == our_nick)
+			if(occupant.nick == question_muc.nick)
+			{
 				// We joined the question room, now join the team room and tell them
-				team_muc.join(support_config.team_rooms[question_type], our_nick);
-			else if(ui_state == "wait")
+				team_muc.join(support_config.team_rooms[question_type], question_muc.nick);
+				// Also post our question to the question room for reference
+				question_muc.send_message(question_text);
+			}
+			else if(current_assistant == null)
 			{
 				// We were waiting for an assistant, and one just joined
-				var html = "<span class='muc-message'><span class='muc-nick'>" + htmlescape(occupant.nick) + "</span>" + " is answering your query</span><br/>\n";
-				$("#support-log").append(html).scrollTop($("#support-log")[0].scrollHeight);
-				$("#support-send-button").click(function ()
+				set_assistant(occupant.nick);
+				if(ui_state == "wait")
+				{
+					$("#support-send-button").click(function ()
 					{
 						question_muc.send_message($("#support-input").val());
 						$("#support-input").val("");
 					});
-				set_ui_state("converse");
+					set_ui_state("converse");
+				}
 			}
 		},
 		
@@ -141,12 +145,12 @@
 		function (result) // Success
 		{
 			var unique = Strophe.getText(result.getElementsByTagName("unique")[0]);
-			question_muc.join(unique + "@" + support_config.muc_server, our_nick);
+			question_muc.join(unique + "@" + support_config.muc_server, question_name);
 		},
 		function (result) // Failure to get unique room name
 		{
 			var unique = "support-"+Math.floor(Math.random()*512);
-			question_muc.join(unique + "@" + support_config.muc_server, our_nick);
+			question_muc.join(unique + "@" + support_config.muc_server, question_name);
 		});
 	
 	// Create the team MUC object (it will be joined after we join the question MUC)
@@ -154,13 +158,13 @@
 		// Someone joined the team MUC
 		joined: function (stanza, muc, occupant)
 		{
-			if(occupant.nick != our_nick)
+			if(occupant.nick != team_muc.nick)
 				return;
 			
 			var sent = false;
 			for(var nick in team_muc.occupants)
 			{
-				if(team_muc.occupants[nick].affiliation == "none" || nick == our_nick)
+				if(team_muc.occupants[nick].affiliation == "none" || nick == team_muc.nick)
 					continue;
 				sent = true;
 				if(support_config.send_invites)
@@ -178,8 +182,7 @@
 		{
 			if(error == "conflict")
 			{
-				our_nick += "_";
-				muc.join(support_config.team_rooms[question_type], our_nick);
+				muc.join(support_config.team_rooms[question_type], team_muc.nick+"_");
 			}
 			else
 				set_ui_state("error");

mercurial