social_stream-presence 0.8.4 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. data/app/assets/javascripts/chat_interface_manager.js.erb +42 -132
  2. data/app/assets/javascripts/chat_persistence.js +84 -70
  3. data/app/assets/javascripts/chat_utilities.js +10 -33
  4. data/app/assets/javascripts/chat_window_manager.js +275 -217
  5. data/app/assets/javascripts/jquery.ui.chatbox.sstreampresence.js +9 -2
  6. data/app/assets/javascripts/notifications.js +191 -0
  7. data/app/assets/javascripts/social_stream-presence.js +1 -0
  8. data/app/assets/javascripts/videochat.js.erb +4 -24
  9. data/app/assets/javascripts/xmpp_client_management.js.erb +369 -47
  10. data/app/assets/stylesheets/chat.css.scss +1 -1
  11. data/app/views/chat/_contacts.html.erb +5 -5
  12. data/app/views/chat/_index.html.erb +10 -2
  13. data/config/locales/en.yml +9 -1
  14. data/config/locales/es.yml +9 -1
  15. data/ejabberd/ejabberd_files.zip +0 -0
  16. data/ejabberd/ejabberd_scripts/emanagement +132 -2
  17. data/ejabberd/installer.sh +1 -0
  18. data/ejabberd/mod_muc_admin/mod_muc_admin.beam +0 -0
  19. data/ejabberd/mod_muc_admin/mod_muc_admin.erl +871 -0
  20. data/ejabberd/mod_sspresence/mod_sspresence.beam +0 -0
  21. data/lib/social_stream-presence.rb +1 -1
  22. data/lib/social_stream/presence/engine.rb +6 -0
  23. data/lib/social_stream/presence/models/buddy_manager.rb +32 -26
  24. data/lib/social_stream/presence/models/group_manager.rb +51 -0
  25. data/lib/social_stream/presence/version.rb +1 -1
  26. data/lib/social_stream/presence/xmpp_server_order.rb +84 -10
  27. data/lib/tasks/presence/synchronize.rake +15 -0
  28. data/vendor/assets/javascripts/strophe.muc.js +934 -0
  29. metadata +9 -24
@@ -1,8 +1,6 @@
1
- var global;
2
1
  ////////////////////
3
2
  //Reconnect button interface functions
4
3
  ////////////////////
5
-
6
4
  var connectButtonTimer;
7
5
  var periodBetweenAttempts=15; //(seg)
8
6
  var connectButtonTimerCounter=periodBetweenAttempts+1;
@@ -38,11 +36,9 @@ function changeChatHeaderTitle(msg){
38
36
  ////////////////////
39
37
  //Chat interface: Setting Functions
40
38
  ////////////////////
41
-
42
39
  var focusSearchContactsFlag=false;
43
40
  var changeSelectContactValueFlag = false;
44
41
 
45
-
46
42
  function settingStatusSelector(){
47
43
  //JQuery DropdwanStatus
48
44
  $(".dropdown dt a").click(function(event) {
@@ -81,18 +77,11 @@ function settingStatusSelector(){
81
77
  });
82
78
  }
83
79
 
84
-
85
80
  function settingChatBoxFunctions(){
86
81
 
87
82
  $("div.user_presence").click(function(event, ui){
88
- var guest_name = $(this).attr("name");
89
83
  var guest_slug = $(this).attr("slug");
90
- var guest_jid = guest_slug + "@" + domain;
91
-
92
- if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
93
- } else {
94
- getChatBoxForSlug(guest_slug).chatbox("option", "boxManager").toggleBox(true);
95
- };
84
+ createBuddyChatBox(guest_slug)
96
85
  });
97
86
 
98
87
  //Hide tooltips on mouseleave
@@ -161,18 +150,11 @@ function setAllUserFunctions(){
161
150
  settingTooltips();
162
151
  }
163
152
 
164
-
165
153
  function changeSelectContactValue(name,valueSelectedInSearchContacts){
166
154
 
167
155
  if((valueSelectedInSearchContacts != "ZERO_CONTACTS")&&(valueSelectedInSearchContacts != "")){
168
156
  var guest_slug = valueSelectedInSearchContacts;
169
- var guest_name = getNameFromSlug(guest_slug);
170
- var guest_jid = guest_slug + "@" + domain;
171
-
172
- if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
173
- } else {
174
- window[getChatVariableFromSlug(guest_slug)].chatbox("option", "boxManager").toggleBox(true);
175
- };
157
+ createBuddyChatBox(guest_slug)
176
158
 
177
159
  //Check for online status and show notification
178
160
  if (! isSlugChatConnected(guest_slug)) {
@@ -184,7 +166,6 @@ function changeSelectContactValue(name,valueSelectedInSearchContacts){
184
166
  changeContactListVisibility(false);
185
167
  }
186
168
 
187
-
188
169
  function changeContactListVisibility(visible){
189
170
  var nItems = getAllSlugsLength();
190
171
  if (visible){
@@ -202,7 +183,6 @@ function changeContactListVisibility(visible){
202
183
  }
203
184
  }
204
185
 
205
-
206
186
  function setStatusWidgetTitle(status){
207
187
 
208
188
  if((status in sstreamChatStatus)){
@@ -279,7 +259,7 @@ function updateChatWindow(){
279
259
  updateConnectedUsersOfMainChatBox();
280
260
  return;
281
261
  }
282
-
262
+
283
263
  $.post("/chatWindow", { }, function(data){
284
264
  //Prevent tooltips
285
265
  $(".tooltip").hide()
@@ -293,13 +273,21 @@ function updateChatWindow(){
293
273
  afterNewConnectionFlag = false;
294
274
  if(afterFirstConnectionFlag){
295
275
  restoreChatData();
276
+ if(typeof current_group_slug != 'undefined') {
277
+ accessRoom(current_group_slug,false);
278
+ }
296
279
  afterFirstConnectionFlag = false;
297
280
  } else {
298
281
  updateAllNotifications();
282
+ //Rejoin rooms
283
+ $.each(getAllSlugsWithVisibleGroupBoxes(), function(index, value) {
284
+ accessRoom(value,$(value).is(":visible"))
285
+ });
299
286
  }
300
287
  }
301
288
  }
302
- });
289
+ },'html');
290
+
303
291
  }
304
292
 
305
293
 
@@ -341,7 +329,6 @@ function loadDisconnectionDiv(){
341
329
  }
342
330
  }
343
331
 
344
-
345
332
  function loadWidgetsDiv(data){
346
333
  $("#chat_partial").html(modifyChatPartialIfMainBox($("#chat_widgets").html()));
347
334
  $("#chat_partial").append(data);
@@ -357,7 +344,13 @@ function fillSearchContactSelect(){
357
344
  });
358
345
  }
359
346
 
360
-
347
+ function updateInterfaceAfterUserDisconnect(){
348
+ updateNotificationsAfterUserDisconnect();
349
+ $.each(getAllSlugsWithVisibleVideoBoxes(), function(index, value) {
350
+ closeVideoSession(value);
351
+ });
352
+
353
+ }
361
354
 
362
355
  /////////////////////
363
356
  // Connection Box Management
@@ -436,7 +429,7 @@ function isSlugChatConnected(slug){
436
429
  }
437
430
 
438
431
  function existsSlugChatBox(slug){
439
- return getConnectionBoxFromSlug(slug)!=null;
432
+ return getChatBoxForSlug(slug)!=null;
440
433
  }
441
434
 
442
435
  function getConnectedSlugsLength(){
@@ -485,36 +478,33 @@ function getAllSlugsByChatConnectedState(){
485
478
  //Insert received message in chatbox
486
479
  ////////////////////
487
480
 
488
- function putReceivedMessageOnChatWindow(from_jid,from_slug,body,msgID){
489
-
481
+ function afterReceivedChatMessage(from_slug,msg,msgID){
490
482
  //Antiflood control
491
- if (antifloodControl(from_jid,from_slug,body,msgID)){
483
+ if (antifloodControl(from_slug,msg,msgID)){
492
484
  return;
493
- }
494
-
495
- //Check slugs connectionBox
496
- if (!existsSlugChatBox(from_slug)) {
497
- //No connectionBox for this user!
498
- var from_name = getNameFromSlug(from_slug);
499
- if(! isAdminSlug(from_slug)){
500
- updateChatWindow();
501
- }
502
- } else {
503
- var from_name = $('div.user_presence[slug=' + from_slug + ']').attr('name');
485
+ }
486
+ var from_name = getNameFromSlug(from_slug)
487
+ createBuddyChatBox(from_slug)
488
+ writeReceivedMessageOnChatWindow(from_name,from_slug,msg)
489
+ }
490
+
491
+ function afterReceivedGroupChatMessage(room_nick_jid,msg){
492
+ var from_slug = getSlugFromJid(room_nick_jid)
493
+ var from_name = getNickFromChatRoomJid(room_nick_jid)
494
+
495
+ if(!(existsSlugChatBox(from_slug))){
496
+ createGroupChatBox(from_slug,true)
504
497
  }
498
+ writeReceivedMessageOnChatWindow(from_name,from_slug,msg)
499
+ }
505
500
 
506
- //Create or toggle from_slug's chatBox.
507
- if (createChatBox(from_slug, from_name, from_jid, user_name, user_jid)) {
508
- } else {
509
- window[getChatVariableFromSlug(from_slug)].chatbox("option", "boxManager").toggleBox(true);
510
- }
511
-
501
+ function writeReceivedMessageOnChatWindow(from_name,from_slug,msg){
512
502
  //Parse content before show it.
513
- var content = getParsedContent(Strophe.getText(body), false)
503
+ var content = getParsedContent(msg, false)
514
504
  var headerMessage = getParsedName(from_name,false);
515
505
 
516
- //Show message to chatBox.
517
- $("#" + from_slug).chatbox("option", "boxManager").addMsg(headerMessage, content);
506
+ //Write message in chatBox.
507
+ getChatBoxForSlug(from_slug).chatbox("option", "boxManager").addMsg(headerMessage, content);
518
508
 
519
509
  //Rotate chatBoxes priority.
520
510
  rotatePriority(from_slug);
@@ -523,89 +513,9 @@ function putReceivedMessageOnChatWindow(from_jid,from_slug,body,msgID){
523
513
  blinkTitleOnMessage(from_name);
524
514
 
525
515
  //Check for play sound
526
- if (mustPlaySoundForChatWindow(window[getChatVariableFromSlug(from_slug)])) {
516
+ if (mustPlaySoundForChatWindow(getChatBoxForSlug(from_slug))) {
527
517
  playSound("onMessageAudio");
528
- }
529
-
530
- }
531
-
532
-
533
- ////////////////////
534
- //Notifications on chat Window
535
- ////////////////////
536
-
537
- function showChatNotification(notification,type,msg){
538
- notification.html("<p notification_type=\"" + type + "\" class=\"ui-chatbox-notify-text\">" + msg + "</p>");
539
- notification.css("display","block");
540
- notification.css("visibility","visible");
541
- notification.fadeIn();
542
- }
543
-
544
- function showChatNotificationForSlug(slug,type,msg){
545
- var notification = $("#" + slug).parent().find("div.ui-chatbox-notify");
546
- if(notification.length==1){
547
- showChatNotification(notification,type,msg);
548
- }
549
- }
550
-
551
- function showOfflineChatNotificationForSlug(slug){
552
- var msg = I18n.t("chat.notify.guestOffline", {name: getNameFromSlug(slug)});
553
- showChatNotificationForSlug(slug,"guestOffline",msg);
554
- }
555
-
556
- function showVideoChatNotificationForSlug(slug,msg){
557
- showChatNotificationForSlug(slug,"videochat",msg);
558
- }
559
-
560
- function showVideoChatNotificationForSlugClientIssue(slug){
561
- var msg = I18n.t("chat.notify.videochat.clientIssue", {name: getNameFromSlug(slug)});
562
- showVideoChatNotificationForSlug(slug,msg);
563
- }
564
-
565
- function showVideoChatNotificationForSlugClientOffline(slug){
566
- var msg = I18n.t("chat.notify.videochat.offline", {name: getNameFromSlug(slug)});
567
- showVideoChatNotificationForSlug(slug,msg);
568
- }
569
-
570
- function hideChatNotification(notification){
571
- notification.fadeOut();
572
- notification.css("display","none");
573
- notification.css("visibility","hidden");
574
- }
575
-
576
- function hideChatNotificationForSlug(slug){
577
- var notification = $("#" + slug).parent().find("div.ui-chatbox-notify");
578
- hideChatNotification(notification);
579
- }
580
-
581
- function updateInterfaceAfterUsersDisconnect(){
582
- updateNotificationsAfterUserDisconnect();
583
- $.each(getAllSlugsWithVisibleVideoBoxes(), function(index, value) {
584
- closeVideoSession(value);
585
- });
586
- }
587
-
588
- function updateNotificationsAfterUserDisconnect(){
589
- var notification = $("div.ui-chatbox-notify");
590
- var msg = I18n.t('chat.notify.offline');
591
- showChatNotification(notification,"userOffline",msg);
592
- }
593
-
594
- function hideAllNotifications(){
595
- var notification = $("div.ui-chatbox-notify");
596
- hideChatNotification(notification);
597
- }
598
-
599
- function updateAllNotifications(){
600
- hideAllNotifications();
601
- if(disconnectionFlag){
602
- updateNotificationsAfterUserDisconnect();
603
- } else {
604
- //Notification for offline contacts
605
- $.each(getAllDisconnectedSlugsWithChatBoxes(), function(index, value) {
606
- showOfflineChatNotificationForSlug(value)
607
- });
608
- }
518
+ }
609
519
  }
610
520
 
611
521
 
@@ -2,7 +2,6 @@
2
2
  // Store and restore conversations using session storage.
3
3
  ////////////////////
4
4
 
5
-
6
5
  function storeChatData(){
7
6
 
8
7
  //Check for Session Storage support
@@ -25,19 +24,25 @@ function storeChatStatus(){
25
24
  }
26
25
 
27
26
  function storeConversations() {
28
-
29
27
  var chatboxes = getAllChatBoxes();
30
28
  var visibleChatBoxes = getVisibleChatBoxes();
31
29
  var storedSlugs = [];
30
+ var storedGroupSlugs = [];
32
31
  var visibleMaxSlugs = [];
33
32
  var visibleMinSlugs = [];
34
33
 
35
34
  //Stored all conversations
36
35
  for (var i=0;i<chatboxes.length;i++){
37
36
  var slug = chatboxes[i].id
38
- var log = $(chatboxes[i]).html()
39
- sessionStorage.setItem("chat_log_" + slug, log);
40
- storedSlugs.push(slug)
37
+ if(isSlugGroup(slug)){
38
+ if(visibleChatBoxes.indexOf(getChatBoxForSlug(slug))!=-1){
39
+ storedGroupSlugs.push(slug)
40
+ }
41
+ } else {
42
+ var log = $(chatboxes[i]).html()
43
+ sessionStorage.setItem("chat_log_" + slug, log);
44
+ storedSlugs.push(slug)
45
+ }
41
46
  }
42
47
 
43
48
  if(storedSlugs.length>0){
@@ -47,6 +52,13 @@ function storeConversations() {
47
52
  sessionStorage.setItem("slugs_with_stored_log", null);
48
53
  }
49
54
 
55
+ if(storedGroupSlugs.length>0){
56
+ //Stored open groups slugs
57
+ sessionStorage.setItem("open_group_slugs", storedGroupSlugs.join(","));
58
+ } else {
59
+ sessionStorage.setItem("open_group_slugs", null);
60
+ }
61
+
50
62
  //Stored slugs with visible chatbox
51
63
  for (var j=0;j<visibleChatBoxes.length;j++){
52
64
  if(visibleChatBoxes[j].is(":visible")){
@@ -80,6 +92,7 @@ function removeAllDataStored(){
80
92
  sessionStorage.removeItem("slugs_with_stored_log");
81
93
  sessionStorage.removeItem("slugs_with_visible_max_chatbox");
82
94
  sessionStorage.removeItem("slugs_with_visible_min_chatbox");
95
+ sessionStorage.removeItem("open_group_slugs");
83
96
  }
84
97
 
85
98
  function getRestoreUserChatStatus(){
@@ -95,7 +108,6 @@ function getRestoreUserChatStatus(){
95
108
  }
96
109
  }
97
110
 
98
-
99
111
  function restoreChatData(){
100
112
 
101
113
  //Check for Session Storage support
@@ -103,10 +115,9 @@ function restoreChatData(){
103
115
  return
104
116
  }
105
117
 
106
- restoreConversations();
118
+ restoreChatBoxes();
107
119
  }
108
120
 
109
-
110
121
  function getRestoreMainChatBoxStatus(){
111
122
  if (!window.sessionStorage) {
112
123
  return false;
@@ -119,76 +130,79 @@ function getRestoreMainChatBoxStatus(){
119
130
  }
120
131
  }
121
132
 
122
- function restoreConversations() {
133
+ function restoreChatBoxes(){
123
134
 
124
- //Get Stored slugs
125
- var storedSlugsString = sessionStorage.getItem("slugs_with_stored_log");
135
+ //Get slugs with visible chatbox
136
+ var visibleMaxSlugsString = sessionStorage.getItem("slugs_with_visible_max_chatbox");
137
+ var visibleMinSlugsString = sessionStorage.getItem("slugs_with_visible_min_chatbox");
138
+
139
+ if(visibleMaxSlugsString!=null){
140
+ var visibleMaxSlugs = visibleMaxSlugsString.split(",")
141
+ } else {
142
+ var visibleMaxSlugs = [];
143
+ }
144
+
145
+ if(visibleMinSlugsString!=null){
146
+ var visibleMinSlugs = visibleMinSlugsString.split(",")
147
+ } else {
148
+ var visibleMinSlugs = [];
149
+ }
150
+
151
+ restoreBuddyChatBoxes(visibleMaxSlugs,visibleMinSlugs);
152
+ restoreGroupsChatBoxes(visibleMaxSlugs,visibleMinSlugs);
153
+ }
154
+
155
+ function restoreGroupsChatBoxes(visibleMaxSlugs,visibleMinSlugs){
156
+ var groupSlugsString = sessionStorage.getItem("open_group_slugs")
157
+ if((groupSlugsString != null)&&(groupSlugsString != "null")){
158
+ var groupSlugs=groupSlugsString.split(",")
126
159
 
127
- if (storedSlugsString != null){
128
- var storedSlugs=storedSlugsString.split(",")
129
-
130
- //Get slugs with visible chatbox
131
- var visibleMaxSlugsString = sessionStorage.getItem("slugs_with_visible_max_chatbox");
132
- var visibleMinSlugsString = sessionStorage.getItem("slugs_with_visible_min_chatbox");
133
-
134
- if(visibleMaxSlugsString!=null){
135
- var visibleMaxSlugs = visibleMaxSlugsString.split(",")
136
- } else {
137
- var visibleMaxSlugs = [];
138
- }
139
-
140
- if(visibleMinSlugsString!=null){
141
- var visibleMinSlugs = visibleMinSlugsString.split(",")
142
- } else {
143
- var visibleMinSlugs = [];
144
- }
145
-
160
+ for (var i=0;i<groupSlugs.length;i++){
161
+ var guest_slug = groupSlugs[i]
162
+ var guest_name = getNameFromSlug(guest_slug)
163
+ var open = (visibleMinSlugs.indexOf(guest_slug)==-1)
164
+ accessRoom(guest_slug,open)
165
+ }
166
+ }
167
+ }
168
+
169
+ function restoreBuddyChatBoxes(visibleMaxSlugs,visibleMinSlugs) {
170
+ //Get Stored slugs
171
+ var storedSlugsString = sessionStorage.getItem("slugs_with_stored_log");
172
+
173
+ if (storedSlugsString != null){
174
+ var storedSlugs=storedSlugsString.split(",")
175
+
176
+ for (var i=0;i<storedSlugs.length;i++){
177
+ var restoreLog = sessionStorage.getItem("chat_log_" + storedSlugs[i]);
146
178
 
147
- for (var i=0;i<storedSlugs.length;i++){
148
- var restoreLog = sessionStorage.getItem("chat_log_" + storedSlugs[i]);
179
+ if (restoreLog != null){
180
+
181
+ var guest_slug = storedSlugs[i];
182
+ var guest_name = getNameFromSlug(guest_slug)
183
+ var guest_jid = guest_slug + "@" + domain;
184
+ createBuddyChatBox(guest_slug)
185
+
186
+ if ((visibleMinSlugs.indexOf(guest_slug)!=-1)){
187
+ //Minimize chatbox
188
+ window[getChatVariableFromSlug(guest_slug)].parent().toggle(false);
189
+ }
190
+ if ((visibleMaxSlugs.indexOf(guest_slug)==-1)&&(visibleMinSlugs.indexOf(guest_slug)==-1)){
191
+ closeChatBox(guest_slug);
192
+ }
149
193
 
150
- if (restoreLog != null){
151
-
152
- //Create window (if it not exists)
153
-
154
- var guest_slug = storedSlugs[i];
155
-
156
- //Check for slug name and connectionBox visibility
157
- if (typeof($('div.user_presence[slug=' + guest_slug + ']').attr('name')) == 'undefined') {
158
- //No connectionBox for this user (user disconnect)
159
- var guest_name = getNameFromSlug(guest_slug)
160
- } else {
161
- var guest_name = $('div.user_presence[slug=' + guest_slug + ']').attr('name');
162
- }
163
-
164
- var guest_jid = guest_slug + "@" + domain;
165
-
166
-
167
- if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
168
- if ((visibleMinSlugs.indexOf(guest_slug)!=-1)){
169
- //Minimize chatbox
170
- window[getChatVariableFromSlug(guest_slug)].parent().toggle(false);
171
- }
172
- if ((visibleMaxSlugs.indexOf(guest_slug)==-1)&&(visibleMinSlugs.indexOf(guest_slug)==-1)){
173
- closeChatBox(guest_slug);
174
- }
175
- } else {
176
- //Always created.
177
- }
178
-
179
- window[getChatVariableFromSlug(guest_slug)].html(restoreLog)
180
-
181
- if (! isSlugChatConnected(guest_slug)) {
182
- showOfflineChatNotificationForSlug(guest_slug);
183
- }
184
-
194
+ getChatBoxForSlug(guest_slug).html(restoreLog)
195
+
196
+ if (! isSlugChatConnected(guest_slug)) {
197
+ showOfflineChatNotificationForSlug(guest_slug);
185
198
  }
186
- }
187
- }
199
+
200
+ }
201
+ }
202
+ }
188
203
  }
189
204
 
190
205
 
191
-
192
206
  ////////////////////
193
207
  // Events
194
208
  ////////////////////