social_stream-base 0.21.2 → 0.22.0
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/app/models/activity.rb +4 -2
- data/app/models/activity_action.rb +3 -2
- data/app/models/activity_object.rb +17 -10
- data/app/models/actor.rb +14 -1
- data/app/models/comment.rb +24 -0
- data/app/views/activities/_comments.html.erb +3 -1
- data/db/migrate/20120621135650_add_comment_count_to_activity_object.rb +24 -0
- data/db/migrate/20120627115244_fix_activity_object_follower_count.rb +17 -0
- data/lib/social_stream/base/version.rb +1 -1
- data/social_stream-base.gemspec +1 -1
- data/spec/integration/activity.rb +15 -0
- data/spec/models/activity_action_spec.rb +8 -0
- metadata +9 -6
data/app/models/activity.rb
CHANGED
|
@@ -182,12 +182,14 @@ class Activity < ActiveRecord::Base
|
|
|
182
182
|
|
|
183
183
|
# The first activity object of this activity
|
|
184
184
|
def direct_activity_object
|
|
185
|
-
|
|
185
|
+
@direct_activity_object ||=
|
|
186
|
+
activity_objects.first
|
|
186
187
|
end
|
|
187
188
|
|
|
188
189
|
# The first object of this activity
|
|
189
190
|
def direct_object
|
|
190
|
-
|
|
191
|
+
@direct_object ||=
|
|
192
|
+
direct_activity_object.try(:object)
|
|
191
193
|
end
|
|
192
194
|
|
|
193
195
|
# The title for this activity in the stream
|
|
@@ -5,8 +5,6 @@ class ActivityAction < ActiveRecord::Base
|
|
|
5
5
|
belongs_to :actor
|
|
6
6
|
belongs_to :activity_object
|
|
7
7
|
|
|
8
|
-
before_save :change_follower_count
|
|
9
|
-
|
|
10
8
|
scope :sent_by, lambda{ |actor|
|
|
11
9
|
where(:actor_id => Actor.normalize_id(actor))
|
|
12
10
|
}
|
|
@@ -27,8 +25,11 @@ class ActivityAction < ActiveRecord::Base
|
|
|
27
25
|
authored_or_owned.sent_by(subject)
|
|
28
26
|
}
|
|
29
27
|
|
|
28
|
+
|
|
30
29
|
before_create :follow_by_author_and_owner
|
|
31
30
|
|
|
31
|
+
after_save :change_follower_count
|
|
32
|
+
|
|
32
33
|
private
|
|
33
34
|
|
|
34
35
|
# Updates the follower_count counter in the {ActivityObject}
|
|
@@ -92,6 +92,21 @@ class ActivityObject < ActiveRecord::Base
|
|
|
92
92
|
merge(ActivityObjectAudience.where(:relation_id => Relation.ids_shared_with(subject)))
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
# Obtain the {ActivityAction} between this {ActivityObject}
|
|
96
|
+
# and the {Actor} identified by actor_id
|
|
97
|
+
def received_action_by(actor_id)
|
|
98
|
+
received_actions.
|
|
99
|
+
find{ |a| a.actor_id == actor_id }
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Obtain received_action_by(actor_id) or create it if it does
|
|
103
|
+
# not exist
|
|
104
|
+
def received_action_by!(actor_id)
|
|
105
|
+
received_action_by(actor_id) ||
|
|
106
|
+
received_actions.build(:actor_id => actor_id)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Get the first {ActivityAction} that has activated the role flag
|
|
95
110
|
def received_role_action(role)
|
|
96
111
|
received_actions.
|
|
97
112
|
find{ |a| a.__send__ "#{ role }?" }
|
|
@@ -106,16 +121,9 @@ class ActivityObject < ActiveRecord::Base
|
|
|
106
121
|
|
|
107
122
|
def #{ role }_id=(actor_id) # def author_id=(actor_id)
|
|
108
123
|
action = # action =
|
|
109
|
-
|
|
110
|
-
find{ |a| a.actor_id == actor_id } # select{ |a| a.actor_id == actor_id }
|
|
124
|
+
received_action_by!(actor_id) # received_action_by!(actor_id)
|
|
111
125
|
#
|
|
112
|
-
|
|
113
|
-
action.#{ role } = true # action.author = true
|
|
114
|
-
else # else
|
|
115
|
-
received_actions. # received_actions.
|
|
116
|
-
build :actor_id => actor_id, # build :actor_id => actor_id,
|
|
117
|
-
:#{ role } => true # :author => true
|
|
118
|
-
end # end
|
|
126
|
+
action.#{ role } = true # action.author = true
|
|
119
127
|
#
|
|
120
128
|
actor_id # actor_id
|
|
121
129
|
end # end
|
|
@@ -133,7 +141,6 @@ class ActivityObject < ActiveRecord::Base
|
|
|
133
141
|
def #{ role }_subject # def author_subject
|
|
134
142
|
#{ role }.subject # author.subject
|
|
135
143
|
end # end
|
|
136
|
-
|
|
137
144
|
EOC
|
|
138
145
|
|
|
139
146
|
class_eval code, __FILE__, __LINE__ - code.lines.count - 2
|
data/app/models/actor.rb
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# type of a {Tie} is a {Relation}. Each actor can define and customize their relations own
|
|
6
6
|
# {Relation Relations}.
|
|
7
7
|
#
|
|
8
|
-
# Every {Actor} has an Avatar, a {Profile} with personal
|
|
8
|
+
# Every {Actor} has an Avatar, a {Profile} with personal or group information, contact data, etc.
|
|
9
9
|
#
|
|
10
10
|
# {Actor Actors} perform {ActivityAction actions} (like, suscribe, etc.) on
|
|
11
11
|
# {ActivityObject activity objects} ({Post posts}, {Comment commments}, pictures, events..)
|
|
@@ -81,6 +81,19 @@ class Actor < ActiveRecord::Base
|
|
|
81
81
|
:source => :activity_object,
|
|
82
82
|
:conditions => { 'activity_actions.follow' => true }
|
|
83
83
|
|
|
84
|
+
has_many :authored_activities,
|
|
85
|
+
:class_name => "Activity",
|
|
86
|
+
:foreign_key => :author_id,
|
|
87
|
+
:dependent => :destroy
|
|
88
|
+
has_many :user_authored_activities,
|
|
89
|
+
:class_name => "Activity",
|
|
90
|
+
:foreign_key => :user_author_id,
|
|
91
|
+
:dependent => :destroy
|
|
92
|
+
has_many :owned_activities,
|
|
93
|
+
:class_name => "Activity",
|
|
94
|
+
:foreign_key => :owner_id,
|
|
95
|
+
:dependent => :destroy
|
|
96
|
+
|
|
84
97
|
scope :alphabetic, order('actors.name')
|
|
85
98
|
|
|
86
99
|
scope :letter, lambda { |param|
|
data/app/models/comment.rb
CHANGED
|
@@ -4,6 +4,9 @@ class Comment < ActiveRecord::Base
|
|
|
4
4
|
alias_attribute :text, :description
|
|
5
5
|
validates_presence_of :text
|
|
6
6
|
|
|
7
|
+
after_create :increment_comment_count
|
|
8
|
+
before_destroy :decrement_comment_count
|
|
9
|
+
|
|
7
10
|
define_index do
|
|
8
11
|
activity_object_index
|
|
9
12
|
end
|
|
@@ -15,4 +18,25 @@ class Comment < ActiveRecord::Base
|
|
|
15
18
|
def title
|
|
16
19
|
description.truncate(30, :separator =>' ')
|
|
17
20
|
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
# after_create callback
|
|
25
|
+
#
|
|
26
|
+
# Increment comment counter in parent's activity_object with a comment
|
|
27
|
+
def increment_comment_count
|
|
28
|
+
return if self.post_activity.parent.blank?
|
|
29
|
+
|
|
30
|
+
self.post_activity.parent.direct_activity_object.increment!(:comment_count)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# before_destroy callback
|
|
34
|
+
#
|
|
35
|
+
# Decrement comment counter in parent's activity_object when comment is destroyed
|
|
36
|
+
def decrement_comment_count
|
|
37
|
+
return if self.post_activity.blank? || self.post_activity.parent.blank?
|
|
38
|
+
|
|
39
|
+
self.post_activity.parent.direct_activity_object.decrement!(:comment_count)
|
|
40
|
+
end
|
|
41
|
+
|
|
18
42
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
class AddCommentCountToActivityObject < ActiveRecord::Migration
|
|
2
|
+
def up
|
|
3
|
+
add_column :activity_objects, :comment_count, :integer, :default => 0
|
|
4
|
+
|
|
5
|
+
ActivityObject.record_timestamps = false
|
|
6
|
+
ActivityObject.reset_column_information
|
|
7
|
+
|
|
8
|
+
ActivityObject.all.each do |ao|
|
|
9
|
+
parent_activity = ao.activities.first
|
|
10
|
+
|
|
11
|
+
# Actors have not parent activities
|
|
12
|
+
next if parent_activity.blank?
|
|
13
|
+
|
|
14
|
+
ao.update_attribute(:comment_count, Activity.includes(:activity_objects).where('activity_objects.object_type' => "Comment").where(:ancestry => [parent_activity.id]).size)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
ActivityObject.record_timestamps = true
|
|
18
|
+
ActivityObject.reset_column_information
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def down
|
|
22
|
+
remove_column :activity_objects, :comment_count
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Reset follower_count for all the ActivityObjects that are not Actors
|
|
2
|
+
# See: https://github.com/ging/social_stream/issues/274
|
|
3
|
+
class FixActivityObjectFollowerCount < ActiveRecord::Migration
|
|
4
|
+
def up
|
|
5
|
+
ActivityObject.record_timestamps = false
|
|
6
|
+
|
|
7
|
+
ActivityObject.where("object_type != ?", "Actor").all.each do |ao|
|
|
8
|
+
ao.update_attribute :follower_count, ao.received_actions.where(:follow => true).count
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
ActivityObject.record_timestamps = true
|
|
12
|
+
ActivityObject.reset_column_information
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def down
|
|
16
|
+
end
|
|
17
|
+
end
|
data/social_stream-base.gemspec
CHANGED
|
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
|
|
|
34
34
|
# jQuery
|
|
35
35
|
s.add_runtime_dependency('jquery-rails', '>= 1.0.9')
|
|
36
36
|
# Authorization
|
|
37
|
-
s.add_runtime_dependency('cancan', '
|
|
37
|
+
s.add_runtime_dependency('cancan', '1.6.7')
|
|
38
38
|
# Pagination
|
|
39
39
|
s.add_runtime_dependency('kaminari', '~> 0.13.0')
|
|
40
40
|
# OAuth client
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Activity do
|
|
4
|
+
before(:all) do
|
|
5
|
+
@activity = Factory(:activity)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "should be destroyed along with its author" do
|
|
9
|
+
author = @activity.author
|
|
10
|
+
|
|
11
|
+
author.destroy
|
|
12
|
+
|
|
13
|
+
Activity.find_by_id(@activity.id).should be_nil
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -31,6 +31,10 @@ describe ActivityAction do
|
|
|
31
31
|
it "should not be duplicated" do
|
|
32
32
|
@post.received_actions.count.should == 2
|
|
33
33
|
end
|
|
34
|
+
|
|
35
|
+
it "should initialize follower count" do
|
|
36
|
+
@post.reload.follower_count.should == 2
|
|
37
|
+
end
|
|
34
38
|
end
|
|
35
39
|
|
|
36
40
|
describe "where posting to self" do
|
|
@@ -41,6 +45,10 @@ describe ActivityAction do
|
|
|
41
45
|
it "should not be duplicated" do
|
|
42
46
|
@post.received_actions.count.should == 1
|
|
43
47
|
end
|
|
48
|
+
|
|
49
|
+
it "should initialize follower count" do
|
|
50
|
+
@post.reload.follower_count.should == 1
|
|
51
|
+
end
|
|
44
52
|
end
|
|
45
53
|
|
|
46
54
|
describe "where building the post" do
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: social_stream-base
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.22.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2012-06-
|
|
13
|
+
date: 2012-06-28 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: deep_merge
|
|
@@ -161,17 +161,17 @@ dependencies:
|
|
|
161
161
|
requirement: !ruby/object:Gem::Requirement
|
|
162
162
|
none: false
|
|
163
163
|
requirements:
|
|
164
|
-
- -
|
|
164
|
+
- - '='
|
|
165
165
|
- !ruby/object:Gem::Version
|
|
166
|
-
version: 1.6.
|
|
166
|
+
version: 1.6.7
|
|
167
167
|
type: :runtime
|
|
168
168
|
prerelease: false
|
|
169
169
|
version_requirements: !ruby/object:Gem::Requirement
|
|
170
170
|
none: false
|
|
171
171
|
requirements:
|
|
172
|
-
- -
|
|
172
|
+
- - '='
|
|
173
173
|
- !ruby/object:Gem::Version
|
|
174
|
-
version: 1.6.
|
|
174
|
+
version: 1.6.7
|
|
175
175
|
- !ruby/object:Gem::Dependency
|
|
176
176
|
name: kaminari
|
|
177
177
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -1059,6 +1059,8 @@ files:
|
|
|
1059
1059
|
- db/migrate/20120411132550_add_visit_count_to_activity_object.rb
|
|
1060
1060
|
- db/migrate/20120411151413_relation_public_permissions.rb
|
|
1061
1061
|
- db/migrate/20120526171311_remove_activity_channels.rb
|
|
1062
|
+
- db/migrate/20120621135650_add_comment_count_to_activity_object.rb
|
|
1063
|
+
- db/migrate/20120627115244_fix_activity_object_follower_count.rb
|
|
1062
1064
|
- lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb
|
|
1063
1065
|
- lib/acts_as_taggable_on/social_stream.rb
|
|
1064
1066
|
- lib/generators/social_stream/base/install_generator.rb
|
|
@@ -1195,6 +1197,7 @@ files:
|
|
|
1195
1197
|
- spec/factories/relation_custom.rb
|
|
1196
1198
|
- spec/factories/tie.rb
|
|
1197
1199
|
- spec/factories/user.rb
|
|
1200
|
+
- spec/integration/activity.rb
|
|
1198
1201
|
- spec/integration/navigation_spec.rb
|
|
1199
1202
|
- spec/integration/resque_access_spec.rb
|
|
1200
1203
|
- spec/models/activity_action_spec.rb
|