social_stream 0.12.7 → 0.12.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,10 +25,6 @@ module SocialStream
25
25
  end
26
26
  end
27
27
 
28
- initializer "social_stream-base.cancan_devise_integration" do
29
- ApplicationController.rescue_handlers += [["CanCan::AccessDenied", :rescue_from_access_denied]]
30
- end
31
-
32
28
  initializer "social_stream-base.toolbar_config" do
33
29
  SocialStream::ToolbarConfig.module_eval do
34
30
  include SocialStream::ToolbarConfig::Base
@@ -52,6 +48,10 @@ module SocialStream
52
48
  config.email_method = :mailboxer_email
53
49
  end
54
50
  end
51
+
52
+ config.to_prepare do
53
+ ApplicationController.rescue_handlers += [["CanCan::AccessDenied", :rescue_from_access_denied]]
54
+ end
55
55
  end
56
56
  end
57
57
  end
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Base
3
- VERSION = "0.9.29".freeze
3
+ VERSION = "0.9.30".freeze
4
4
  end
5
5
  end
@@ -10,8 +10,10 @@ module SocialStream
10
10
 
11
11
  # Redirect to login if the user is trying to access a protected resource
12
12
  # and she is not authenticated
13
- def rescue_from_access_denied
14
- unless user_signed_in?
13
+ def rescue_from_access_denied(exception)
14
+ if user_signed_in?
15
+ raise exception
16
+ else
15
17
  redirect_to new_user_session_path
16
18
  end
17
19
  end
@@ -41,9 +41,7 @@ describe UsersController do
41
41
  begin
42
42
  get :edit, :id => Factory(:user).to_param
43
43
 
44
- assert false
45
- rescue CanCan::AccessDenied
46
- assert true
44
+ response.should redirect_to(:new_user_session)
47
45
  end
48
46
  end
49
47
  end
@@ -1,3 +1,3 @@
1
1
  module SocialStream
2
- VERSION = "0.12.7".freeze
2
+ VERSION = "0.12.8".freeze
3
3
  end
@@ -6,7 +6,6 @@ function log(msg) {
6
6
  //console.log(msg)
7
7
  }
8
8
 
9
-
10
9
  ////////////////////
11
10
  //Hash table
12
11
  ////////////////////
@@ -24,6 +23,18 @@ statusIcons['away'] = "away";
24
23
  statusIcons['xa'] = "away";
25
24
  statusIcons['dnd'] = "dnd";
26
25
 
26
+ var chatIcons = new Array();
27
+ chatIcons[':)'] = "face-smile.png";
28
+ chatIcons[':('] = "face-sad.png";
29
+ chatIcons['(B)'] = "beer.png";
30
+ chatIcons['(C)'] = "clock.png";
31
+ chatIcons['(P)'] = "present.png";
32
+ chatIcons[':P']= "face-raspberry.png";
33
+ chatIcons[':Z']= "face-tired.png";
34
+ chatIcons['(R)']= "rain.png";
35
+ chatIcons['(S)']= "sun.png";
36
+ chatIcons[';)']= "face-wink.png";
37
+
27
38
  ////////////////////
28
39
  //Connect functions
29
40
  ////////////////////
@@ -230,32 +241,107 @@ function onMessage(msg) {
230
241
  return true;
231
242
  }
232
243
 
244
+
245
+
246
+ function onPresence(presence) {
247
+
248
+ //Check presence stanza type
249
+ ptype = $(presence).attr('type');
250
+
251
+ switch (ptype){
252
+ case undefined:
253
+ processAvailablePresenceStanza(presence)
254
+ break;
255
+ case "available":
256
+ processAvailablePresenceStanza(presence)
257
+ break;
258
+ case "unavailable":
259
+ processUnavailablePresenceStanza(presence)
260
+ break;
261
+ default :
262
+ //Stanza type not recognize
263
+ processAvailablePresenceStanza(presence)
264
+ }
265
+
266
+ return true;
267
+ }
268
+
269
+ function processAvailablePresenceStanza(presence){
270
+ from = $(presence).attr('from');
271
+ slug = from.split("@")[0];
272
+
273
+ if (slug != user_slug) {
274
+ if (getConnectionBoxFromSlug(slug)!=null){
275
+ status = $(presence).find('show').text();
276
+ setUserIconStatus(slug, status);
277
+ if (cacheConnectedUsers.indexOf(slug) != -1) {
278
+ showConnectionBoxFromSlug(slug);
279
+ }
280
+ } else {
281
+ setTimeout("refreshChatWindow()", 3000);
282
+ }
283
+ }
284
+ }
285
+
286
+ function processUnavailablePresenceStanza(presence){
287
+ from = $(presence).attr('from');
288
+ slug = from.split("@")[0];
289
+
290
+ if (slug != user_slug) {
291
+ if (getConnectionBoxFromSlug(slug)!=null){
292
+ hideConnectionBoxFromSlug(slug)
293
+ }
294
+ }
295
+ }
296
+
297
+ function sendChatMessage(from,to,text){
298
+ var type = "chat";
299
+ var body= $build("body");
300
+ body.t(text);
301
+ var message = $msg({to: to, from: from, type: 'chat'}).cnode(body.tree());
302
+ connection.send(message.tree());
303
+ resumeAwayTimerIfAway();
304
+ return true;
305
+ }
306
+
307
+ function authByCookie(){
308
+ var authMethod = '<%= SocialStream::Presence.auth_method %>';
309
+ return authMethod=="cookie";
310
+ }
311
+
312
+ function authByPassword(){
313
+ var authMethod = '<%= SocialStream::Presence.auth_method %>';
314
+ return authMethod=="password";
315
+ }
316
+
317
+ function ifCookie(){
318
+ return (!(typeof cookie == 'undefined'))
319
+ }
320
+
321
+
322
+
233
323
  ///////////////////////////////////////////////////////
234
- //Allow new features in chat msg like links, images, icons, ...
324
+ // Parser functions
325
+ // Allow new features in chat msg like links, images, emoticons, ...
235
326
  ///////////////////////////////////////////////////////
236
327
 
237
- var chatIcons = new Array();
238
- chatIcons[':)'] = "face-smile.png";
239
- chatIcons[':('] = "face-sad.png";
240
- chatIcons['(B)'] = "beer.png";
241
- chatIcons['(C)'] = "clock.png";
242
- chatIcons['(P)'] = "present.png";
243
- chatIcons[':P']= "face-raspberry.png";
244
- chatIcons[':Z']= "face-tired.png";
245
- chatIcons['(R)']= "rain.png";
246
- chatIcons['(S)']= "sun.png";
247
- chatIcons[';)']= "face-wink.png";
248
-
328
+ //Patterns
329
+ var html_tag_pattern=/.*\<[^>]+>.*/g
330
+ var simple_word_pattern=/^[aA-zZ0-9]+$/g
331
+ var http_urls_pattern=/(http(s)?:\/\/)([aA-zZ0-9%=_&+?])+([./-][aA-zZ0-9%=_&+?]+)*[/]?/g
332
+ var www_urls_pattern = /(www[.])([aA-zZ0-9%=_&+?])+([./-][aA-zZ0-9%=_&+?]+)*[/]?/g
333
+ var icons_a_pattern=/\([A-Z]\)/g
334
+ var icons_b_pattern=/((:|;)([()A-Z]))/g
335
+ var youtube_video_pattern=/(http(s)?:\/\/)?(((youtu.be\/)([aA-zZ0-9]+))|((www.youtube.com\/watch\?v=)([aA-z0-9Z&=.])+))/g
249
336
 
250
337
  function parseContent(content){
251
-
252
- var html_tag_pattern=/.*\<[^>]+>.*/g
253
- if (html_tag_pattern.test(content)){
254
- content = content.replace(/>/g, "&gt;");
338
+
339
+ if (content.match(html_tag_pattern)!=null){
340
+ content = content.replace(/>/g, "&gt;");
255
341
  content = content.replace(/</g, "&lt;");
256
- return "<pre>" + content + "</pre>"
257
- }
258
-
342
+ return "<pre>" + content + "</pre>"
343
+ }
344
+
259
345
  words = content.split(" ");
260
346
  for(i=0; i<words.length; i++){
261
347
  words[i] = parseWord(words[i]);
@@ -266,93 +352,77 @@ function parseContent(content){
266
352
 
267
353
  function parseWord(word){
268
354
 
269
- //Look for empty words
270
- if (word.trim()==""){
271
- return word
272
- }
273
-
274
- //Look for simple words
275
- var simple_word_pattern=/^[aA-zZ0-9]+$/g
276
- if (simple_word_pattern.test(word)){
277
- return word
278
- }
355
+ //Look for empty or simple words
356
+ if ((word.trim()=="")||(word.match(simple_word_pattern)!=null)){
357
+ return word
358
+ }
279
359
 
280
360
  //Look for http urls
281
- var http_urls_pattern=/(http(s)?:\/\/)([aA-zZ0-9%=_&+?])+([./-][aA-zZ0-9%=_&+?]+)*[/]?/g
282
- http_urls = word.match(http_urls_pattern)
361
+ var http_urls = word.match(http_urls_pattern)
283
362
  if (http_urls!=null){
284
- url = http_urls[0]
285
- type = getUrlType(url);
363
+ var url = http_urls[0]
364
+ var type = getUrlType(url);
286
365
 
287
366
  switch(type){
288
- case "link":
289
- link = buildUrlLink(url,url)
290
- subwords = word.split(url)
291
- word = parseWord(subwords[0]) + link + parseWord(subwords[1])
292
- break;
293
- case "image":
294
- imageLink = buildImageLink(url);
295
- subwords = word.split(url)
296
- word = parseWord(subwords[0]) + imageLink + parseWord(subwords[1])
297
- break;
298
- default:
367
+ case "link":
368
+ var link = buildUrlLink(url,url)
369
+ var subwords = splitFirst(word,url)
370
+ return parseWord(subwords[0]) + link + parseWord(subwords[1])
371
+ case "image":
372
+ var imageLink = buildImageLink(url);
373
+ var subwords = splitFirst(word,url)
374
+ return parseWord(subwords[0]) + imageLink + parseWord(subwords[1])
375
+ case "video-youtube":
376
+ var youtubeLink = buildYoutubeVideoLink(url);
377
+ var subwords = splitFirst(word,url)
378
+ return parseWord(subwords[0]) + youtubeLink + parseWord(subwords[1])
379
+ default:
380
+ return word
299
381
  }
300
- return word
301
382
  }
302
383
 
303
384
 
304
385
  //Look for www urls
305
- var www_urls_pattern = /(www[.])([aA-zZ0-9%=_&+?])+([.][aA-zZ0-9%=_&+?]+)*[/]?/g
306
- www_urls = word.match(www_urls_pattern)
386
+ var www_urls = word.match(www_urls_pattern)
307
387
  if (www_urls!=null){
308
- url = www_urls[0]
309
- type = getUrlType(url);
388
+ var url = www_urls[0]
389
+ var type = getUrlType(url);
310
390
 
311
391
  switch(type){
312
392
  case "link":
313
- link = buildUrlLink("http://" + url,url)
314
- subwords = word.split(url)
315
- word = parseWord(subwords[0]) + link + parseWord(subwords[1])
316
- break;
393
+ var link = buildUrlLink("http://" + url,url)
394
+ var subwords = splitFirst(word,url)
395
+ return parseWord(subwords[0]) + link + parseWord(subwords[1])
317
396
  case "image":
318
- imageLink = buildImageLink("http://" + url);
319
- subwords = word.split(url)
320
- word = parseWord(subwords[0]) + imageLink + parseWord(subwords[1])
321
- break;
397
+ var imageLink = buildImageLink("http://" + url);
398
+ var subwords = splitFirst(word,url)
399
+ return parseWord(subwords[0]) + imageLink + parseWord(subwords[1])
400
+ case "video-youtube":
401
+ var youtubeLink = buildYoutubeVideoLink("http://" + url);
402
+ var subwords = splitFirst(word,url)
403
+ return parseWord(subwords[0]) + youtubeLink + parseWord(subwords[1])
322
404
  default:
323
- }
324
- return word
405
+ return word
406
+ }
325
407
  }
326
408
 
327
- //Look for icons: Directly replace
328
- var icons_a_pattern=/\(([A-Z])+\)/g
329
- var icons_b_pattern=/(:|;)([()A-Z])(.)*/g
330
- if (((icons_a_pattern.test(word))) || (icons_b_pattern.test(word))) {
331
- for (var i in chatIcons) {
332
- word = word.replace(buildRegex(i), buildIconImage(i))
333
- }
409
+ //Look for icons: Regex
410
+ var icons_a = word.match(icons_a_pattern)
411
+ if(icons_a!=null){
412
+ for(g=0; g<icons_a.length; g++){
413
+ word = word.replace(buildRegex(icons_a[g]), buildIconImage(icons_a[g]))
414
+ }
415
+ }
416
+
417
+ var icons_b = word.match(icons_b_pattern)
418
+ if(icons_b!=null){
419
+ for(h=0; h<icons_b.length; h++){
420
+ word = word.replace(buildRegex(icons_b[h]), buildIconImage(icons_b[h]))
421
+ }
334
422
  }
335
-
336
- //Look for icons with Regex
337
- // var icons_a_pattern=/\(([A-Z])+\)/g
338
- // if (icons_a_pattern.test(word)){
339
- // icon = word.replace(/[^(]*(\([A-Z]+\))(\([A-Z]+\))?(.)*/g, "$1")
340
- // subwords = splitFirst(word,icon)
341
- // image = buildIconImage(icon);
342
- // return subwords[0] + image + subwords[1];
343
- // }
344
-
345
- // var icons_b_pattern=/:([()A-Z])(.)*/g
346
- // if (icons_b_pattern.test(word)){
347
- // icon = word.replace(/[aA-zZ]*(:[()A-Z])(.)*/g, "$1")
348
- // subwords = splitFirst(word,icon)
349
- // image = buildIconImage(icon);
350
- // return subwords[0] + image + subwords[1];
351
- //return parseWord(subwords[0]) + image + parseWord(subwords[1]);
352
- // }
353
423
 
354
-
355
- //No special content detected
424
+
425
+ //No special content detected (maybe emoticons but not special pattern like urls)
356
426
  return word
357
427
  }
358
428
 
@@ -369,138 +439,105 @@ function splitFirst(word,key){
369
439
  function buildIconImage(icon){
370
440
  if (icon in chatIcons){
371
441
  image_file = chatIcons[icon]
372
- image = "<img class=\"chatIcon\" src=\"assets/emoticons/" + image_file + "\"/>";
373
- return image
442
+ return "<img class=\"chatEmoticon\" src=\"assets/emoticons/" + image_file + "\"/>";
374
443
  }
375
444
  return icon
376
445
  }
377
446
 
378
447
  function buildUrlLink(url,name){
379
- link = "<a target=\"_blank\" class=\"chatLink\" href=\"" + url + "\">" + name + "</a>";
380
- return link
448
+ return "<a target=\"_blank\" class=\"chatLink\" href=\"" + url + "\">" + name + "</a>";
381
449
  }
382
450
 
383
451
  function buildImageLink(url){
384
- link = "<a target=\"_blank\" class=\"chatImageLink\" href=\"" + url + "\">" + "<img class=\"chatImage\" src=\"" + url + "\"/>" + "</a>";
385
- return link
386
- }
452
+ return "<a target=\"_blank\" class=\"chatImageLink\" href=\"" + url + "\">" + "<img class=\"chatImage\" src=\"" + url + "\"/>" + "</a>";
453
+ }
454
+
455
+ function buildYoutubeVideoLink(url){
456
+ //Get youtube video id
457
+ var youtube_video_id=url.split(/v\/|v=|youtu\.be\//)[1].split(/[?&]/)[0];
458
+ var youtube_api_url = "http://gdata.youtube.com/feeds/api/videos/" + youtube_video_id
459
+
460
+ //Get info from the video
461
+ $.ajax({
462
+ type: "GET",
463
+ url: youtube_api_url,
464
+ cache: false,
465
+ dataType:'jsonp',
466
+ success: function(data){
467
+ var url_name = url;
468
+ var youtube_video_thumbnail = "";
469
+
470
+ //Video title
471
+ var video_title = $(data).find("media\\:title")
472
+ if (video_title.length > 0) {
473
+ //url_name = url + " (" + $(video_title).text() + ")";
474
+ url_name = $(video_title).text()
475
+ }
476
+
477
+ //Thumbnails
478
+ var thumbnails = $(data).find("media\\:thumbnail")
479
+ if (thumbnails.length>0){
480
+ var thumbnail_url = $(thumbnails[0]).attr("url")
481
+ if (thumbnail_url!=null){
482
+ youtube_video_thumbnail = "<p><img class=\"chatVideoImage\" src=\"" + thumbnail_url + "\"/></p>";
483
+ }
484
+ }
485
+
486
+ //Replace video link
487
+ $("a[youtube_id=" + youtube_video_id + "]").html(buildUrlLink(url,url_name)+youtube_video_thumbnail);
488
+ },
489
+ error: function(xOptions, textStatus){
490
+ //Handle errors
491
+ }
492
+ });
387
493
 
494
+ return "<a target=\"_blank\" youtube_id=\"" + youtube_video_id + "\" class=\"chatLink\" href=\"" + url + "\">" + url + "</a>";
495
+ }
388
496
 
389
497
  function buildRegex(word){
390
- word = word.replace(")","\\)")
391
- word = word.replace("(","\\(")
392
- pattern = "(" + word + ")";
498
+ word = word.replace(")","\\)")
499
+ word = word.replace("(","\\(")
500
+ var pattern = "(" + word + ")";
393
501
  pattern = buildPattern(pattern)
394
502
  return (new RegExp(pattern,'g'));
395
503
  }
396
504
 
397
505
  function buildPattern(pattern){
398
- //Escape pattern special characters
506
+ //Escape pattern special characters
399
507
  pattern = pattern.replace("+","\\+")
400
508
  pattern = pattern.replace("?","\\?")
401
509
  return pattern
402
510
  }
403
511
 
512
+
404
513
  function getUrlType(url){
405
- urlArray = url.split(".");
514
+
515
+ if (url.match(youtube_video_pattern)!=null){
516
+ return "video-youtube"
517
+ }
518
+
519
+ var urlArray = url.split(".");
406
520
  if (urlArray!=null && urlArray.length>0){
407
- extension= urlArray[urlArray.length-1]
521
+ var extension= urlArray[urlArray.length-1]
408
522
  } else {
409
- extension = null;
523
+ var extension = null;
410
524
  }
411
525
 
412
526
  switch(extension){
413
- case "jpg":
414
- return "image"
415
- break;
416
- case "png":
417
- return "image"
418
- break;
419
- case "gif":
420
- return "image"
421
- break;
422
- default:
423
- return "link"
424
- }
425
- }
426
-
427
-
428
-
429
- function onPresence(presence) {
430
-
431
- //Check presence stanza type
432
- ptype = $(presence).attr('type');
433
-
434
- switch (ptype){
435
- case undefined:
436
- processAvailablePresenceStanza(presence)
437
- break;
438
- case "available":
439
- processAvailablePresenceStanza(presence)
440
- break;
441
- case "unavailable":
442
- processUnavailablePresenceStanza(presence)
443
- break;
444
- default :
445
- //Stanza type not recognize
446
- processAvailablePresenceStanza(presence)
447
- }
448
-
449
- return true;
450
- }
451
-
452
- function processAvailablePresenceStanza(presence){
453
- from = $(presence).attr('from');
454
- slug = from.split("@")[0];
455
-
456
- if (slug != user_slug) {
457
- if (getConnectionBoxFromSlug(slug)!=null){
458
- status = $(presence).find('show').text();
459
- setUserIconStatus(slug, status);
460
- if (cacheConnectedUsers.indexOf(slug) != -1) {
461
- showConnectionBoxFromSlug(slug);
462
- }
463
- } else {
464
- setTimeout("refreshChatWindow()", 3000);
465
- }
466
- }
467
- }
468
-
469
- function processUnavailablePresenceStanza(presence){
470
- from = $(presence).attr('from');
471
- slug = from.split("@")[0];
472
-
473
- if (slug != user_slug) {
474
- if (getConnectionBoxFromSlug(slug)!=null){
475
- hideConnectionBoxFromSlug(slug)
476
- }
527
+ case "jpg":
528
+ return "image"
529
+ break;
530
+ case "png":
531
+ return "image"
532
+ break;
533
+ case "gif":
534
+ return "image"
535
+ break;
536
+ default:
537
+ return "link"
477
538
  }
478
539
  }
479
540
 
480
- function sendChatMessage(from,to,text){
481
- var type = "chat";
482
- var body= $build("body");
483
- body.t(text);
484
- var message = $msg({to: to, from: from, type: 'chat'}).cnode(body.tree());
485
- connection.send(message.tree());
486
- resumeAwayTimerIfAway();
487
- return true;
488
- }
489
-
490
- function authByCookie(){
491
- var authMethod = '<%= SocialStream::Presence.auth_method %>';
492
- return authMethod=="cookie";
493
- }
494
-
495
- function authByPassword(){
496
- var authMethod = '<%= SocialStream::Presence.auth_method %>';
497
- return authMethod=="password";
498
- }
499
-
500
- function ifCookie(){
501
- return (!(typeof cookie == 'undefined'))
502
- }
503
-
504
541
  ////////////////////
505
542
  //Audio functions
506
543
  ////////////////////
@@ -239,14 +239,19 @@ input.connectChatButton{
239
239
  }
240
240
 
241
241
 
242
- /* Chat text */
242
+ /* Chat text style */
243
243
 
244
244
  .chatImage {
245
245
  max-width: 100px;
246
246
  max-height: 100px;
247
247
  }
248
248
 
249
- .chatIcon {
249
+ .chatVideoImage {
250
+ max-width: 100px;
251
+ max-height: 100px;
252
+ }
253
+
254
+ .chatEmoticon {
250
255
  max-width:20px;
251
256
  max-height: 20px;
252
257
  }
@@ -255,5 +260,6 @@ a.chatLink:link, a.chatLink:visited {
255
260
  color: #1E726A;
256
261
  }
257
262
 
258
- .chatImageLink {
263
+ a.chatImageLink:link, a.chatImageLink:visited {
264
+ color: #1E726A;
259
265
  }
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.files = `git ls-files`.split("\n")
12
12
 
13
13
  # Gem dependencies
14
- s.add_runtime_dependency('social_stream-base', '~> 0.9.29')
14
+ s.add_runtime_dependency('social_stream-base', '~> 0.9.30')
15
15
  s.add_runtime_dependency('social_stream-documents', '~> 0.4.4')
16
16
  s.add_runtime_dependency('social_stream-events', '~> 0.0.20')
17
17
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_stream
3
3
  version: !ruby/object:Gem::Version
4
- hash: 33
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 12
9
- - 7
10
- version: 0.12.7
9
+ - 8
10
+ version: 0.12.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - GING - DIT - UPM
@@ -27,12 +27,12 @@ dependencies:
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- hash: 1
30
+ hash: 7
31
31
  segments:
32
32
  - 0
33
33
  - 9
34
- - 29
35
- version: 0.9.29
34
+ - 30
35
+ version: 0.9.30
36
36
  type: :runtime
37
37
  version_requirements: *id001
38
38
  - !ruby/object:Gem::Dependency