social_stream 0.19.2 → 0.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +1 -1
- data/README.rdoc +1 -1
- data/base/app/assets/stylesheets/cheesecake.css.scss +43 -12
- data/base/app/controllers/contacts_controller.rb +1 -1
- data/base/app/models/activity.rb +4 -1
- data/base/app/models/actor.rb +2 -14
- data/base/app/models/relation.rb +2 -4
- data/base/app/models/relation/single.rb +2 -7
- data/base/app/models/tie.rb +2 -1
- data/base/app/views/activities/_new.html.erb +1 -1
- data/base/app/views/cheesecake/_cheesecake.html.erb +170 -105
- data/base/app/views/cheesecake/_index.html.erb +45 -47
- data/base/app/views/cheesecake/_sector_form.html.erb +1 -0
- data/base/app/views/toolbar/_home.html.erb +1 -1
- data/base/config/locales/en.yml +2 -0
- data/base/config/locales/es.yml +2 -0
- data/base/config/locales/rails.es.yml +192 -0
- data/base/db/migrate/20110912074426_add_reject_relation.rb +2 -2
- data/base/db/migrate/20120201185454_singleton_single_relations.rb +46 -0
- data/base/lib/social_stream/base/version.rb +1 -1
- data/base/lib/tasks/db/populate.rake +1 -1
- data/base/spec/controllers/posts_controller_spec.rb +2 -2
- data/base/spec/factories/activity.rb +1 -1
- data/base/spec/factories/post.rb +1 -1
- data/base/spec/factories/tie.rb +3 -3
- data/base/spec/models/activity_authorization_spec.rb +3 -3
- data/base/spec/support/db.rb +3 -1
- data/documents/app/assets/images/48/{word.png → doc.png} +0 -0
- data/documents/app/assets/images/48/{excel.png → xls.png} +0 -0
- data/documents/lib/social_stream/documents/version.rb +1 -1
- data/documents/social_stream-documents.gemspec +1 -1
- data/documents/spec/factories/document.rb +1 -1
- data/documents/spec/factories/picture.rb +1 -1
- data/documents/spec/support/db.rb +3 -3
- data/events/app/views/events/_sidebar_calendar.html.erb +5 -5
- data/events/lib/social_stream/events/version.rb +1 -1
- data/events/social_stream-events.gemspec +1 -1
- data/lib/social_stream/version.rb +1 -1
- data/linkser/db/migrate/20120202104549_add_links_foreign_key.rb +9 -0
- data/presence/app/assets/javascripts/chat_interface_manager.js.erb +167 -177
- data/presence/app/assets/javascripts/chat_persistence.js +194 -0
- data/presence/app/assets/javascripts/chat_utilities.js +15 -0
- data/presence/app/assets/javascripts/chat_window_manager.js +57 -1
- data/presence/app/assets/javascripts/xmpp_client_management.js.erb +191 -143
- data/presence/app/assets/stylesheets/chat.css.scss +4 -5
- data/presence/app/views/chat/_contacts.html.erb +2 -5
- data/presence/app/views/chat/_index.html.erb +46 -32
- data/presence/app/views/chat/_off.html.erb +2 -2
- data/presence/config/routes.rb +1 -1
- data/presence/lib/social_stream/presence/version.rb +1 -1
- data/presence/vendor/assets/javascripts/jquery.ui.chatbox.js +14 -11
- data/social_stream.gemspec +4 -4
- data/spec/support/db.rb +4 -4
- 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
|
-
//
|
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
|
-
|
63
|
+
if((connection!=null)&&(connection.connected)){
|
19
64
|
return true;
|
20
65
|
} else {
|
21
|
-
|
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
|
127
|
+
var userStatus;
|
94
128
|
var awayTimerPeriod = 60000;
|
95
129
|
var timerPeriod = 5000;
|
96
130
|
var refreshMinTime = 3*timerPeriod;
|
97
|
-
var awayTime =
|
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
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
166
|
+
return;
|
132
167
|
}
|
133
|
-
|
134
|
-
|
168
|
+
|
169
|
+
if (status == Strophe.Status.CONNECTING) {
|
135
170
|
log('Strophe is connecting.');
|
136
|
-
|
171
|
+
return;
|
137
172
|
}
|
138
|
-
|
139
|
-
|
173
|
+
|
174
|
+
if (status == Strophe.Status.DISCONNECTING) {
|
140
175
|
log('Strophe is disconnecting.');
|
141
176
|
return;
|
142
177
|
}
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
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
|
-
|
184
|
+
disconnectionFlag = true;
|
150
185
|
} else if (status == Strophe.Status.AUTHFAIL) {
|
151
186
|
log('Strophe authentication fail.');
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
-
|
193
|
+
disconnectionFlag = true;
|
159
194
|
} else if (status == Strophe.Status.DISCONNECTED) {
|
160
195
|
log('Strophe is disconnected.');
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
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
|
-
|
168
|
-
|
169
|
-
|
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
|
-
|
173
|
-
|
174
|
-
|
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
|
-
|
177
|
-
|
222
|
+
timer = setInterval("timerFunction()", timerPeriod);
|
223
|
+
|
224
|
+
hideAllNotifications();
|
178
225
|
}
|
179
|
-
|
180
|
-
|
226
|
+
|
227
|
+
updateChatWindow();
|
181
228
|
}
|
182
229
|
|
183
230
|
function onReconnect(){
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
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
|
-
|
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
|
-
|
201
|
-
|
202
|
-
|
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
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
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
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
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
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
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
|
-
|
299
|
+
case "unavailable":
|
257
300
|
processUnavailablePresenceStanza(presence)
|
258
301
|
break;
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
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
|
-
|
312
|
+
from = $(presence).attr('from');
|
270
313
|
slug = from.split("@")[0];
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
314
|
+
|
315
|
+
if (slug != user_slug) {
|
316
|
+
if (getConnectionBoxFromSlug(slug)!=null){
|
317
|
+
status = $(presence).find('show').text();
|
275
318
|
setUserIconStatus(slug, status);
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
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
|
-
|
330
|
+
from = $(presence).attr('from');
|
288
331
|
slug = from.split("@")[0];
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
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
|
-
|
308
|
-
|
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
|
-
|
372
|
+
setStatusWidgetTitle(status);
|
325
373
|
}
|
326
|
-
}
|
374
|
+
}
|