social_stream 0.19.2 → 0.19.3

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