social_stream 0.27.3 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- activity_objects.first
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
- direct_activity_object.try(:object)
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
- received_actions. # received_actions.
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
- if action # if action
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
@@ -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 o group information, contact data, etc.
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|
@@ -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
@@ -1,3 +1,5 @@
1
1
  <div class="activity_comments" id="comments_<%= dom_id(activity) %>">
2
- <%= render activity.comments %>
2
+ <% if activity.direct_activity_object.blank? || activity.direct_activity_object.comment_count > 0 %>
3
+ <%= render activity.comments %>
4
+ <% end %>
3
5
  </div>
@@ -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
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Base
3
- VERSION = "0.21.2".freeze
3
+ VERSION = "0.22.0".freeze
4
4
  end
5
5
  end
@@ -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', '~> 1.6.4')
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
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Documents
3
- VERSION = "0.15.1".freeze
3
+ VERSION = "0.16.0".freeze
4
4
  end
5
5
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.files = `git ls-files`.split("\n")
13
13
 
14
14
  # Gem dependencies
15
- s.add_runtime_dependency('social_stream-base', '~> 0.21.1')
15
+ s.add_runtime_dependency('social_stream-base', '~> 0.22.0')
16
16
  s.add_runtime_dependency('paperclip-ffmpeg', '~> 0.7.0')
17
17
  s.add_runtime_dependency('paperclip','= 2.4.5')
18
18
  s.add_runtime_dependency('delayed_paperclip','2.4.5.1')
@@ -97,7 +97,8 @@ div.event_date {
97
97
 
98
98
  .event_details .follow_sentence {
99
99
  float: left;
100
- padding: 20px 10px;
100
+ padding: 10px 10px;
101
+ width: 175px;
101
102
  }
102
103
 
103
104
  .event_sidebar .event_frequency {
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Events
3
- VERSION = "0.13.2".freeze
3
+ VERSION = "0.14.0".freeze
4
4
  end
5
5
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.files = `git ls-files`.split("\n")
13
13
 
14
14
  # Gem dependencies
15
- s.add_runtime_dependency('social_stream-base', '~> 0.21.2')
15
+ s.add_runtime_dependency('social_stream-base', '~> 0.22.0')
16
16
  s.add_runtime_dependency('rails-scheduler', '~> 0.0.8')
17
17
 
18
18
  # Development Gem dependencies
@@ -1,3 +1,3 @@
1
1
  module SocialStream
2
- VERSION = "0.27.3".freeze
2
+ VERSION = "0.28.0".freeze
3
3
  end
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Linkser
3
- VERSION = "0.12.0".freeze
3
+ VERSION = "0.13.0".freeze
4
4
  end
5
5
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.files = `git ls-files`.split("\n")
13
13
 
14
14
  # Gem dependencies
15
- s.add_runtime_dependency('social_stream-base', '~> 0.21.0')
15
+ s.add_runtime_dependency('social_stream-base', '~> 0.22.0')
16
16
  s.add_runtime_dependency('linkser', '~> 0.0.12')
17
17
  # Development Gem dependencies
18
18
  s.add_development_dependency('sqlite3-ruby')
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Presence
3
- VERSION = "0.14.0"
3
+ VERSION = "0.15.0"
4
4
  end
5
5
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # Gem dependencies
22
- s.add_runtime_dependency('social_stream-base', '~> 0.21.0')
22
+ s.add_runtime_dependency('social_stream-base', '~> 0.22.0')
23
23
 
24
24
  s.add_runtime_dependency "xmpp4r"
25
25
 
@@ -11,11 +11,11 @@ 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.21.2')
15
- s.add_runtime_dependency('social_stream-documents', '~> 0.15.1')
16
- s.add_runtime_dependency('social_stream-events', '~> 0.13.2')
17
- s.add_runtime_dependency('social_stream-linkser', '~> 0.12.0')
18
- s.add_runtime_dependency('social_stream-presence', '~> 0.14.0')
14
+ s.add_runtime_dependency('social_stream-base', '~> 0.22.0')
15
+ s.add_runtime_dependency('social_stream-documents', '~> 0.16.0')
16
+ s.add_runtime_dependency('social_stream-events', '~> 0.14.0')
17
+ s.add_runtime_dependency('social_stream-linkser', '~> 0.13.0')
18
+ s.add_runtime_dependency('social_stream-presence', '~> 0.15.0')
19
19
 
20
20
  # Development Gem dependencies
21
21
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.3
4
+ version: 0.28.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-15 00:00:00.000000000 Z
13
+ date: 2012-06-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: social_stream-base
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 0.21.2
22
+ version: 0.22.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- version: 0.21.2
30
+ version: 0.22.0
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: social_stream-documents
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -35,7 +35,7 @@ dependencies:
35
35
  requirements:
36
36
  - - ~>
37
37
  - !ruby/object:Gem::Version
38
- version: 0.15.1
38
+ version: 0.16.0
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  requirements:
44
44
  - - ~>
45
45
  - !ruby/object:Gem::Version
46
- version: 0.15.1
46
+ version: 0.16.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: social_stream-events
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -51,7 +51,7 @@ dependencies:
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 0.13.2
54
+ version: 0.14.0
55
55
  type: :runtime
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
@@ -59,7 +59,7 @@ dependencies:
59
59
  requirements:
60
60
  - - ~>
61
61
  - !ruby/object:Gem::Version
62
- version: 0.13.2
62
+ version: 0.14.0
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: social_stream-linkser
65
65
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +67,7 @@ dependencies:
67
67
  requirements:
68
68
  - - ~>
69
69
  - !ruby/object:Gem::Version
70
- version: 0.12.0
70
+ version: 0.13.0
71
71
  type: :runtime
72
72
  prerelease: false
73
73
  version_requirements: !ruby/object:Gem::Requirement
@@ -75,7 +75,7 @@ dependencies:
75
75
  requirements:
76
76
  - - ~>
77
77
  - !ruby/object:Gem::Version
78
- version: 0.12.0
78
+ version: 0.13.0
79
79
  - !ruby/object:Gem::Dependency
80
80
  name: social_stream-presence
81
81
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +83,7 @@ dependencies:
83
83
  requirements:
84
84
  - - ~>
85
85
  - !ruby/object:Gem::Version
86
- version: 0.14.0
86
+ version: 0.15.0
87
87
  type: :runtime
88
88
  prerelease: false
89
89
  version_requirements: !ruby/object:Gem::Requirement
@@ -91,7 +91,7 @@ dependencies:
91
91
  requirements:
92
92
  - - ~>
93
93
  - !ruby/object:Gem::Version
94
- version: 0.14.0
94
+ version: 0.15.0
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: capybara
97
97
  requirement: !ruby/object:Gem::Requirement
@@ -743,6 +743,8 @@ files:
743
743
  - base/db/migrate/20120411132550_add_visit_count_to_activity_object.rb
744
744
  - base/db/migrate/20120411151413_relation_public_permissions.rb
745
745
  - base/db/migrate/20120526171311_remove_activity_channels.rb
746
+ - base/db/migrate/20120621135650_add_comment_count_to_activity_object.rb
747
+ - base/db/migrate/20120627115244_fix_activity_object_follower_count.rb
746
748
  - base/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb
747
749
  - base/lib/acts_as_taggable_on/social_stream.rb
748
750
  - base/lib/generators/social_stream/base/install_generator.rb
@@ -879,6 +881,7 @@ files:
879
881
  - base/spec/factories/relation_custom.rb
880
882
  - base/spec/factories/tie.rb
881
883
  - base/spec/factories/user.rb
884
+ - base/spec/integration/activity.rb
882
885
  - base/spec/integration/navigation_spec.rb
883
886
  - base/spec/integration/resque_access_spec.rb
884
887
  - base/spec/models/activity_action_spec.rb