social_stream 0.24.1 → 0.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/base/app/assets/javascripts/social_stream.action.js +40 -0
  2. data/base/app/assets/javascripts/social_stream.comments.js +26 -1
  3. data/base/app/assets/javascripts/social_stream.timeline.js +15 -7
  4. data/base/app/assets/javascripts/social_stream.wall.js.erb +1 -0
  5. data/base/app/assets/stylesheets/social_stream-base.css.scss +13 -0
  6. data/base/app/models/activity.rb +5 -1
  7. data/base/app/models/activity_action.rb +6 -0
  8. data/base/app/models/activity_object.rb +131 -9
  9. data/base/app/models/actor.rb +2 -0
  10. data/base/app/models/channel.rb +0 -1
  11. data/base/app/models/comment.rb +0 -6
  12. data/base/app/views/activity_actions/_update.js.erb +11 -0
  13. data/base/app/views/activity_actions/create.js.erb +1 -1
  14. data/base/app/views/activity_actions/update.js.erb +1 -1
  15. data/base/app/views/comments/create.js.erb +1 -1
  16. data/base/app/views/posts/create.js.erb +1 -1
  17. data/base/db/migrate/20120111141717_create_social_stream.rb +265 -0
  18. data/base/db/migrate/20120326083509_object_channels_to_actions.rb +45 -0
  19. data/base/lib/social_stream/ability/base.rb +2 -2
  20. data/base/lib/social_stream/base/version.rb +1 -1
  21. data/base/lib/social_stream/controllers/cancan_devise_integration.rb +9 -5
  22. data/base/lib/social_stream/models/object.rb +0 -72
  23. data/base/lib/social_stream/models/subject.rb +2 -1
  24. data/base/lib/social_stream/models/subtype.rb +6 -1
  25. data/base/spec/controllers/groups_controller_spec.rb +6 -0
  26. data/base/spec/factories/post.rb +6 -0
  27. data/base/spec/models/activity_action_spec.rb +35 -0
  28. data/documents/app/assets/javascripts/social_stream.video.js.erb +2 -1
  29. data/documents/app/controllers/documents_controller.rb +4 -1
  30. data/documents/app/models/document.rb +10 -0
  31. data/documents/app/models/video.rb +17 -1
  32. data/documents/app/views/videos/_video_processed.html.erb +1 -0
  33. data/documents/app/views/videos/_video_show.html.erb +2 -1
  34. data/documents/db/migrate/{20110615143707_create_social_stream_documents.rb → 20120109155431_create_social_stream_documents.rb} +9 -11
  35. data/documents/lib/social_stream/documents/engine.rb +1 -0
  36. data/documents/lib/social_stream/documents/version.rb +1 -1
  37. data/documents/social_stream-documents.gemspec +1 -1
  38. data/events/app/assets/javascripts/social_stream.calendar.js.erb +15 -9
  39. data/events/app/assets/javascripts/social_stream.events.action.js +31 -0
  40. data/events/db/migrate/20111218203314_create_events.rb +33 -0
  41. data/events/db/migrate/20120330131859_create_social_stream_events.rb +10 -0
  42. data/events/lib/social_stream/events/version.rb +1 -1
  43. data/events/social_stream-events.gemspec +1 -1
  44. data/lib/social_stream/version.rb +1 -1
  45. data/lib/tasks/migrations.rake +2 -0
  46. data/linkser/app/views/links/create.js.erb +1 -1
  47. data/linkser/db/migrate/{20111129100618_create_social_stream_linkser.rb → 20111219122952_create_social_stream_linkser.rb} +4 -7
  48. data/linkser/lib/social_stream/linkser/version.rb +1 -1
  49. data/linkser/social_stream-linkser.gemspec +1 -1
  50. data/presence/db/migrate/20120330132148_create_social_stream_presence.rb +10 -0
  51. data/presence/lib/social_stream/presence/version.rb +1 -1
  52. data/presence/social_stream-presence.gemspec +1 -1
  53. data/social_stream.gemspec +5 -5
  54. metadata +42 -54
  55. data/base/app/assets/stylesheets/social_stream-base.css +0 -5
  56. data/base/app/views/activity_actions/_update_form.js.erb +0 -2
  57. data/base/db/migrate/20110610112023_create_social_stream.rb +0 -319
  58. data/base/db/migrate/20110705103202_empty_ties_count.rb +0 -17
  59. data/base/db/migrate/20110712090343_remove_spheres.rb +0 -30
  60. data/base/db/migrate/20110712142140_remove_permission_function.rb +0 -26
  61. data/base/db/migrate/20110912074426_add_reject_relation.rb +0 -29
  62. data/base/db/migrate/20111124100618_object_actors.rb +0 -52
  63. data/base/db/migrate/20111221103509_add_language_field.rb +0 -13
  64. data/base/db/migrate/20120103103125_add_channels.rb +0 -88
  65. data/base/db/migrate/20120109081509_update_notify_permissions.rb +0 -15
  66. data/base/db/migrate/20120111120920_remove_language_default.rb +0 -9
  67. data/base/db/migrate/20120111141717_activity_channels.rb +0 -74
  68. data/documents/db/migrate/20110922173707_add_file_processing_to_document.rb +0 -9
  69. data/documents/db/migrate/20111005112707_add_title_and_description_to_document.rb +0 -11
  70. data/documents/db/migrate/20120109155431_document_object_type.rb +0 -16
  71. data/events/db/migrate/20111101193523_create_events.rb +0 -13
  72. data/events/db/migrate/20111120104349_create_rooms.rb +0 -26
  73. data/events/db/migrate/20111204155637_add_scheduler.rb +0 -33
  74. data/events/db/migrate/20111218203314_change_scheduler.rb +0 -11
  75. data/linkser/db/migrate/20111219122952_add_width_height_to_link.rb +0 -15
@@ -0,0 +1,40 @@
1
+ SocialStream.Action = (function(SS, $, undefined){
2
+ var updateCallbacks = [];
3
+
4
+ var addUpdateCallback = function(callback){
5
+ updateCallbacks.push(callback);
6
+ }
7
+
8
+ var update = function(action){
9
+ $.each(updateCallbacks, function(i, callback){ callback(action); });
10
+ }
11
+
12
+ var updateFollow = function(action){
13
+ var follow = action.follow;
14
+
15
+ if (!follow) {
16
+ return;
17
+ }
18
+
19
+ followForms(action).replaceWith(follow.form);
20
+ followSentences(action).replaceWith(follow.sentence);
21
+ }
22
+
23
+ var followForms = function(action) {
24
+ return $('.follow_form-' + action.activity_object.id);
25
+ }
26
+
27
+ var followSentences = function(action) {
28
+ return $('.follow_sentence-' + action.activity_object.id);
29
+ }
30
+
31
+ addUpdateCallback(updateFollow);
32
+
33
+ return {
34
+ addUpdateCallback: addUpdateCallback,
35
+ update: update,
36
+ followForms: followForms,
37
+ followSentences: followSentences
38
+ }
39
+
40
+ })(SocialStream, jQuery);
@@ -10,22 +10,38 @@ SocialStream.Comments = (function(SS, $, undefined){
10
10
  $(".activity_new_comment").each(function(){
11
11
  if ($.trim($(this).siblings(".activity_comments").text()) != ""){
12
12
  $(this).show();
13
+ $(this).find(".input_new_comments").val("");
13
14
  }
14
15
  });
15
16
 
17
+ hideNewCommentElements();
18
+ newCommentWatermark();
19
+ newCommentAutoSize();
20
+ newCommentClick();
21
+ newCommentLink();
22
+ }
23
+
24
+ var hideNewCommentElements = function(){
16
25
  $(".activities_comment_btn").hide();
17
26
  $(".actor_name_new_comment").hide();
18
27
  $(".actor_logo_new_comment").hide();
28
+ }
19
29
 
30
+ var newCommentWatermark = function(){
20
31
  $(".input_new_comments").watermark(I18n.t('comment.input'),"#666");
32
+ }
33
+
21
34
 
35
+ var newCommentAutoSize = function(){
22
36
  $(".input_new_comments")
23
37
  .change(function(){autoSize(this);})
24
38
  .keydown(function(){autoSize(this);})
25
39
  .keyup(function(){autoSize(this);});
26
40
 
27
41
  $(".input_new_comments").each(function(){autoSize(this)});
42
+ }
28
43
 
44
+ var newCommentClick = function(){
29
45
  $(".input_new_comments").click(function(){
30
46
  $(".activities_comment_btn").hide();
31
47
  $(".new_comment").removeClass("new_comment_shown");
@@ -38,7 +54,9 @@ SocialStream.Comments = (function(SS, $, undefined){
38
54
  comment.find(".actor_logo_new_comment").show();
39
55
  return false;
40
56
  });
57
+ }
41
58
 
59
+ var newCommentLink = function(){
42
60
  //javascript for tocomment option
43
61
  $(".to_comment").click(function(){
44
62
  $(this).parents(".activity_content").find(".activity_new_comment").show();
@@ -49,7 +67,7 @@ SocialStream.Comments = (function(SS, $, undefined){
49
67
  .focus()
50
68
  .val("");
51
69
 
52
- return false;
70
+ return false;
53
71
  });
54
72
  }
55
73
 
@@ -61,6 +79,13 @@ SocialStream.Comments = (function(SS, $, undefined){
61
79
  }
62
80
 
63
81
  SocialStream.Timeline.addInitCallback(initNew);
82
+
83
+ SocialStream.Timeline.addCreateCallback(hideNewCommentElements);
84
+ SocialStream.Timeline.addCreateCallback(newCommentWatermark);
85
+ SocialStream.Timeline.addCreateCallback(newCommentAutoSize);
86
+ SocialStream.Timeline.addCreateCallback(newCommentClick);
87
+ SocialStream.Timeline.addCreateCallback(newCommentLink);
88
+
64
89
  SocialStream.Objects.addInitCallback(initNew);
65
90
 
66
91
  return {
@@ -1,14 +1,24 @@
1
1
  SocialStream.Timeline = (function(SS, $, undefined){
2
+ // FIXME: DRY!!
2
3
  var initCallbacks = [];
4
+ var createCallbacks = [];
3
5
 
4
6
  var addInitCallback = function(callback){
5
7
  initCallbacks.push(callback);
6
8
  }
7
9
 
10
+ var addCreateCallback = function(callback){
11
+ createCallbacks.push(callback);
12
+ }
13
+
8
14
  var init = function(){
9
15
  $.each(initCallbacks, function(i, callback){ callback(); });
10
16
  }
11
17
 
18
+ var create = function(activityId){
19
+ $.each(createCallbacks, function(i, callback){ callback(activityId); });
20
+ }
21
+
12
22
  var initPrivacyTooltips = function(activityId) {
13
23
  var fullId = '.activity_audience';
14
24
  var summaryId = '.activity_audience_summary';
@@ -51,19 +61,17 @@ SocialStream.Timeline = (function(SS, $, undefined){
51
61
  };
52
62
 
53
63
 
54
- var newActivity = function(activityId){
55
- initPrivacyTooltips(activityId);
56
- SS.Wall.unblockForms();
57
- }
58
-
59
64
  addInitCallback(initPrivacyTooltips);
60
65
  addInitCallback(initComments);
61
66
 
67
+ addCreateCallback(initPrivacyTooltips);
68
+
62
69
  return {
63
70
  addInitCallback: addInitCallback,
64
71
  init: init,
72
+ addCreateCallback: addCreateCallback,
73
+ create: create,
65
74
  initPrivacyTooltips: initPrivacyTooltips,
66
- showAllComments: showAllComments,
67
- newActivity: newActivity
75
+ showAllComments: showAllComments
68
76
  };
69
77
  }) (SocialStream, jQuery);
@@ -140,6 +140,7 @@ SocialStream.Wall = (function(SS, $, undefined){
140
140
  addInitCallback(initSecuritySelect);
141
141
  addInitCallback(activateAntiRebounds);
142
142
 
143
+ SS.Timeline.addCreateCallback(unblockForms);
143
144
  return {
144
145
  addInitCallback: addInitCallback,
145
146
  init: init,
@@ -0,0 +1,13 @@
1
+ /*
2
+ *= require avatars_for_rails
3
+ *
4
+ *= require_self
5
+ *= require_tree .
6
+ */
7
+
8
+ @import "colors";
9
+
10
+ .ui-effects-transfer {
11
+ border: 2px solid $separation-color;
12
+ background-color: $secondary-color;
13
+ }
@@ -331,13 +331,17 @@ class Activity < ActiveRecord::Base
331
331
  def fill_relations
332
332
  return if relation_ids.present?
333
333
 
334
- # FIXME: repeated in SocialStream::Models::Object#_relation_ids
335
334
  self.relation_ids =
335
+ # FIXME: repeated in ActivityObject#_relation_ids
336
+ if SocialStream.relation_model == :custom
336
337
  if channel.reflexive?
337
338
  receiver.relation_customs.map(&:id)
338
339
  else
339
340
  receiver.relation_customs.allow(channel.author, 'create', 'activity').map(&:id)
340
341
  end
342
+ else
343
+ Array.wrap Relation::Public.instance.id
344
+ end
341
345
  end
342
346
 
343
347
  #
@@ -15,6 +15,8 @@ class ActivityAction < ActiveRecord::Base
15
15
  where(:activity_object_id => ActivityObject.normalize_id(activity_object))
16
16
  }
17
17
 
18
+ before_create :follow_by_author_and_owner
19
+
18
20
  private
19
21
 
20
22
  # Updates the follower_count counter in the {ActivityObject}
@@ -25,4 +27,8 @@ class ActivityAction < ActiveRecord::Base
25
27
  activity_object.increment!(:follower_count) :
26
28
  activity_object.decrement!(:follower_count)
27
29
  end
30
+
31
+ def follow_by_author_and_owner
32
+ self.follow = true if author? || user_author? || owner?
33
+ end
28
34
  end
@@ -9,8 +9,8 @@
9
9
  # Objects are added to +config/initializers/social_stream.rb+
10
10
  #
11
11
  class ActivityObject < ActiveRecord::Base
12
- # See {SocialStream::Models::Channeled}
13
- channeled
12
+ attr_writer :_relation_ids
13
+ attr_reader :_activity_parent_id
14
14
 
15
15
  # ActivityObject is a supertype of SocialStream.objects
16
16
  supertype_of :object
@@ -22,7 +22,8 @@ class ActivityObject < ActiveRecord::Base
22
22
 
23
23
  has_many :received_actions,
24
24
  :class_name => "ActivityAction",
25
- :dependent => :destroy
25
+ :dependent => :destroy,
26
+ :autosave => true
26
27
  has_many :followers,
27
28
  :through => :received_actions,
28
29
  :source => :actor,
@@ -43,10 +44,71 @@ class ActivityObject < ActiveRecord::Base
43
44
 
44
45
  validates_presence_of :object_type
45
46
 
47
+ # TODO: This is currently defined in lib/social_stream/models/object.rb
48
+ #
49
+ # Need to fix activity_object_spec_helper before activating it
50
+ #
51
+ # validates_presence_of :author_id, :owner_id, :user_author_id, :unless => :acts_as_actor?
52
+ # after_create :create_post_activity, :unless => :acts_as_actor?
53
+
46
54
  scope :authored_by, lambda { |subject|
47
- joins(:channel).merge(Channel.authored_by(subject))
55
+ joins(:received_author_action).merge(ActivityAction.sent_by(subject))
48
56
  }
49
57
 
58
+ scope :followed, order("activity_objects.follower_count DESC")
59
+
60
+ def received_role_action(role)
61
+ received_actions.
62
+ find{ |a| a.__send__ "#{ role }?" }
63
+ end
64
+
65
+ %w{ author user_author owner }.each do |role|
66
+ code = <<-EOC
67
+ def #{ role }_id # def author_id
68
+ received_role_action(:#{ role }). # received_role_action(:author).
69
+ try(:actor_id) # try(:actor_id)
70
+ end # end
71
+
72
+ def #{ role }_id=(actor_id) # def author_id=(actor_id)
73
+ action = # action =
74
+ received_actions. # received_actions.
75
+ find{ |a| a.actor_id == actor_id } # select{ |a| a.actor_id == actor_id }
76
+ #
77
+ if action # if action
78
+ action.#{ role } = true # action.author = true
79
+ else # else
80
+ received_actions. # received_actions.
81
+ build :actor_id => actor_id, # build :actor_id => actor_id,
82
+ :#{ role } => true # :author => true
83
+ end # end
84
+ #
85
+ actor_id # actor_id
86
+ end # end
87
+
88
+ def #{ role } # def author
89
+ received_role_action(:#{ role }). # received_role_action(:author).
90
+ try(:actor) # try(:actor)
91
+ end # end
92
+
93
+ def #{ role }=(actor) # def author=(actor)
94
+ self.#{ role }_id = # self.author_id =
95
+ Actor.normalize_id(actor) # Actor.normalize_id(actor)
96
+ end # end
97
+
98
+ def #{ role }_subject # def author_subject
99
+ #{ role }.subject # author.subject
100
+ end # end
101
+
102
+ EOC
103
+
104
+ class_eval code, __FILE__, __LINE__ - code.lines.count - 2
105
+ end
106
+
107
+ # Was the author represented when this {ActivityObject} was created?
108
+ def represented_author?
109
+ author_id != user_author_id
110
+ end
111
+
50
112
  # The object of this activity object
51
113
  def object
52
114
  subtype_instance.is_a?(Actor) ?
@@ -54,11 +116,6 @@ class ActivityObject < ActiveRecord::Base
54
116
  subtype_instance
55
117
  end
56
118
 
57
- # The activity in which this activity_object was created
58
- def post_activity
59
- activities.includes(:activity_verb).where('activity_verbs.name' => 'post').first
60
- end
61
-
62
119
  # Does this {ActivityObject} has {Actor}?
63
120
  def acts_as_actor?
64
121
  object_type == "Actor"
@@ -69,4 +126,69 @@ class ActivityObject < ActiveRecord::Base
69
126
  received_actions.sent_by(actor).first
70
127
  end
71
128
 
129
+ # The activity in which this activity_object was created
130
+ def post_activity
131
+ activities.includes(:activity_verb).where('activity_verbs.name' => 'post').first
132
+ end
133
+
134
+ # Build the post activity when this object is not saved
135
+ def build_post_activity
136
+ Activity.new :author => author,
137
+ :user_author => user_author,
138
+ :owner => owner,
139
+ :relation_ids => Array(_relation_ids)
140
+ end
141
+
142
+ def _relation_ids
143
+ @_relation_ids ||=
144
+ if author.blank? || owner.blank?
145
+ nil
146
+ else
147
+ # FIXME: repeated in Activity#fill_relations
148
+ if SocialStream.relation_model == :custom
149
+ if author == owner
150
+ owner.relation_customs.map(&:id)
151
+ else
152
+ owner.
153
+ relation_customs.
154
+ allow(author, 'create', 'activity').
155
+ map(&:id)
156
+ end
157
+ else
158
+ Array.wrap Relation::Public.instance.id
159
+ end
160
+ end
161
+ end
162
+
163
+ def _activity_parent
164
+ @_activity_parent ||= Activity.find(_activity_parent_id)
165
+ end
166
+
167
+ def _activity_parent_id=(id)
168
+ self._relation_ids = Activity.find(id).relation_ids
169
+ @_activity_parent_id = id
170
+ end
171
+
172
+ private
173
+
174
+ def create_post_activity
175
+ create_activity "post"
176
+ end
177
+
178
+ def create_update_activity
179
+ create_activity "update"
180
+ end
181
+
182
+ def create_activity(verb)
183
+ a = Activity.new :verb => verb,
184
+ :author_id => author_id,
185
+ :user_author => user_author,
186
+ :owner => owner,
187
+ :relation_ids => _relation_ids,
188
+ :parent_id => _activity_parent_id
189
+
190
+ a.activity_objects << self
191
+
192
+ a.save!
193
+ end
72
194
  end
@@ -113,6 +113,8 @@ class Actor < ActiveRecord::Base
113
113
  joins(:received_contacts).merge(Contact.active.sent_by(a))
114
114
  }
115
115
 
116
+ scope :followed, joins(:activity_object).merge(ActivityObject.followed)
117
+
116
118
  scope :followed_by, lambda { |a|
117
119
  select("DISTINCT actors.*").
118
120
  joins(:received_ties => { :relation => :permissions }).
@@ -19,7 +19,6 @@ class Channel < ActiveRecord::Base
19
19
  belongs_to :user_author,
20
20
  :class_name => "Actor"
21
21
 
22
- has_many :activity_objects, :dependent => :destroy
23
22
  has_many :activities, :dependent => :destroy
24
23
 
25
24
  validates_uniqueness_of :author_id, :scope => [ :owner_id, :user_author_id ]
@@ -10,16 +10,10 @@ class Comment < ActiveRecord::Base
10
10
  has created_at
11
11
  end
12
12
 
13
-
14
13
  def parent_post
15
14
  self.post_activity.parent.direct_object
16
15
  end
17
16
 
18
- def _activity_parent_id=(id)
19
- self._relation_ids = Activity.find(id).relation_ids
20
- @_activity_parent_id = id
21
- end
22
-
23
17
  def title
24
18
  description.truncate(30, :separator =>' ')
25
19
  end
@@ -0,0 +1,11 @@
1
+ SocialStream.Action.update({
2
+ activity_object: {
3
+ id: "<%= dom_id(@activity_action.activity_object) %>",
4
+ type: "<%= @activity_action.activity_object.object_type %>"
5
+ },
6
+ follow: {
7
+ following: <%= @activity_action.follow? %>,
8
+ form: "<%= escape_javascript render(:partial => 'activity_actions/follow_form', :locals => { :activity_object => @activity_action.activity_object }) %>",
9
+ sentence: "<%= escape_javascript render(:partial => 'activity_actions/follow_sentence', :locals => { :activity_object => @activity_action.activity_object }) %>"
10
+ }
11
+ });