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.
@@ -1,17 +1,3 @@
1
- ////////////////////
2
- //Hash table
3
- ////////////////////
4
-
5
- //Keys: Xmpp status
6
- //Value: Social Stream Status
7
- var statusIcons = new Array();
8
- statusIcons[''] = "available";
9
- statusIcons['chat'] = "available";
10
- statusIcons['away'] = "away";
11
- statusIcons['xa'] = "away";
12
- statusIcons['dnd'] = "dnd";
13
-
14
-
15
1
  ////////////////////
16
2
  //Reconnect button interface functions
17
3
  ////////////////////
@@ -21,18 +7,18 @@ var periodBetweenAttempts=15; //(seg)
21
7
  var connectButtonTimerCounter=periodBetweenAttempts+1;
22
8
 
23
9
  function connectButtonTimerFunction(){
24
- connectButtonTimerCounter++;
25
- if (connectButtonTimerCounter > (periodBetweenAttempts-1)) {
26
- clearTimeout(connectButtonTimer);
27
- $("#chat_header_title").html(I18n.t('chat.disconnected'))
28
- }
10
+ connectButtonTimerCounter++;
11
+ if (connectButtonTimerCounter > (periodBetweenAttempts-1)) {
12
+ clearTimeout(connectButtonTimer);
13
+ $("#chat_header_title").html('<%=I18n.t('chat.disconnected')%>')
14
+ }
29
15
  }
30
16
 
31
17
  function requestConnectToChat(){
32
18
  if (connectButtonTimerCounter > (periodBetweenAttempts-1)) {
33
19
  connectButtonTimerCounter=0;
34
- connectButtonTimer = setInterval("connectButtonTimerFunction()", 1000)
35
- $("#chat_header_title").html(I18n.t('chat.connecting'))
20
+ connectButtonTimer = setInterval("connectButtonTimerFunction()", 1000)
21
+ $("#chat_header_title").html('<%=I18n.t('chat.connecting')%>')
36
22
  return true
37
23
  } else {
38
24
  return false
@@ -45,48 +31,48 @@ function requestConnectToChat(){
45
31
  ////////////////////
46
32
 
47
33
  function setUserFunctions(){
48
-
49
- $("div.user_presence").click(function(event, ui){
50
- var guest_name = $(this).attr("name");
51
- var guest_slug = $(this).attr("slug");
52
- var guest_jid = guest_slug + "@" + domain;
53
-
54
- if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
55
- } else {
56
- window[getChatVariableFromSlug(guest_slug)].chatbox("option", "boxManager").toggleBox(true);
57
- };
58
- });
59
-
60
-
34
+
35
+ $("div.user_presence").click(function(event, ui){
36
+ var guest_name = $(this).attr("name");
37
+ var guest_slug = $(this).attr("slug");
38
+ var guest_jid = guest_slug + "@" + domain;
39
+
40
+ if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
41
+ } else {
42
+ window[getChatVariableFromSlug(guest_slug)].chatbox("option", "boxManager").toggleBox(true);
43
+ };
44
+ });
45
+
46
+
61
47
  ////////////////////
62
48
  //Chat interface: Status selector
63
49
  ////////////////////
64
50
 
65
- //JQuery DropdwanStatus
66
-
67
- $(".dropdown dt a").click(function(event) {
68
- event.preventDefault();
51
+ //JQuery DropdwanStatus
52
+
53
+ $(".dropdown dt a").click(function(event) {
54
+ event.preventDefault();
69
55
  $(".dropdown dd ul").toggle();
70
-
71
- if($(".dropdown dd ul").is(":visible")){
72
- setStatusWidgetTitle("default");
73
- } else {
74
- setStatusWidgetTitle(userStatus);
75
- }
76
-
77
- restartAwayTimer(false);
78
-
56
+
57
+ if($(".dropdown dd ul").is(":visible")){
58
+ setStatusWidgetTitle("default");
59
+ } else {
60
+ setStatusWidgetTitle(userStatus);
61
+ }
62
+
63
+ restartAwayTimer();
64
+
79
65
  });
80
66
 
81
67
  $(".dropdown dd ul li a.option").click(function(event) {
82
- event.preventDefault();
83
- userStatus = $(this).find("span.value").html();
84
- if(userStatus == "offline"){
85
- disconnectStrophe();
86
- } else {
87
- sendStatus(userStatus);
88
- }
89
- $(".dropdown dd ul").hide();
68
+ event.preventDefault();
69
+ userStatus = $(this).find("span.value").html();
70
+ if(userStatus == "offline"){
71
+ disconnectStrophe();
72
+ } else {
73
+ sendStatus(userStatus);
74
+ }
75
+ $(".dropdown dd ul").hide();
90
76
  });
91
77
 
92
78
 
@@ -95,35 +81,40 @@ function setUserFunctions(){
95
81
  if (! $clicked.parents().hasClass("dropdown")){
96
82
  //Click outside the select...
97
83
  $(".dropdown dd ul").hide();
98
- setStatusWidgetTitle(userStatus);
84
+ setStatusWidgetTitle(userStatus);
99
85
  }
100
86
  });
101
-
87
+
102
88
  }
103
89
 
104
90
  function setStatusWidgetTitle(status){
105
-
106
- if ($(".dropdown dt a span").length == 0){
107
- return;
91
+
92
+ if((status in sstreamChatStatus)){
93
+ status = sstreamChatStatus[status];
108
94
  }
109
95
 
110
- if(status=="default"){
111
- var defaultTitle = I18n.t('chat.status.choose');
96
+
97
+ if ($(".dropdown dt a span").length == 0){
98
+ return;
99
+ }
100
+
101
+ if(status=="default"){
102
+ var defaultTitle = '<%=I18n.t('chat.status.choose')%>'
112
103
  $(".dropdown dt a span").html(defaultTitle);
113
- return;
104
+ return;
114
105
  }
115
-
116
- if(status=="offline"){
117
- var text = $("#" + status).html();
106
+
107
+ if(status=="offline"){
108
+ var text = $("#" + status).html();
118
109
  $(".dropdown dt a span").html(text);
119
- return;
120
- }
121
-
122
- if ((status in statusIcons)&&($("#" + statusIcons[status]).length > 0)) {
123
- var text = $("#" + statusIcons[status]).html();
110
+ return;
111
+ }
112
+
113
+ if ((status in statusIcons)&&($("#" + statusIcons[status]).length > 0)) {
114
+ var text = $("#" + statusIcons[status]).html();
124
115
  $(".dropdown dt a span").html(text);
125
116
  }
126
-
117
+
127
118
  }
128
119
 
129
120
 
@@ -132,34 +123,29 @@ function setStatusWidgetTitle(status){
132
123
  ////////////////////
133
124
 
134
125
  function awayTimerFunction(){
135
- awayCounter++;
136
- if (awayCounter > (awayTime/awayTimerPeriod)){
137
- if (userStatus != "dnd") {
138
- userStatus = "away";
139
- sendStatus(userStatus);
140
- }
141
- clearTimeout(awayTimer);
142
- }
126
+ awayCounter++;
127
+ if (awayCounter > (awayTime/awayTimerPeriod)){
128
+ if ((userStatus != "dnd")&&(userStatus != "away")) {
129
+ userStatus = "autoaway";
130
+ sendStatus(userStatus);
131
+ }
132
+ clearTimeout(awayTimer);
133
+ }
143
134
  }
144
135
 
145
- function autochangeStatusOnUserAway(){
146
- if (userStatus == "away"){
147
- userStatus = "chat";
136
+ function autochangeStatusIfAutoAway(){
137
+ if (userStatus == "autoaway"){
138
+ userStatus = "available";
148
139
  sendStatus(userStatus);
149
140
  }
150
141
  }
151
142
 
152
- function restartAwayTimer(autochangeStatus){
153
-
154
- if (awayCounter > (awayTime/awayTimerPeriod)){
155
- awayTimer = setInterval("awayTimerFunction()", awayTimerPeriod);
156
-
157
- if(autochangeStatus){
158
- autochangeStatusOnUserAway();
159
- }
160
- }
161
-
162
- awayCounter = 0;
143
+ function restartAwayTimer(){
144
+ if (awayCounter > (awayTime/awayTimerPeriod)){
145
+ awayTimer = setInterval("awayTimerFunction()", awayTimerPeriod);
146
+ autochangeStatusIfAutoAway();
147
+ }
148
+ awayCounter = 0;
163
149
  }
164
150
 
165
151
 
@@ -168,82 +154,86 @@ function restartAwayTimer(autochangeStatus){
168
154
  ////////////////////
169
155
 
170
156
  function timerFunction(){
171
- timerCounter++;
172
-
157
+ timerCounter++;
158
+
173
159
  if((timerCounter > cyclesToRefresh)&&(requestContacts)) {
174
160
  requestContacts = false;
175
161
  updateChatWindow();
176
- }
162
+ }
177
163
  }
178
164
 
179
165
 
180
166
  function refreshChatWindow(){
181
- if(timerCounter > cyclesToRefresh){
182
- updateChatWindow();
183
- } else {
184
- requestContacts = true;
185
- }
167
+ if(timerCounter > cyclesToRefresh){
168
+ updateChatWindow();
169
+ } else {
170
+ requestContacts = true;
171
+ }
186
172
  }
187
173
 
188
174
 
189
175
  function updateChatWindow(){
190
- timerCounter=0;
191
- log("updateChatWindow()");
192
- var stropheConnectedAndOnlineStatus = ((isStropheConnected()) && (userStatus!="offline") && (!disconnectionFlag));
176
+ timerCounter=0;
177
+ log("updateChatWindow()");
178
+ var stropheConnectedAndOnlineStatus = ((isStropheConnected()) && (userStatus!="offline") && (!disconnectionFlag));
193
179
  $.post("/chatWindow", { userConnected: stropheConnectedAndOnlineStatus }, function(data){
194
- $(".tooltip").hide() //Prevent tooltips
180
+ $(".tooltip").hide() //Prevent tooltips
195
181
  $("#chat_partial").html(data);
196
182
  if (isStropheConnected()) {
197
- setStatusWidgetTitle(userStatus);
183
+ setStatusWidgetTitle(userStatus);
198
184
  $(".user_presence a[title]").tooltip();
199
185
  setUserFunctions();
186
+ if (afterNewConnectionFlag){
187
+ afterNewConnectionFlag = false;
188
+ restoreChatData();
189
+ }
200
190
  }
201
191
  });
202
192
  }
203
193
 
204
194
  function getConnectionBoxFromSlug(slug){
205
- if ($('div.user_presence[slug=' + slug + ']').length > 0){
206
- return ($('div.user_presence[slug=' + slug + ']'))[0];
207
- } else {
208
- return null;
209
- }
195
+ if ($('div.user_presence[slug=' + slug + ']').length > 0){
196
+ return ($('div.user_presence[slug=' + slug + ']'))[0];
197
+ } else {
198
+ return null;
199
+ }
210
200
  }
211
201
 
212
202
  var cacheConnectedUsers = [];
213
203
  function hideConnectionBoxFromSlug(slug){
214
204
  if ($('div.user_presence[slug=' + slug + ']').length > 0){
215
205
  $('div.user_presence[slug=' + slug + ']').hide();
216
- if(cacheConnectedUsers.indexOf(slug)==-1){
217
- cacheConnectedUsers.push(slug);
218
- }
206
+ if(cacheConnectedUsers.indexOf(slug)==-1){
207
+ cacheConnectedUsers.push(slug);
208
+ }
219
209
  }
220
210
  }
221
211
 
222
212
  function showConnectionBoxFromSlug(slug){
223
213
  if ($('div.user_presence[slug=' + slug + ']').length > 0){
224
- if (!($('div.user_presence[slug=' + slug + ']').is(":visible"))){
225
- $('div.user_presence[slug=' + slug + ']').show();
226
- }
214
+ if (!($('div.user_presence[slug=' + slug + ']').is(":visible"))){
215
+ $('div.user_presence[slug=' + slug + ']').show();
216
+ }
227
217
  }
228
218
  }
229
219
 
230
220
  function setUserIconStatus(slug, status){
231
- if (status in statusIcons) {
232
- iconName = statusIcons[status];
233
- var $img_status = $('img.presence_status');
234
- connectionBox = getConnectionBoxFromSlug(slug);
221
+ if (status in statusIcons) {
222
+ iconName = statusIcons[status];
223
+ var $img_status = $('img.presence_status');
224
+ connectionBox = getConnectionBoxFromSlug(slug);
235
225
  $(connectionBox).find($img_status).attr("src", "/assets/status/" + iconName + ".png")
236
226
  }
237
227
  }
238
228
 
239
229
  function getAllConnectedSlugs(){
240
- connectedSlugs=[];
230
+ connectedSlugs=[];
241
231
  connectionBoxes = $('div.user_presence[slug]');
242
- $.each(connectionBoxes, function(index, value) {
243
- if($(value).is(":visible")){
244
- connectedSlugs.push($(value).attr("slug"))
245
- }
246
- });
232
+ $.each(connectionBoxes, function(index, value) {
233
+ if($(value).is(":visible")){
234
+ connectedSlugs.push($(value).attr("slug"))
235
+ }
236
+ });
247
237
  return connectedSlugs
248
238
  }
249
239
 
@@ -253,47 +243,47 @@ function getAllConnectedSlugs(){
253
243
  ////////////////////
254
244
 
255
245
  function putReceivedMessageOnChatWindow(from_jid,from_slug,body,msgID){
256
-
257
- //Antiflood control
258
- if (antifloodControl(from_jid,from_slug,body,msgID)){
259
- return;
260
- }
261
-
262
- //Check for from_slug name and connectionBox visibility
263
- if (typeof($('div.user_presence[slug=' + from_slug + ']').attr('name')) == 'undefined') {
264
- //No connectionBox for this user!
265
- var from_name = from_slug;
266
- refreshChatWindow();
267
- } else {
268
- showConnectionBoxFromSlug(from_slug);
269
- var from_name = $('div.user_presence[slug=' + from_slug + ']').attr('name');
270
- }
271
-
272
-
273
- //Create or toggle from_slug's chatBox.
274
- if (createChatBox(from_slug, from_name, from_jid, user_name, user_jid)) {
275
- } else {
276
- window[getChatVariableFromSlug(from_slug)].chatbox("option", "boxManager").toggleBox(true);
277
- }
278
-
279
- //Parse content before show it.
280
- var content = getParsedContent(Strophe.getText(body), false)
281
- var headerMessage = getParsedName(from_name,false);
282
-
283
- //Show message to chatBox.
284
- $("#" + from_slug).chatbox("option", "boxManager").addMsg(headerMessage, content);
285
-
286
- //Rotate chatBoxes priority.
287
- rotatePriority(from_slug);
288
-
289
- //Check for start blinkTitle.
290
- blinkTitleOnMessage(from_name);
291
-
292
- //Check for play sound
293
- if (mustPlaySoundForChatWindow(window[getChatVariableFromSlug(from_slug)])) {
294
- playSound("onMessageAudio");
295
- }
296
-
246
+
247
+ //Antiflood control
248
+ if (antifloodControl(from_jid,from_slug,body,msgID)){
249
+ return;
250
+ }
251
+
252
+ //Check for from_slug name and connectionBox visibility
253
+ if (typeof($('div.user_presence[slug=' + from_slug + ']').attr('name')) == 'undefined') {
254
+ //No connectionBox for this user!
255
+ var from_name = from_slug;
256
+ refreshChatWindow();
257
+ } else {
258
+ showConnectionBoxFromSlug(from_slug);
259
+ var from_name = $('div.user_presence[slug=' + from_slug + ']').attr('name');
260
+ }
261
+
262
+
263
+ //Create or toggle from_slug's chatBox.
264
+ if (createChatBox(from_slug, from_name, from_jid, user_name, user_jid)) {
265
+ } else {
266
+ window[getChatVariableFromSlug(from_slug)].chatbox("option", "boxManager").toggleBox(true);
267
+ }
268
+
269
+ //Parse content before show it.
270
+ var content = getParsedContent(Strophe.getText(body), false)
271
+ var headerMessage = getParsedName(from_name,false);
272
+
273
+ //Show message to chatBox.
274
+ $("#" + from_slug).chatbox("option", "boxManager").addMsg(headerMessage, content);
275
+
276
+ //Rotate chatBoxes priority.
277
+ rotatePriority(from_slug);
278
+
279
+ //Check for start blinkTitle.
280
+ blinkTitleOnMessage(from_name);
281
+
282
+ //Check for play sound
283
+ if (mustPlaySoundForChatWindow(window[getChatVariableFromSlug(from_slug)])) {
284
+ playSound("onMessageAudio");
285
+ }
286
+
297
287
  }
298
288
 
299
289
 
@@ -302,8 +292,8 @@ function putReceivedMessageOnChatWindow(from_jid,from_slug,body,msgID){
302
292
  ////////////////////
303
293
 
304
294
  function showChatNotificationForSlug(slug,msg){
305
- var notification = $("#" + slug).parent().find("div.ui-chatbox-notify");
306
- showChatNotification(notification,msg);
295
+ var notification = $("#" + slug).parent().find("div.ui-chatbox-notify");
296
+ showChatNotification(notification,msg);
307
297
  }
308
298
 
309
299
  function showChatNotification(notification,msg){
@@ -314,7 +304,7 @@ function showChatNotification(notification,msg){
314
304
 
315
305
  function hideChatNotificationForSlug(slug){
316
306
  var notification = $("#" + slug).parent().find("div.ui-chatbox-notify");
317
- hideChatNotification(notification);
307
+ hideChatNotification(notification);
318
308
  }
319
309
 
320
310
  function hideChatNotification(notification){
@@ -323,12 +313,12 @@ function hideChatNotification(notification){
323
313
  }
324
314
 
325
315
  function notifyWhenUsersDisconnect(){
326
- var notification = $("div.ui-chatbox-notify");
327
- var msg = I18n.t('chat.notify.offline');
328
- showChatNotification(notification,msg);
316
+ var notification = $("div.ui-chatbox-notify");
317
+ var msg = '<%=I18n.t('chat.notify.offline')%>';
318
+ showChatNotification(notification,msg);
329
319
  }
330
320
 
331
321
  function hideAllNotifications(){
332
- var notification = $("div.ui-chatbox-notify");
322
+ var notification = $("div.ui-chatbox-notify");
333
323
  hideChatNotification(notification);
334
- }
324
+ }