social_stream-presence 0.5.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,179 @@
1
+ ////////////////////
2
+ // Store and restore conversations using session storage.
3
+ ////////////////////
4
+
5
+
6
+ function storeChatData(){
7
+ //Check for Session Storage support
8
+ if (! window.sessionStorage){
9
+ return
10
+ }
11
+
12
+ storeUserChatStatus();
13
+ storeChatConnectionParametres();
14
+ storeConversations();
15
+ }
16
+
17
+ function storeConversations() {
18
+
19
+ var chatboxes = getAllChatBoxes();
20
+ var visibleChatBoxes = getVisibleChatBoxes();
21
+ var storedSlugs = [];
22
+ var visibleMaxSlugs = [];
23
+ var visibleMinSlugs = [];
24
+
25
+ //window[getChatVariableFromSlug("eric-white")].is(":visible")
26
+
27
+ //Stored all conversations
28
+ for (var i=0;i<chatboxes.length;i++){
29
+ var slug = chatboxes[i].id
30
+ var log = $(chatboxes[i]).html()
31
+ sessionStorage.setItem("chat_log_" + slug, log);
32
+ storedSlugs.push(slug)
33
+ }
34
+
35
+ if(storedSlugs.length>0){
36
+ //Stored slugs with stored conversations
37
+ sessionStorage.setItem("slugs_with_stored_log", storedSlugs.join(","));
38
+ } else {
39
+ sessionStorage.setItem("slugs_with_stored_log", null);
40
+ }
41
+
42
+ //Stored slugs with visible chatbox
43
+ for (var j=0;j<visibleChatBoxes.length;j++){
44
+ if(visibleChatBoxes[j].is(":visible")){
45
+ visibleMaxSlugs.push($(visibleChatBoxes[j]).attr("id"))
46
+ } else {
47
+ visibleMinSlugs.push($(visibleChatBoxes[j]).attr("id"))
48
+ }
49
+ }
50
+
51
+ if (visibleMaxSlugs.length > 0) {
52
+ sessionStorage.setItem("slugs_with_visible_max_chatbox", visibleMaxSlugs.join(","));
53
+ } else {
54
+ sessionStorage.setItem("slugs_with_visible_max_chatbox", null);
55
+ }
56
+
57
+ if (visibleMinSlugs.length > 0) {
58
+ sessionStorage.setItem("slugs_with_visible_min_chatbox", visibleMinSlugs.join(","));
59
+ } else {
60
+ sessionStorage.setItem("slugs_with_visible_min_chatbox", null);
61
+ }
62
+ }
63
+
64
+
65
+ function storeChatConnectionParametres() {
66
+ if (sessionStorage.getItem("cookie") == null){
67
+ sessionStorage.setItem("cookie", cookie);
68
+ sessionStorage.setItem("chat_user_name", user_name);
69
+ sessionStorage.setItem("chat_user_slug", user_slug);
70
+ sessionStorage.setItem("chat_user_jid", user_jid);
71
+ }
72
+ }
73
+
74
+ function storeUserChatStatus(){
75
+ sessionStorage.setItem("chat_user_status", userStatus);
76
+ }
77
+
78
+ function getRestoreUserChatStatus(){
79
+ if (!window.sessionStorage) {
80
+ return "available";
81
+ }
82
+
83
+ var restoreUserChatStatus = sessionStorage.getItem("chat_user_status");
84
+ if ((restoreUserChatStatus != null)&&((restoreUserChatStatus in sstreamChatStatus)||(restoreUserChatStatus=="offline"))){
85
+ return restoreUserChatStatus;
86
+ } else {
87
+ return "available";
88
+ }
89
+ }
90
+
91
+
92
+ function restoreChatData(){
93
+ //Check for Session Storage support
94
+ if (! window.sessionStorage){
95
+ return
96
+ }
97
+ restoreConversations();
98
+ }
99
+
100
+ function restoreConversations() {
101
+
102
+ //Get Stored slugs
103
+ var storedSlugsString = sessionStorage.getItem("slugs_with_stored_log");
104
+
105
+ if (storedSlugsString != null){
106
+ var storedSlugs=storedSlugsString.split(",")
107
+
108
+ //Get slugs with visible chatbox
109
+ var visibleMaxSlugsString = sessionStorage.getItem("slugs_with_visible_max_chatbox");
110
+ var visibleMinSlugsString = sessionStorage.getItem("slugs_with_visible_min_chatbox");
111
+
112
+ if(visibleMaxSlugsString!=null){
113
+ var visibleMaxSlugs = visibleMaxSlugsString.split(",")
114
+ } else {
115
+ var visibleMaxSlugs = [];
116
+ }
117
+
118
+ if(visibleMinSlugsString!=null){
119
+ var visibleMinSlugs = visibleMinSlugsString.split(",")
120
+ } else {
121
+ var visibleMinSlugs = [];
122
+ }
123
+
124
+
125
+ for (var i=0;i<storedSlugs.length;i++){
126
+ restoreLog = sessionStorage.getItem("chat_log_" + storedSlugs[i]);
127
+
128
+ if (restoreLog != null){
129
+
130
+ //Create window (if it not exists)
131
+
132
+ var guest_slug = storedSlugs[i];
133
+
134
+ //Check for slug name and connectionBox visibility
135
+ if (typeof($('div.user_presence[slug=' + guest_slug + ']').attr('name')) == 'undefined') {
136
+ //No connectionBox for this user (user disconnect)
137
+ var guest_name = getNameFromSlug(guest_slug)
138
+ } else {
139
+ var guest_name = $('div.user_presence[slug=' + guest_slug + ']').attr('name');
140
+ }
141
+
142
+ var guest_jid = guest_slug + "@" + domain;
143
+
144
+
145
+ if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
146
+ if ((visibleMinSlugs.indexOf(guest_slug)!=-1)){
147
+ //Minimize chatbox
148
+ window[getChatVariableFromSlug(guest_slug)].parent().toggle(false);
149
+ }
150
+ if ((visibleMaxSlugs.indexOf(guest_slug)==-1)&&(visibleMinSlugs.indexOf(guest_slug)==-1)){
151
+ window[getChatVariableFromSlug(guest_slug)].chatbox("option", "boxManager").toggleBox(false);
152
+ }
153
+ } else {
154
+ //Always created.
155
+ }
156
+
157
+ window[getChatVariableFromSlug(guest_slug)].html(restoreLog)
158
+
159
+ //Mark as disconnect if user is offline.
160
+ if (typeof($('div.user_presence[slug=' + guest_slug + ']').attr('name')) == 'undefined') {
161
+ //No connectionBox for this user!
162
+ showChatNotificationForSlug(guest_slug,guest_name + " is offline");
163
+ }
164
+
165
+ }
166
+ }
167
+ }
168
+ }
169
+
170
+
171
+
172
+ ////////////////////
173
+ // Events
174
+ ////////////////////
175
+
176
+ $(window).unload(function() {
177
+ storeChatData();
178
+ disconnectStrophe();
179
+ });
@@ -214,6 +214,21 @@ function offlineDataSendControl(){
214
214
  }
215
215
 
216
216
 
217
+ ////////////////////
218
+ //Build name from slug
219
+ ////////////////////
220
+
221
+ function getNameFromSlug(slug){
222
+ var cname = slug.split("-");
223
+ var name = "";
224
+ for(i=0; i<cname.length; i++){
225
+ if (i!=0){
226
+ name = name + " ";
227
+ }
228
+ name = name + cname[i][0].toUpperCase() + cname[i].substring(1,cname[i].length);
229
+ }
230
+ return name;
231
+ }
217
232
 
218
233
 
219
234
  ////////////////////
@@ -20,7 +20,7 @@ function createChatBox(guest_slug,guest_name,guest_jid,user_name,user_jid){
20
20
  if (typeof window[getChatVariableFromSlug(guest_slug)] == 'undefined') {
21
21
 
22
22
  //Add div with id = guest_slug
23
- $("#chat_divs").append("<div id=" + guest_slug + " name=" + guest_name + "></div>")
23
+ $("#chat_divs").append("<div id=" + guest_slug + " name=" + guest_name + " class=chatbox ></div>")
24
24
 
25
25
 
26
26
  //Offset Management for new box
@@ -114,6 +114,13 @@ function getSlugFromChatVariable(variable){
114
114
  return variable.split("_")[1];
115
115
  }
116
116
 
117
+ function getVisibleChatBoxes(){
118
+ return visibleChatBoxes
119
+ }
120
+
121
+ function getAllChatBoxes(){
122
+ return $(".chatbox")
123
+ }
117
124
 
118
125
  ////////////////////
119
126
  //Box replacement
@@ -1,6 +1,25 @@
1
1
  ////////////////////
2
- //Hash table
2
+ //Global constants
3
3
  ////////////////////
4
+ var BOSH_SERVICE = '<%= SocialStream::Presence.bosh_service || root_url + "http-bind/" %>';
5
+ var domain = '<%=SocialStream::Presence.domain%>';
6
+ var sound_path = "/assets/audio/chat/onMessage";
7
+
8
+
9
+ ////////////////////
10
+ //Hash tables
11
+ ////////////////////
12
+
13
+ //Keys: Social Stream Chat Status
14
+ //Value: Xmpp status
15
+ var sstreamChatStatus = new Array();
16
+ sstreamChatStatus['available'] = "chat";
17
+ sstreamChatStatus['away'] = "away";
18
+ sstreamChatStatus['autoaway'] = "away";
19
+ sstreamChatStatus['dnd'] = "dnd";
20
+
21
+ //Keys: Xmpp status
22
+ //Value: Message associated with Xmpp Status
4
23
  var statusMessage = new Array();
5
24
  statusMessage[''] = "";
6
25
  statusMessage['chat'] = "";
@@ -8,27 +27,49 @@ statusMessage['away'] = "Away";
8
27
  statusMessage['xa'] = "Away";
9
28
  statusMessage['dnd'] = "Busy";
10
29
 
30
+ //Keys: Xmpp status
31
+ //Value: Icon name (Same as Social Stream Status)
32
+ var statusIcons = new Array();
33
+ statusIcons[''] = "available";
34
+ statusIcons['chat'] = "available";
35
+ statusIcons['away'] = "away";
36
+ statusIcons['xa'] = "away";
37
+ statusIcons['dnd'] = "dnd";
38
+
11
39
 
12
40
 
13
41
  ////////////////////
14
42
  //Connect functions
15
43
  ////////////////////
16
44
 
45
+ function connectToChat(user_jid,cookie,password){
46
+
47
+ if (isStropheConnected()){
48
+ return true;
49
+ }
50
+
51
+ if (authByCookie()){
52
+ if (connectToServerWithCookie(user_jid, cookie)==false){
53
+ refreshChatWindow();
54
+ }
55
+ } else {
56
+ if (connectToServerWithPassword(user_jid,password)==false){
57
+ refreshChatWindow();
58
+ }
59
+ }
60
+ }
61
+
62
+
17
63
  function isStropheConnected(){
18
- if((connection!=null)&&(connection.connected)){
64
+ if((connection!=null)&&(connection.connected)){
19
65
  return true;
20
66
  } else {
21
- return false;
22
- }
67
+ return false;
68
+ }
23
69
  }
24
70
 
25
71
 
26
- function connectToServerWithCookie(){
27
-
28
- if (isStropheConnected()){
29
- log("connectToServerWithCookie() returns: Strophe already connected");
30
- }
31
- log("connectToServerWithCookie() calls");
72
+ function connectToServerWithCookie(user_jid, cookie){
32
73
  try {
33
74
  connection = new Strophe.Connection(BOSH_SERVICE);
34
75
  connection.connect(user_jid, cookie, onConnect);
@@ -36,16 +77,13 @@ function connectToServerWithCookie(){
36
77
  //"Handle errors"
37
78
  return false;
38
79
  }
80
+ return true;
39
81
  }
40
82
 
41
83
 
42
84
  //Password: Get from chatPassword param if exists, instead try to get from sessionStorage.
43
- function connectToServerWithPassword(chatPassword){
85
+ function connectToServerWithPassword(user_jid, chatPassword){
44
86
 
45
- if (isStropheConnected()){
46
- log("connectToServerWithPassword() returns: Strophe already connected");
47
- }
48
-
49
87
  //Get Password
50
88
  if ((chatPassword!=null)&&(chatPassword!="")){
51
89
  var password = chatPassword;
@@ -67,6 +105,7 @@ function connectToServerWithPassword(chatPassword){
67
105
  return true;
68
106
  }
69
107
 
108
+
70
109
  ////////
71
110
  //Auth Methods
72
111
  ///////
@@ -80,21 +119,17 @@ function authByPassword(){
80
119
  return authMethod=="password";
81
120
  }
82
121
 
83
- function ifCookie(){
84
- return (!(typeof cookie == 'undefined'))
85
- }
86
-
87
122
 
88
123
  ////////////////////
89
124
  //Stanza management using Strophe
90
125
  ////////////////////
91
126
 
92
127
  //Global variables
93
- var userStatus = "chat";
128
+ var userStatus;
94
129
  var awayTimerPeriod = 60000;
95
130
  var timerPeriod = 5000;
96
131
  var refreshMinTime = 3*timerPeriod;
97
- var awayTime = 20*60000; //20 minutes
132
+ var awayTime = 10*60000; //10 minutes
98
133
  var awayCounter = 0;
99
134
  var timerCounter = 0;
100
135
  var connection = null;
@@ -103,116 +138,125 @@ var awayTimer;
103
138
  var timer;
104
139
  var reconnectTimer;
105
140
  var disconnectionFlag = true;
141
+ var afterNewConnectionFlagFlag = false;
106
142
  var requestContacts=false;
107
143
  var cyclesToRefresh = (refreshMinTime/timerPeriod);
108
144
 
109
145
 
110
146
  function onConnect(status) {
111
-
112
- //Status.ERROR An error has occurred
113
- //Status.CONNECTING The connection is currently being made
114
- //Status.CONNFAIL The connection attempt failed
115
- //Status.AUTHENTICATING The connection is authenticating
116
- //Status.AUTHFAIL The authentication attempt failed
117
- //Status.CONNECTED The connection has succeeded
118
- //Status.DISCONNECTED The connection has been terminated
119
- //Status.DISCONNECTING The connection is currently being terminated
120
- //Status.ATTACHED The connection has been attached
121
-
122
- log('Strophe onConnect callback call with status ' + status);
123
-
124
- if (status == Strophe.Status.ATTACHED){
125
- log('Strophe connection attached');
126
- return;
127
- }
128
-
129
- if (status == Strophe.Status.AUTHENTICATING ){
147
+
148
+ //Status.ERROR An error has occurred
149
+ //Status.CONNECTING The connection is currently being made
150
+ //Status.CONNFAIL The connection attempt failed
151
+ //Status.AUTHENTICATING The connection is authenticating
152
+ //Status.AUTHFAIL The authentication attempt failed
153
+ //Status.CONNECTED The connection has succeeded
154
+ //Status.DISCONNECTED The connection has been terminated
155
+ //Status.DISCONNECTING The connection is currently being terminated
156
+ //Status.ATTACHED The connection has been attached
157
+
158
+ log('Strophe onConnect callback call with status ' + status);
159
+
160
+ if (status == Strophe.Status.ATTACHED){
161
+ log('Strophe connection attached');
162
+ return;
163
+ }
164
+
165
+ if (status == Strophe.Status.AUTHENTICATING ){
130
166
  log('Strophe connection AUTHENTICATING');
131
- return;
167
+ return;
132
168
  }
133
-
134
- if (status == Strophe.Status.CONNECTING) {
169
+
170
+ if (status == Strophe.Status.CONNECTING) {
135
171
  log('Strophe is connecting.');
136
- return;
172
+ return;
137
173
  }
138
-
139
- if (status == Strophe.Status.DISCONNECTING) {
174
+
175
+ if (status == Strophe.Status.DISCONNECTING) {
140
176
  log('Strophe is disconnecting.');
141
177
  return;
142
178
  }
143
-
144
- clearTimeout(initialTimer);
145
-
146
- if (status == Strophe.Status.CONNFAIL) {
179
+
180
+ clearTimeout(initialTimer);
181
+
182
+ if (status == Strophe.Status.CONNFAIL) {
147
183
  log('Strophe failed to connect.');
148
184
  reconnectTimer = setTimeout ("onReconnect()", 5000);
149
- disconnectionFlag = true;
185
+ disconnectionFlag = true;
150
186
  } else if (status == Strophe.Status.AUTHFAIL) {
151
187
  log('Strophe authentication fail.');
152
- if ((window.sessionStorage)&&(sessionStorage.getItem("ss_user_pass") != null)){
153
- sessionStorage.setItem("ss_user_pass",null);
154
- }
155
- disconnectionFlag = true;
188
+ if ((window.sessionStorage)&&(sessionStorage.getItem("ss_user_pass") != null)){
189
+ sessionStorage.setItem("ss_user_pass",null);
190
+ }
191
+ disconnectionFlag = true;
156
192
  } else if (status == Strophe.Status.ERROR) {
157
193
  log('Strophe error.');
158
- disconnectionFlag = true;
194
+ disconnectionFlag = true;
159
195
  } else if (status == Strophe.Status.DISCONNECTED) {
160
196
  log('Strophe is disconnected.');
161
- disconnectionFlag = true;
162
- clearTimeout(awayTimer);
163
- notifyWhenUsersDisconnect();
164
- reconnectTimer = setTimeout ("onReconnect()", 5000);
197
+ disconnectionFlag = true;
198
+ clearTimeout(awayTimer);
199
+ notifyWhenUsersDisconnect();
200
+ reconnectTimer = setTimeout ("onReconnect()", 5000);
165
201
  } else if (status == Strophe.Status.CONNECTED) {
202
+ //AFTER CONNECT ACTIONS
203
+
166
204
  log('Strophe is connected.');
167
- log('Presenze stanza send for:' + connection.jid);
168
- clearTimeout(reconnectTimer);
169
- connection.addHandler(onMessage, null, 'message', null, null, null);
170
- connection.addHandler(onPresence, null, 'presence', null, null, null);
205
+
206
+ clearTimeout(reconnectTimer);
207
+
171
208
  //addHandler:(callback, namespace to match, stanza name, stanza type, stanza id , stanza from, options)
172
- disconnectionFlag = false;
173
- userStatus = "chat";
174
- sendStatus(userStatus);
209
+ connection.addHandler(onMessage, null, 'message', null, null, null);
210
+ connection.addHandler(onPresence, null, 'presence', null, null, null);
211
+
212
+ disconnectionFlag = false;
213
+ afterNewConnectionFlag = true;
214
+
215
+ log('Presenze stanza send for:' + connection.jid);
216
+ userStatus = getRestoreUserChatStatus();
217
+ if(userStatus=="offline"){
218
+ userStatus="chat";
219
+ }
220
+ sendStatus(userStatus);
221
+
175
222
  awayTimer = setInterval("awayTimerFunction()", awayTimerPeriod);
176
- timer = setInterval("timerFunction()", timerPeriod);
177
- hideAllNotifications();
223
+ timer = setInterval("timerFunction()", timerPeriod);
224
+
225
+ hideAllNotifications();
178
226
  }
179
-
180
- updateChatWindow();
227
+
228
+ updateChatWindow();
181
229
  }
182
230
 
183
231
  function onReconnect(){
184
-
185
- if ((!isStropheConnected())&&(userStatus!="offline")) {
186
-
187
- if (reconnectAttempts>0) {
188
- reconnectAttempts--;
232
+
233
+ if ((!isStropheConnected())&&(userStatus!="offline")) {
234
+
235
+ if (reconnectAttempts>0) {
236
+ reconnectAttempts--;
237
+
238
+ $("#chat_header_title").html('<%=I18n.t('chat.reconnecting')%>')
189
239
 
190
- $("#chat_header_title").html(I18n.t('chat.reconnecting'))
240
+ connectToChat(user_jid,cookie,null);
191
241
 
192
- if (authByCookie()){
193
- //Authentication by cookie
194
- connectToServerWithCookie();
195
- } else {
196
- //Authentication by password
197
- connectToServerWithPassword(null);
198
- }
199
242
  reconnectTimer = setTimeout ("onReconnect()", 9000);
200
- } else {
201
- $("#chat_header_title").html(I18n.t('chat.unableconnect'))
202
- //Notify issue to Rails App Server?
203
- }
204
-
205
- }
243
+
244
+ } else {
245
+ $("#chat_header_title").html('<%=I18n.t('chat.unableconnect')%>')
246
+ //Notify issue to Rails App Server?
247
+ }
248
+
249
+ }
206
250
  }
207
251
 
208
252
  function disconnectStrophe(){
209
- userStatus = "offline";
210
- setStatusWidgetTitle("offline");
211
-
212
- if(isStropheConnected()){
213
- connection.send($pres({type: "unavailable"}).tree());
253
+ userStatus = "offline";
254
+ setStatusWidgetTitle("offline");
255
+
256
+ if(isStropheConnected()){
257
+ connection.send($pres({type: "unavailable"}).tree());
214
258
  connection.disconnect();
215
- }
259
+ }
216
260
  }
217
261
 
218
262
  ////////
@@ -225,11 +269,11 @@ function onMessage(msg) {
225
269
  var elems = msg.getElementsByTagName('body');
226
270
 
227
271
  if (type == "chat" && elems.length > 0) {
228
- var body = elems[0];
229
- var from_slug = from.split("@")[0];
230
- var from_jid = from_slug + "@" + domain;
231
-
232
- putReceivedMessageOnChatWindow(from_jid,from_slug,body,null)
272
+ var body = elems[0];
273
+ var from_slug = from.split("@")[0];
274
+ var from_jid = from_slug + "@" + domain;
275
+
276
+ putReceivedMessageOnChatWindow(from_jid,from_slug,body,null)
233
277
  }
234
278
 
235
279
  // we must return true to keep the handler alive.
@@ -242,56 +286,56 @@ function onMessage(msg) {
242
286
  //Manage Presence stanzas
243
287
  ///////
244
288
  function onPresence(presence) {
245
-
246
- //Check presence stanza type
247
- ptype = $(presence).attr('type');
248
-
249
- switch (ptype){
250
- case undefined:
251
- processAvailablePresenceStanza(presence)
252
- break;
253
- case "available":
254
- processAvailablePresenceStanza(presence)
289
+
290
+ //Check presence stanza type
291
+ ptype = $(presence).attr('type');
292
+
293
+ switch (ptype){
294
+ case undefined:
295
+ processAvailablePresenceStanza(presence)
296
+ break;
297
+ case "available":
298
+ processAvailablePresenceStanza(presence)
255
299
  break;
256
- case "unavailable":
300
+ case "unavailable":
257
301
  processUnavailablePresenceStanza(presence)
258
302
  break;
259
- default :
260
- //Stanza type not recognize
261
- processAvailablePresenceStanza(presence)
262
- }
263
-
264
- return true;
303
+ default :
304
+ //Stanza type not recognize
305
+ processAvailablePresenceStanza(presence)
306
+ }
307
+
308
+ return true;
265
309
  }
266
310
 
267
311
 
268
312
  function processAvailablePresenceStanza(presence){
269
- from = $(presence).attr('from');
313
+ from = $(presence).attr('from');
270
314
  slug = from.split("@")[0];
271
-
272
- if (slug != user_slug) {
273
- if (getConnectionBoxFromSlug(slug)!=null){
274
- status = $(presence).find('show').text();
315
+
316
+ if (slug != user_slug) {
317
+ if (getConnectionBoxFromSlug(slug)!=null){
318
+ status = $(presence).find('show').text();
275
319
  setUserIconStatus(slug, status);
276
- if (cacheConnectedUsers.indexOf(slug) != -1) {
277
- showConnectionBoxFromSlug(slug);
278
- hideChatNotificationForSlug(slug);
279
- }
280
- } else {
281
- setTimeout("refreshChatWindow()", 3000);
282
- }
283
- }
320
+ if (cacheConnectedUsers.indexOf(slug) != -1) {
321
+ showConnectionBoxFromSlug(slug);
322
+ hideChatNotificationForSlug(slug);
323
+ }
324
+ } else {
325
+ setTimeout("refreshChatWindow()", 3000);
326
+ }
327
+ }
284
328
  }
285
329
 
286
330
  function processUnavailablePresenceStanza(presence){
287
- from = $(presence).attr('from');
331
+ from = $(presence).attr('from');
288
332
  slug = from.split("@")[0];
289
-
290
- if (slug != user_slug) {
291
- if (getConnectionBoxFromSlug(slug)!=null){
292
- hideConnectionBoxFromSlug(slug)
293
- showChatNotificationForSlug(slug,$(getConnectionBoxFromSlug(slug)).attr("name") + " is offline");
294
- }
333
+
334
+ if (slug != user_slug) {
335
+ if (getConnectionBoxFromSlug(slug)!=null){
336
+ hideConnectionBoxFromSlug(slug)
337
+ showChatNotificationForSlug(slug,$(getConnectionBoxFromSlug(slug)).attr("name") + " is offline");
338
+ }
295
339
  }
296
340
  }
297
341
 
@@ -303,9 +347,9 @@ function sendChatMessage(from,to,text){
303
347
  var body= $build("body");
304
348
  body.t(text);
305
349
  var message = $msg({to: to, from: from, type: 'chat'}).cnode(body.tree());
306
- connection.send(message.tree());
307
- restartAwayTimer(false);
308
- return true;
350
+ connection.send(message.tree());
351
+ restartAwayTimer();
352
+ return true;
309
353
  }
310
354
 
311
355
 
@@ -313,6 +357,11 @@ function sendChatMessage(from,to,text){
313
357
  //Send Presence stanzas with status
314
358
  ///////
315
359
  function sendStatus(status){
360
+
361
+ if((status in sstreamChatStatus)){
362
+ status = sstreamChatStatus[status];
363
+ }
364
+
316
365
  if (status in statusMessage){
317
366
  //Send status to the XMPP Server
318
367
  var pres = $pres()
@@ -321,6 +370,6 @@ function sendStatus(status){
321
370
  .c('show')
322
371
  .t(status);
323
372
  connection.send(pres.tree());
324
- setStatusWidgetTitle(status);
373
+ setStatusWidgetTitle(status);
325
374
  }
326
- }
375
+ }