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.
- data/app/assets/javascripts/chat_interface_manager.js.erb +167 -177
- data/app/assets/javascripts/chat_persistence.js +179 -0
- data/app/assets/javascripts/chat_utilities.js +15 -0
- data/app/assets/javascripts/chat_window_manager.js +8 -1
- data/app/assets/javascripts/xmpp_client_management.js.erb +192 -143
- data/app/assets/stylesheets/chat.css.scss +4 -5
- data/app/views/chat/_contacts.html.erb +1 -1
- data/app/views/chat/_index.html.erb +7 -13
- data/app/views/chat/_off.html.erb +2 -2
- data/lib/social_stream/presence/version.rb +1 -1
- data/vendor/assets/javascripts/jquery.ui.chatbox.js +14 -11
- metadata +92 -64
@@ -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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
35
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
51
|
+
//JQuery DropdwanStatus
|
52
|
+
|
53
|
+
$(".dropdown dt a").click(function(event) {
|
54
|
+
event.preventDefault();
|
69
55
|
$(".dropdown dd ul").toggle();
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
84
|
+
setStatusWidgetTitle(userStatus);
|
99
85
|
}
|
100
86
|
});
|
101
|
-
|
87
|
+
|
102
88
|
}
|
103
89
|
|
104
90
|
function setStatusWidgetTitle(status){
|
105
|
-
|
106
|
-
if
|
107
|
-
|
91
|
+
|
92
|
+
if((status in sstreamChatStatus)){
|
93
|
+
status = sstreamChatStatus[status];
|
108
94
|
}
|
109
95
|
|
110
|
-
|
111
|
-
|
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
|
-
|
104
|
+
return;
|
114
105
|
}
|
115
|
-
|
116
|
-
|
117
|
-
|
106
|
+
|
107
|
+
if(status=="offline"){
|
108
|
+
var text = $("#" + status).html();
|
118
109
|
$(".dropdown dt a span").html(text);
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
if ((status in statusIcons)&&($("#" + statusIcons[status]).length > 0)) {
|
123
|
-
|
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
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
146
|
-
|
147
|
-
userStatus = "
|
136
|
+
function autochangeStatusIfAutoAway(){
|
137
|
+
if (userStatus == "autoaway"){
|
138
|
+
userStatus = "available";
|
148
139
|
sendStatus(userStatus);
|
149
140
|
}
|
150
141
|
}
|
151
142
|
|
152
|
-
function restartAwayTimer(
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
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
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
167
|
+
if(timerCounter > cyclesToRefresh){
|
168
|
+
updateChatWindow();
|
169
|
+
} else {
|
170
|
+
requestContacts = true;
|
171
|
+
}
|
186
172
|
}
|
187
173
|
|
188
174
|
|
189
175
|
function updateChatWindow(){
|
190
|
-
|
191
|
-
|
192
|
-
|
176
|
+
timerCounter=0;
|
177
|
+
log("updateChatWindow()");
|
178
|
+
var stropheConnectedAndOnlineStatus = ((isStropheConnected()) && (userStatus!="offline") && (!disconnectionFlag));
|
193
179
|
$.post("/chatWindow", { userConnected: stropheConnectedAndOnlineStatus }, function(data){
|
194
|
-
|
180
|
+
$(".tooltip").hide() //Prevent tooltips
|
195
181
|
$("#chat_partial").html(data);
|
196
182
|
if (isStropheConnected()) {
|
197
|
-
|
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
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
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
|
-
|
217
|
-
|
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
|
-
|
225
|
-
|
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
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
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
|
-
|
230
|
+
connectedSlugs=[];
|
241
231
|
connectionBoxes = $('div.user_presence[slug]');
|
242
|
-
|
243
|
-
|
244
|
-
|
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
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
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
|
-
|
306
|
-
|
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
|
-
|
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
|
-
|
327
|
-
|
328
|
-
|
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
|
-
|
322
|
+
var notification = $("div.ui-chatbox-notify");
|
333
323
|
hideChatNotification(notification);
|
334
|
-
}
|
324
|
+
}
|