support-chat/js/supportchat.js

changeset 55
6f0822a428b7
parent 54
e5e70a46ace8
child 56
5dd3b23da0ae
equal deleted inserted replaced
54:e5e70a46ace8 55:6f0822a428b7
99 { 99 {
100 question_type = $("#support-question-type").val(); 100 question_type = $("#support-question-type").val();
101 question_name = $("#support-question-name").val(); 101 question_name = $("#support-question-name").val();
102 question_text = $("#support-question-text").val(); 102 question_text = $("#support-question-text").val();
103 103
104 var our_nick = question_name;
105
106 set_ui_state("wait"); 104 set_ui_state("wait");
107 105
108 // Create our question room 106 // Create our question room
109 question_muc = new MUC(conn, { 107 question_muc = new MUC(conn, {
110 // Handle room joins 108 // Handle room joins
111 joined: function (stanza, muc, occupant) 109 joined: function (stanza, muc, occupant)
112 { 110 {
113 if(occupant.nick == our_nick) 111 if(occupant.nick == question_muc.nick)
112 {
114 // We joined the question room, now join the team room and tell them 113 // We joined the question room, now join the team room and tell them
115 team_muc.join(support_config.team_rooms[question_type], our_nick); 114 team_muc.join(support_config.team_rooms[question_type], question_muc.nick);
116 else if(ui_state == "wait") 115 // Also post our question to the question room for reference
116 question_muc.send_message(question_text);
117 }
118 else if(current_assistant == null)
117 { 119 {
118 // We were waiting for an assistant, and one just joined 120 // We were waiting for an assistant, and one just joined
119 var html = "<span class='muc-message'><span class='muc-nick'>" + htmlescape(occupant.nick) + "</span>" + " is answering your query</span><br/>\n"; 121 set_assistant(occupant.nick);
120 $("#support-log").append(html).scrollTop($("#support-log")[0].scrollHeight); 122 if(ui_state == "wait")
121 $("#support-send-button").click(function () 123 {
124 $("#support-send-button").click(function ()
122 { 125 {
123 question_muc.send_message($("#support-input").val()); 126 question_muc.send_message($("#support-input").val());
124 $("#support-input").val(""); 127 $("#support-input").val("");
125 }); 128 });
126 set_ui_state("converse"); 129 set_ui_state("converse");
130 }
127 } 131 }
128 }, 132 },
129 133
130 // Handle incoming messages 134 // Handle incoming messages
131 message: function (stanza, muc, nick, message) 135 message: function (stanza, muc, nick, message)
139 conn.sendIQ($iq({to: support_config.muc_server, type: "get"}) 143 conn.sendIQ($iq({to: support_config.muc_server, type: "get"})
140 .c("query", { xmlns: "http://jabber.org/protocol/muc#unique" }), 144 .c("query", { xmlns: "http://jabber.org/protocol/muc#unique" }),
141 function (result) // Success 145 function (result) // Success
142 { 146 {
143 var unique = Strophe.getText(result.getElementsByTagName("unique")[0]); 147 var unique = Strophe.getText(result.getElementsByTagName("unique")[0]);
144 question_muc.join(unique + "@" + support_config.muc_server, our_nick); 148 question_muc.join(unique + "@" + support_config.muc_server, question_name);
145 }, 149 },
146 function (result) // Failure to get unique room name 150 function (result) // Failure to get unique room name
147 { 151 {
148 var unique = "support-"+Math.floor(Math.random()*512); 152 var unique = "support-"+Math.floor(Math.random()*512);
149 question_muc.join(unique + "@" + support_config.muc_server, our_nick); 153 question_muc.join(unique + "@" + support_config.muc_server, question_name);
150 }); 154 });
151 155
152 // Create the team MUC object (it will be joined after we join the question MUC) 156 // Create the team MUC object (it will be joined after we join the question MUC)
153 team_muc = new MUC(conn, { 157 team_muc = new MUC(conn, {
154 // Someone joined the team MUC 158 // Someone joined the team MUC
155 joined: function (stanza, muc, occupant) 159 joined: function (stanza, muc, occupant)
156 { 160 {
157 if(occupant.nick != our_nick) 161 if(occupant.nick != team_muc.nick)
158 return; 162 return;
159 163
160 var sent = false; 164 var sent = false;
161 for(var nick in team_muc.occupants) 165 for(var nick in team_muc.occupants)
162 { 166 {
163 if(team_muc.occupants[nick].affiliation == "none" || nick == our_nick) 167 if(team_muc.occupants[nick].affiliation == "none" || nick == team_muc.nick)
164 continue; 168 continue;
165 sent = true; 169 sent = true;
166 if(support_config.send_invites) 170 if(support_config.send_invites)
167 team_muc.send_invite(team_muc.jid+"/"+nick, question_text + "\n" + question_muc.jid); 171 team_muc.send_invite(team_muc.jid+"/"+nick, question_text + "\n" + question_muc.jid);
168 else 172 else
176 180
177 error: function (stanza, muc, error) 181 error: function (stanza, muc, error)
178 { 182 {
179 if(error == "conflict") 183 if(error == "conflict")
180 { 184 {
181 our_nick += "_"; 185 muc.join(support_config.team_rooms[question_type], team_muc.nick+"_");
182 muc.join(support_config.team_rooms[question_type], our_nick);
183 } 186 }
184 else 187 else
185 set_ui_state("error"); 188 set_ui_state("error");
186 } 189 }
187 }); 190 });

mercurial