social_stream 0.11.2 → 0.11.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -9
- data/base/app/assets/stylesheets/contacts.css.scss +8 -3
- data/base/app/assets/stylesheets/frontpage.css.scss +1 -1
- data/base/app/assets/stylesheets/search.css.scss +17 -1
- data/base/app/controllers/contacts_controller.rb +2 -5
- data/base/app/models/contact.rb +3 -2
- data/base/app/views/activities/_options.html.erb +1 -1
- data/base/app/views/contacts/_form.html.erb +14 -7
- data/base/app/views/frontpage/_social_networks.html.erb +3 -0
- data/base/app/views/groups/_new.html.erb +2 -2
- data/base/app/views/groups/_show.html.erb +1 -2
- data/base/app/views/groups/index.html.erb +1 -1
- data/base/app/views/layouts/_header_signed_out.erb +1 -3
- data/base/app/views/notifications/activities/_follow_subject.html.erb +5 -2
- data/base/app/views/notifications/activities/_like_subject.html.erb +6 -2
- data/base/app/views/notifications/activities/_make-friend_subject.html.erb +5 -2
- data/base/app/views/notifications/activities/_post_subject.html.erb +6 -1
- data/base/app/views/notifications/activities/_update_body.html.erb +5 -1
- data/base/app/views/notifications/activities/_update_subject.html.erb +5 -1
- data/base/app/views/posts/_post_focus_search.html.erb +37 -3
- data/base/app/views/posts/_post_global_search.html.erb +2 -0
- data/base/app/views/profiles/_contact.html.erb +1 -1
- data/base/app/views/search/index.js.erb +2 -0
- data/base/app/views/toolbar/_home.html.erb +4 -0
- data/base/config/locales/en.yml +26 -0
- data/base/config/locales/es.yml +26 -0
- data/base/lib/mailboxer/notification_decoder.rb +8 -6
- data/base/lib/social_stream-base.rb +1 -1
- data/base/lib/social_stream/base/version.rb +1 -1
- data/base/lib/social_stream/migrations/components.rb +1 -1
- data/base/lib/social_stream/toolbar_config/base.rb +12 -1
- data/base/social_stream-base.gemspec +1 -1
- data/base/spec/controllers/contacts_controller_spec.rb +4 -4
- data/events/app/assets/javascripts/social_stream-events.js +2 -2
- data/events/app/assets/stylesheets/social_stream-events.css +3 -0
- data/events/{app → vendor}/assets/javascripts/jquery.ad-gallery.js +0 -0
- data/events/{app → vendor}/assets/javascripts/jquery.ad-gallery.pack.js +0 -0
- data/events/{app → vendor}/assets/stylesheets/ad_next.png +0 -0
- data/events/{app → vendor}/assets/stylesheets/ad_prev.png +0 -0
- data/events/{app → vendor}/assets/stylesheets/ad_scroll_back.png +0 -0
- data/events/{app → vendor}/assets/stylesheets/ad_scroll_forward.png +0 -0
- data/events/{app → vendor}/assets/stylesheets/fullcalendar.css +0 -0
- data/events/{app → vendor}/assets/stylesheets/fullcalendar.print.css +0 -0
- data/events/{app → vendor}/assets/stylesheets/jquery.ad-gallery.css +0 -0
- data/events/{app → vendor}/assets/stylesheets/loader.gif +0 -0
- data/events/vendor/assets/stylesheets/social_stream-events.css +273 -0
- data/lib/social_stream.rb +0 -4
- data/lib/social_stream/version.rb +1 -1
- data/presence/.gitignore +4 -0
- data/presence/Gemfile +4 -0
- data/presence/Rakefile +1 -0
- data/presence/app/assets/audio/chat/onMessageAudio.mp3 +0 -0
- data/presence/app/assets/audio/chat/onMessageAudio.wav +0 -0
- data/presence/app/assets/images/arrow.png +0 -0
- data/presence/app/assets/images/black_arrow3.png +0 -0
- data/presence/app/assets/images/status/available.png +0 -0
- data/presence/app/assets/images/status/away.png +0 -0
- data/presence/app/assets/images/status/dnd.png +0 -0
- data/presence/app/assets/javascripts/jquery-ui-1.8.14.custom.min.js +789 -0
- data/presence/app/assets/javascripts/jquery.tools.min.js +17 -0
- data/presence/app/assets/javascripts/jquery.tools.tooltip.js +11 -0
- data/presence/app/assets/javascripts/jquery.ui.chatbox.js +260 -0
- data/presence/app/assets/javascripts/social_stream-presence.js +2 -0
- data/presence/app/assets/javascripts/store.js +27 -0
- data/presence/app/assets/javascripts/strophe.js +3612 -0
- data/presence/app/assets/javascripts/xmpp_client.js +498 -0
- data/presence/app/assets/stylesheets/chat.css +231 -0
- data/presence/app/assets/stylesheets/jquery.ui.chatbox.css +54 -0
- data/presence/app/assets/stylesheets/social_stream-presence.css +3 -0
- data/presence/app/controllers/xmpp_controller.rb +190 -0
- data/presence/app/helpers/xmpp_helper.rb +33 -0
- data/presence/app/views/xmpp/_chat.html.erb +59 -0
- data/presence/app/views/xmpp/_chat_connecting.html.erb +8 -0
- data/presence/app/views/xmpp/_chat_contacts.html.erb +46 -0
- data/presence/app/views/xmpp/_chat_off.html.erb +35 -0
- data/presence/app/views/xmpp/active_users.html.erb +33 -0
- data/presence/app/views/xmpp/chat.html.erb +13 -0
- data/presence/app/views/xmpp/index.html +19 -0
- data/presence/app/views/xmpp/test.html.erb +11 -0
- data/presence/config/routes.rb +15 -0
- data/presence/db/migrate/20110711111408_add_connected_column_to_user.rb +9 -0
- data/presence/db/migrate/20110928135031_add_status_column_to_user.rb +9 -0
- data/presence/ejabberd/conf/ejabberd.cfg +625 -0
- data/presence/ejabberd/conf/ejabberdctl.cfg +154 -0
- data/presence/ejabberd/conf/inetrc +3 -0
- data/presence/ejabberd/conf/server.pem +37 -0
- data/presence/ejabberd/conf/ssconfig.cfg +29 -0
- data/presence/ejabberd/ejabberd_scripts/authentication_script +117 -0
- data/presence/ejabberd/ejabberd_scripts/authentication_script_org +114 -0
- data/presence/ejabberd/ejabberd_scripts/compile_module +34 -0
- data/presence/ejabberd/ejabberd_scripts/generate_random_password +18 -0
- data/presence/ejabberd/ejabberd_scripts/kill_authentication_script.sh +13 -0
- data/presence/ejabberd/ejabberd_scripts/reset_connection_script +55 -0
- data/presence/ejabberd/ejabberd_scripts/reset_logs.sh +23 -0
- data/presence/ejabberd/ejabberd_scripts/set_connection_script +48 -0
- data/presence/ejabberd/ejabberd_scripts/set_presence_script +48 -0
- data/presence/ejabberd/ejabberd_scripts/show_config.sh +30 -0
- data/presence/ejabberd/ejabberd_scripts/start_ejabberd.sh +68 -0
- data/presence/ejabberd/ejabberd_scripts/stop_ejabberd.sh +12 -0
- data/presence/ejabberd/ejabberd_scripts/synchronize_presence_script +57 -0
- data/presence/ejabberd/ejabberd_scripts/unset_connection_script +48 -0
- data/presence/ejabberd/mod_admin_extra/mod_admin_extra.beam +0 -0
- data/presence/ejabberd/mod_admin_extra/mod_admin_extra.erl +1560 -0
- data/presence/ejabberd/mod_sspresence/mod_sspresence.erl +230 -0
- data/presence/lib/social_stream-presence.rb +13 -0
- data/presence/lib/social_stream/migrations/presence.rb +9 -0
- data/presence/lib/social_stream/presence/config.rb +9 -0
- data/presence/lib/social_stream/presence/engine.rb +49 -0
- data/presence/lib/social_stream/presence/models/buddy_manager.rb +67 -0
- data/presence/social_stream-presence.gemspec +28 -0
- data/presence/spec/demo/.gitignore +5 -0
- data/presence/spec/demo/.rspec +1 -0
- data/presence/spec/demo/README +261 -0
- data/presence/spec/demo/Rakefile +7 -0
- data/presence/spec/demo/app/assets/images/rails.png +0 -0
- data/presence/spec/demo/app/assets/javascripts/application.js +9 -0
- data/presence/spec/demo/app/assets/stylesheets/application.css +7 -0
- data/presence/spec/demo/app/controllers/application_controller.rb +3 -0
- data/presence/spec/demo/app/helpers/application_helper.rb +2 -0
- data/presence/spec/demo/app/mailers/.gitkeep +0 -0
- data/presence/spec/demo/app/models/.gitkeep +0 -0
- data/presence/spec/demo/app/views/layouts/application.html.erb +14 -0
- data/presence/spec/demo/autotest/discover.rb +2 -0
- data/presence/spec/demo/config.ru +4 -0
- data/presence/spec/demo/config/application.rb +41 -0
- data/presence/spec/demo/config/boot.rb +6 -0
- data/presence/spec/demo/config/database.yml +25 -0
- data/presence/spec/demo/config/environment.rb +5 -0
- data/presence/spec/demo/config/environments/development.rb +27 -0
- data/presence/spec/demo/config/environments/production.rb +54 -0
- data/presence/spec/demo/config/environments/test.rb +39 -0
- data/presence/spec/demo/config/initializers/backtrace_silencers.rb +7 -0
- data/presence/spec/demo/config/initializers/inflections.rb +10 -0
- data/presence/spec/demo/config/initializers/mime_types.rb +5 -0
- data/presence/spec/demo/config/initializers/secret_token.rb +7 -0
- data/presence/spec/demo/config/initializers/session_store.rb +8 -0
- data/presence/spec/demo/config/initializers/wrap_parameters.rb +12 -0
- data/presence/spec/demo/config/locales/en.yml +5 -0
- data/presence/spec/demo/config/routes.rb +58 -0
- data/presence/spec/demo/db/seeds.rb +7 -0
- data/presence/spec/demo/doc/README_FOR_APP +2 -0
- data/presence/spec/demo/lib/tasks/.gitkeep +0 -0
- data/presence/spec/demo/log/.gitkeep +0 -0
- data/presence/spec/demo/public/404.html +26 -0
- data/presence/spec/demo/public/422.html +26 -0
- data/presence/spec/demo/public/500.html +26 -0
- data/presence/spec/demo/public/favicon.ico +0 -0
- data/presence/spec/demo/public/index.html +241 -0
- data/presence/spec/demo/public/robots.txt +5 -0
- data/presence/spec/demo/script/rails +6 -0
- data/presence/spec/demo/spec/spec_helper.rb +27 -0
- data/presence/spec/demo/test/fixtures/.gitkeep +0 -0
- data/presence/spec/demo/test/functional/.gitkeep +0 -0
- data/presence/spec/demo/test/integration/.gitkeep +0 -0
- data/presence/spec/demo/test/performance/browsing_test.rb +12 -0
- data/presence/spec/demo/test/test_helper.rb +13 -0
- data/presence/spec/demo/test/unit/.gitkeep +0 -0
- data/presence/spec/demo/vendor/assets/stylesheets/.gitkeep +0 -0
- data/presence/spec/demo/vendor/plugins/.gitkeep +0 -0
- data/presence/spec/discover.rb +2 -0
- data/presence/spec/spec_helper.rb +27 -0
- data/social_stream.gemspec +9 -2
- data/spec/dummy/config/environments/{test_pg.rb → test_mysql.rb} +6 -2
- data/spec/dummy/config/environments/test_postgres.rb +39 -0
- data/spec/spec_helper.rb +1 -4
- metadata +135 -21
- data/base/app/views/groups/_new_activity.html.erb +0 -1
- data/base/app/views/groups/_new_activity_fields.html.erb +0 -7
@@ -0,0 +1,498 @@
|
|
1
|
+
////////////////////
|
2
|
+
//Test functions
|
3
|
+
////////////////////
|
4
|
+
|
5
|
+
function log(msg) {
|
6
|
+
console.log(msg)
|
7
|
+
}
|
8
|
+
|
9
|
+
|
10
|
+
////////////////////
|
11
|
+
//Hash table
|
12
|
+
////////////////////
|
13
|
+
var statusMessage = new Array();
|
14
|
+
statusMessage[''] = "";
|
15
|
+
statusMessage['chat'] = "";
|
16
|
+
statusMessage['away'] = "Away";
|
17
|
+
statusMessage['xa'] = "Away";
|
18
|
+
statusMessage['dnd'] = "Busy";
|
19
|
+
|
20
|
+
////////////////////
|
21
|
+
//Strophe functions
|
22
|
+
////////////////////
|
23
|
+
|
24
|
+
//Global variables
|
25
|
+
var userStatus = "chat";
|
26
|
+
var awayTimerPeriod = 16000;
|
27
|
+
var timerPeriod = 5000;
|
28
|
+
var refreshMinTime = 3*timerPeriod;
|
29
|
+
var awayTime = 300000;
|
30
|
+
var awayCounter = 0;
|
31
|
+
var timerCounter = 0;
|
32
|
+
var connection = null;
|
33
|
+
var userConnected = false;
|
34
|
+
var reconnectAttempts = 3;
|
35
|
+
var awayTimer;
|
36
|
+
var timer;
|
37
|
+
var requestContacts=false;
|
38
|
+
var cyclesToRefresh = (refreshMinTime/timerPeriod);
|
39
|
+
|
40
|
+
function onConnect(status) {
|
41
|
+
|
42
|
+
//Status.ERROR An error has occurred
|
43
|
+
//Status.CONNECTING The connection is currently being made
|
44
|
+
//Status.CONNFAIL The connection attempt failed
|
45
|
+
//Status.AUTHENTICATING The connection is authenticating
|
46
|
+
//Status.AUTHFAIL The authentication attempt failed
|
47
|
+
//Status.CONNECTED The connection has succeeded
|
48
|
+
//Status.DISCONNECTED The connection has been terminated
|
49
|
+
//Status.DISCONNECTING The connection is currently being terminated
|
50
|
+
//Status.ATTACHED The connection has been attached
|
51
|
+
|
52
|
+
log('Strophe onConnect callback call with status ' + status);
|
53
|
+
|
54
|
+
if (status == Strophe.Status.ATTACHED){
|
55
|
+
log('Strophe connection attached');
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
|
59
|
+
if (status == Strophe.Status.AUTHENTICATING ){
|
60
|
+
log('Strophe connection AUTHENTICATING');
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
|
64
|
+
if (status == Strophe.Status.CONNECTING) {
|
65
|
+
log('Strophe is connecting.');
|
66
|
+
return;
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
clearTimeout(initialTimer);
|
71
|
+
|
72
|
+
if (status == Strophe.Status.CONNFAIL) {
|
73
|
+
log('Strophe failed to connect.');
|
74
|
+
userConnected = false;
|
75
|
+
setTimeout ("onReconnect()", 3000);
|
76
|
+
} else if (status == Strophe.Status.AUTHFAIL) {
|
77
|
+
log('Strophe authentication fail.');
|
78
|
+
if ((window.sessionStorage)&&(sessionStorage.getItem("ss_user_pass") != null)){
|
79
|
+
sessionStorage.setItem("ss_user_pass",null);
|
80
|
+
}
|
81
|
+
userConnected = false;
|
82
|
+
} else if (status == Strophe.Status.ERROR) {
|
83
|
+
log('Strophe error.');
|
84
|
+
userConnected = false;
|
85
|
+
} else if (status == Strophe.Status.DISCONNECTED) {
|
86
|
+
log('Strophe is disconnected.');
|
87
|
+
userConnected = false;
|
88
|
+
clearTimeout(awayTimer);
|
89
|
+
setTimeout ("onReconnect()", 3000);
|
90
|
+
} else if (status == Strophe.Status.CONNECTED) {
|
91
|
+
log('Strophe is connected.');
|
92
|
+
log('Presenze stanza send for:' + connection.jid);
|
93
|
+
connection.addHandler(onMessage, null, 'message', null, null, null);
|
94
|
+
connection.addHandler(onPresence, null, 'presence', null, null, null);
|
95
|
+
//addHandler:(callback, namespace to match, stanza name, stanza type, stanza id , stanza from, options)
|
96
|
+
sendStatus(userStatus);
|
97
|
+
userConnected = true;
|
98
|
+
awayTimer = setInterval("awayTimerFunction()", awayTimerPeriod);
|
99
|
+
timer = setInterval("timerFunction()", timerPeriod);
|
100
|
+
}
|
101
|
+
|
102
|
+
updateChatWindow();
|
103
|
+
}
|
104
|
+
|
105
|
+
function onReconnect(){
|
106
|
+
if ((connection != null)&&(!userConnected)) {
|
107
|
+
if (reconnectAttempts>0) {
|
108
|
+
reconnectAttempts--;
|
109
|
+
connectToServer(null);
|
110
|
+
setTimeout ("onReconnect()", 9000);
|
111
|
+
} else {
|
112
|
+
//Notify issue to Rails App Server?
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
function onMessage(msg) {
|
118
|
+
var to = msg.getAttribute('to');
|
119
|
+
var from = msg.getAttribute('from');
|
120
|
+
var type = msg.getAttribute('type');
|
121
|
+
var elems = msg.getElementsByTagName('body');
|
122
|
+
|
123
|
+
if (type == "chat" && elems.length > 0) {
|
124
|
+
|
125
|
+
var body = elems[0];
|
126
|
+
var from_slug = from.split("@")[0];
|
127
|
+
var from_name = $("#" + from_slug).attr("name");
|
128
|
+
var from_jid = from_slug + "@" + domain;
|
129
|
+
|
130
|
+
log(from + ' says: ' + Strophe.getText(body));
|
131
|
+
|
132
|
+
if (typeof ($('div.user_presence[slug=' + from_slug + ']').attr('name')) == 'undefined') {
|
133
|
+
var from_name = from_slug;
|
134
|
+
} else {
|
135
|
+
var from_name = $('div.user_presence[slug=' + from_slug + ']').attr('name');
|
136
|
+
}
|
137
|
+
|
138
|
+
if (mustPlaySoundForChatWindow(window[from_slug])){
|
139
|
+
playSound("onMessageAudio");
|
140
|
+
}
|
141
|
+
|
142
|
+
if (createChatBox(from_slug,from_name,from_jid,user_name,user_jid)) {
|
143
|
+
} else {
|
144
|
+
window[from_slug].chatbox("option", "boxManager").toggleBox(true);
|
145
|
+
}
|
146
|
+
|
147
|
+
$("#" + from_slug).chatbox("option", "boxManager").addMsg(from_name, Strophe.getText(body));
|
148
|
+
rotatePriority(from_slug);
|
149
|
+
}
|
150
|
+
|
151
|
+
// we must return true to keep the handler alive.
|
152
|
+
// returning false would remove it after it finishes.
|
153
|
+
return true;
|
154
|
+
}
|
155
|
+
|
156
|
+
|
157
|
+
function onPresence(presence) {
|
158
|
+
from = $(presence).attr('from');
|
159
|
+
slug = from.split("@")[0];
|
160
|
+
if(slug != user_slug){
|
161
|
+
setTimeout("refreshChatWindow()", 2000);
|
162
|
+
}
|
163
|
+
return true;
|
164
|
+
}
|
165
|
+
|
166
|
+
|
167
|
+
function sendChatMessage(from,to,text){
|
168
|
+
var type = "chat";
|
169
|
+
var body= $build("body");
|
170
|
+
body.t(text);
|
171
|
+
var message = $msg({to: to, from: from, type: 'chat'}).cnode(body.tree());
|
172
|
+
connection.send(message.tree());
|
173
|
+
log(from + ' says: ' + text + ' to ' + to);
|
174
|
+
resumeAwayTimerIfAway();
|
175
|
+
return true;
|
176
|
+
}
|
177
|
+
|
178
|
+
|
179
|
+
////////////////////
|
180
|
+
//Audio functions
|
181
|
+
////////////////////
|
182
|
+
|
183
|
+
//Global audio variables
|
184
|
+
var onMessageAudio;
|
185
|
+
|
186
|
+
var html5_audiotypes=[
|
187
|
+
["mp3","audio/mpeg"],
|
188
|
+
//["mp4","audio/mp4"],
|
189
|
+
//["ogg","audio/ogg"],
|
190
|
+
["wav","audio/wav"]
|
191
|
+
]
|
192
|
+
|
193
|
+
function initAudio(){
|
194
|
+
//Init all audio files
|
195
|
+
initSound("onMessageAudio");
|
196
|
+
}
|
197
|
+
|
198
|
+
function initSound(sound){
|
199
|
+
|
200
|
+
//Check support for HTML5 audio
|
201
|
+
var html5audio=document.createElement('audio')
|
202
|
+
|
203
|
+
if (html5audio.canPlayType){
|
204
|
+
path = 'assets/chat/' + sound;
|
205
|
+
window[sound] = new Audio();
|
206
|
+
|
207
|
+
for(i=0; i<html5_audiotypes.length; i++){
|
208
|
+
if (window[sound].canPlayType(html5_audiotypes[i][1])) {
|
209
|
+
var source= document.createElement('source');
|
210
|
+
source.type= html5_audiotypes[i][1];
|
211
|
+
source.src= path + '.' + html5_audiotypes[i][0];
|
212
|
+
window[sound].addEventListener('ended', endSoundListener);
|
213
|
+
window[sound].appendChild(source);
|
214
|
+
}
|
215
|
+
}
|
216
|
+
} else {
|
217
|
+
//Browser doesn't support HTML5 audio
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
function endSoundListener(){ }
|
222
|
+
|
223
|
+
function playSound(sound){
|
224
|
+
if (window[sound]!=null){
|
225
|
+
window[sound].play();
|
226
|
+
} else {
|
227
|
+
//Fallback option: When browser doesn't support HTML5 audio
|
228
|
+
$('body').append('<embed src="/' + sound + '.mp3" autostart="true" hidden="true" loop="false">');
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
function initAndPlaySound(sound){
|
233
|
+
initSound(sound);
|
234
|
+
playSound(sound);
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
////////////////////
|
240
|
+
//Chat view jquery
|
241
|
+
////////////////////
|
242
|
+
|
243
|
+
$(document).ready(function () {
|
244
|
+
initialTimer = setTimeout("updateChatWindow()", 15000);
|
245
|
+
initAudio();
|
246
|
+
});
|
247
|
+
|
248
|
+
function setUserFunctions(){
|
249
|
+
|
250
|
+
$("div.user_presence").click(function(event, ui){
|
251
|
+
var guest_name = $(this).attr("name");
|
252
|
+
var guest_slug = $(this).attr("slug");
|
253
|
+
var guest_jid = guest_slug + "@" + domain;
|
254
|
+
|
255
|
+
if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
|
256
|
+
} else {
|
257
|
+
window[guest_slug].chatbox("option", "boxManager").toggleBox(true);
|
258
|
+
};
|
259
|
+
});
|
260
|
+
|
261
|
+
|
262
|
+
//JQuery DropdwanStatus
|
263
|
+
|
264
|
+
$(".dropdown dt a").click(function(event) {
|
265
|
+
event.preventDefault();
|
266
|
+
$(".dropdown dd ul").toggle();
|
267
|
+
});
|
268
|
+
|
269
|
+
$(".dropdown dd ul li a.option").click(function(event) {
|
270
|
+
event.preventDefault();
|
271
|
+
var text = $(this).html();
|
272
|
+
$(".dropdown dt a span").html(text);
|
273
|
+
userStatus = getSelectedValue("status");
|
274
|
+
sendStatus(userStatus);
|
275
|
+
$(".dropdown dd ul").hide();
|
276
|
+
});
|
277
|
+
|
278
|
+
|
279
|
+
function getSelectedValue(id) {
|
280
|
+
return $("#" + id).find("dt a span.value").html();
|
281
|
+
}
|
282
|
+
|
283
|
+
$(document).bind('click', function(e) {
|
284
|
+
var $clicked = $(e.target);
|
285
|
+
if (! $clicked.parents().hasClass("dropdown")){
|
286
|
+
//Click outside the select...
|
287
|
+
$(".dropdown dd ul").hide();
|
288
|
+
}
|
289
|
+
});
|
290
|
+
}
|
291
|
+
|
292
|
+
|
293
|
+
function awayTimerFunction(){
|
294
|
+
awayCounter++;
|
295
|
+
if (awayCounter > (awayTime/awayTimerPeriod)){
|
296
|
+
userStatus = "away";
|
297
|
+
sendStatus(userStatus);
|
298
|
+
clearTimeout(awayTimer);
|
299
|
+
} else {
|
300
|
+
userStatus = "chat";
|
301
|
+
}
|
302
|
+
}
|
303
|
+
|
304
|
+
function resumeAwayTimerIfAway(){
|
305
|
+
if (userStatus == "away"){
|
306
|
+
awayCounter = 0;
|
307
|
+
userStatus = "chat";
|
308
|
+
sendStatus(userStatus);
|
309
|
+
awayTimer = setInterval("awayTimerFunction()", awayTimerPeriod);
|
310
|
+
}
|
311
|
+
}
|
312
|
+
|
313
|
+
function timerFunction(){
|
314
|
+
timerCounter++;
|
315
|
+
|
316
|
+
if((timerCounter > cyclesToRefresh)&&(requestContacts)) {
|
317
|
+
requestContacts = false;
|
318
|
+
updateChatWindow();
|
319
|
+
}
|
320
|
+
}
|
321
|
+
|
322
|
+
function refreshChatWindow(){
|
323
|
+
if(timerCounter > cyclesToRefresh){
|
324
|
+
updateChatWindow();
|
325
|
+
} else {
|
326
|
+
requestContacts = true;
|
327
|
+
}
|
328
|
+
}
|
329
|
+
|
330
|
+
function updateChatWindow(){
|
331
|
+
timerCounter=0;
|
332
|
+
log("updateChatWindow()");
|
333
|
+
$.post("/chatWindow", { userConnected: userConnected }, function(data){
|
334
|
+
$("#chat_partial").html(data);
|
335
|
+
if (userConnected) {
|
336
|
+
$(".user_presence a[title]").tooltip();
|
337
|
+
setUserFunctions();
|
338
|
+
}
|
339
|
+
});
|
340
|
+
}
|
341
|
+
|
342
|
+
function sendStatus(status){
|
343
|
+
if (status in statusMessage){
|
344
|
+
//Send status to the XMPP Server
|
345
|
+
var pres = $pres()
|
346
|
+
.c('status')
|
347
|
+
.t(statusMessage[status]).up() //Status message
|
348
|
+
.c('show')
|
349
|
+
.t(status);
|
350
|
+
connection.send(pres.tree());
|
351
|
+
}
|
352
|
+
}
|
353
|
+
|
354
|
+
|
355
|
+
function mustPlaySoundForChatWindow(chatBox){
|
356
|
+
if(userStatus == "dnd"){
|
357
|
+
return false;
|
358
|
+
}
|
359
|
+
|
360
|
+
if (typeof chatBox == 'undefined') {
|
361
|
+
return true;
|
362
|
+
}
|
363
|
+
|
364
|
+
//Enable sounds only for new (or hidden) chatBoxes
|
365
|
+
return (chatBox.chatbox("option", "hidden") == true);
|
366
|
+
}
|
367
|
+
|
368
|
+
////////////////////
|
369
|
+
//Chat functions
|
370
|
+
////////////////////
|
371
|
+
|
372
|
+
var nBox = 0;
|
373
|
+
var maxBox = 5;
|
374
|
+
var chatBoxWidth = 230;
|
375
|
+
var visibleChatBoxes = new Array();
|
376
|
+
var chatBoxSeparation = chatBoxWidth+12;
|
377
|
+
|
378
|
+
|
379
|
+
function createChatBox(guest_slug,guest_name,guest_jid,user_name,user_jid){
|
380
|
+
|
381
|
+
//Create chatbox for new conversations
|
382
|
+
//Open chatbox for old conversations
|
383
|
+
|
384
|
+
//Box Variable name = guest_slug
|
385
|
+
if (typeof window[guest_slug] == 'undefined') {
|
386
|
+
|
387
|
+
//Add div with id = guest_slug
|
388
|
+
$("#chat_divs").append("<div id=" + guest_slug + " name=" + guest_name + "></div>")
|
389
|
+
|
390
|
+
//Add CSS [...]
|
391
|
+
|
392
|
+
|
393
|
+
//Offset Management for new box
|
394
|
+
boxParams = getBoxParams();
|
395
|
+
var offset = boxParams[0];
|
396
|
+
var position = boxParams[1];
|
397
|
+
|
398
|
+
|
399
|
+
window[guest_slug] = $("#" + guest_slug).chatbox({id: user_name,
|
400
|
+
user:{key : "value"},
|
401
|
+
hidden: false,
|
402
|
+
offset: offset, // relative to right edge of the browser window
|
403
|
+
width: chatBoxWidth, // width of the chatbox
|
404
|
+
title : guest_name,
|
405
|
+
position: position,
|
406
|
+
priority: visibleChatBoxes.length+1,
|
407
|
+
boxClosed: function(id) {
|
408
|
+
|
409
|
+
position = $("#" + guest_slug).chatbox("option", "position");
|
410
|
+
|
411
|
+
for (i=position+1;i<visibleChatBoxes.length+1;i++){
|
412
|
+
visibleChatBoxes[i-1].chatbox("option", "offset", visibleChatBoxes[i-1].chatbox("option", "offset") - chatBoxSeparation);
|
413
|
+
visibleChatBoxes[i-1].chatbox("option", "position", visibleChatBoxes[i-1].chatbox("option", "position") - 1 );
|
414
|
+
}
|
415
|
+
|
416
|
+
visibleChatBoxes.splice(position-1,1);
|
417
|
+
$("#" + guest_slug).chatbox("option", "hidden", true);
|
418
|
+
nBox--;
|
419
|
+
},
|
420
|
+
|
421
|
+
messageSent : function(id, user, msg) {
|
422
|
+
rotatePriority(guest_slug);
|
423
|
+
$("#" + guest_slug).chatbox("option", "boxManager").addMsg(id, msg);
|
424
|
+
sendChatMessage(user_jid,guest_jid,msg);
|
425
|
+
}});
|
426
|
+
|
427
|
+
visibleChatBoxes[position-1] = window[guest_slug];
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
return true;
|
432
|
+
|
433
|
+
} else {
|
434
|
+
|
435
|
+
if (visibleChatBoxes.indexOf(window[guest_slug]) == -1) {
|
436
|
+
|
437
|
+
//Offset Management for old box
|
438
|
+
boxParams = getBoxParams();
|
439
|
+
var offset = boxParams[0];
|
440
|
+
var position = boxParams[1];
|
441
|
+
|
442
|
+
window[guest_slug].chatbox("option", "offset", offset);
|
443
|
+
window[guest_slug].chatbox("option", "position", position);
|
444
|
+
visibleChatBoxes[position-1] = window[guest_slug];
|
445
|
+
}
|
446
|
+
|
447
|
+
window[guest_slug].chatbox("option", "hidden", false);
|
448
|
+
return false;
|
449
|
+
}
|
450
|
+
|
451
|
+
}
|
452
|
+
|
453
|
+
function getBoxParams(){
|
454
|
+
|
455
|
+
var boxParams = new Array(2);
|
456
|
+
|
457
|
+
if (nBox==maxBox){
|
458
|
+
//Select box to replaced
|
459
|
+
replaced = visibleChatBoxes[getBoxIndexToReplace()];
|
460
|
+
replaced.chatbox("option", "hidden", true)
|
461
|
+
index = visibleChatBoxes.indexOf(replaced);
|
462
|
+
boxParams[0] = replaced.chatbox("option", "offset")
|
463
|
+
boxParams[1] = replaced.chatbox("option", "position")
|
464
|
+
} else {
|
465
|
+
nBox++;
|
466
|
+
boxParams[0] = (nBox-1)*(chatBoxSeparation);
|
467
|
+
boxParams[1] = nBox;
|
468
|
+
}
|
469
|
+
|
470
|
+
return boxParams
|
471
|
+
}
|
472
|
+
|
473
|
+
|
474
|
+
function getBoxIndexToReplace(){
|
475
|
+
|
476
|
+
tmp = visibleChatBoxes[0];
|
477
|
+
for (i=0;i<visibleChatBoxes.length;i++){
|
478
|
+
if (visibleChatBoxes[i].chatbox("option", "priority") > tmp.chatbox("option", "priority")) {
|
479
|
+
tmp = visibleChatBoxes[i];
|
480
|
+
}
|
481
|
+
}
|
482
|
+
|
483
|
+
return visibleChatBoxes.indexOf(tmp);
|
484
|
+
}
|
485
|
+
|
486
|
+
function rotatePriority(guest_slug){
|
487
|
+
priority = $("#" + guest_slug).chatbox("option", "priority")
|
488
|
+
if(priority>1){
|
489
|
+
for (i=0;i<visibleChatBoxes.length;i++){
|
490
|
+
if(visibleChatBoxes[i].chatbox("option", "priority")<priority){
|
491
|
+
visibleChatBoxes[i].chatbox("option", "priority",visibleChatBoxes[i].chatbox("option", "priority")+1);
|
492
|
+
}
|
493
|
+
}
|
494
|
+
$("#" + guest_slug).chatbox("option", "priority", 1);
|
495
|
+
}
|
496
|
+
}
|
497
|
+
|
498
|
+
|