Sha256: 37fcee8d60346d17891c79d38e241b67ccc3e465b3bbb1d8e67c305fc3149856

Contents?: true

Size: 1.24 KB

Versions: 13

Compression:

Stored size: 1.24 KB

Contents

# This model includes all the actions performed by {Actor actors}
# on {ActivityObject activity objects}
# 
class ActivityAction < ActiveRecord::Base
  belongs_to :actor
  belongs_to :activity_object

  before_save :change_follower_count

  scope :sent_by, lambda{ |actor|
    where(:actor_id => Actor.normalize_id(actor))
  }

  scope :not_sent_by, lambda{ |actor|
    where(arel_table[:actor_id].not_in(Actor.normalize_id(actor)))
  }

  scope :received_by, lambda{ |activity_object|
    where(:activity_object_id => ActivityObject.normalize_id(activity_object))
  }

  scope :authored_or_owned, where(arel_table[:author].eq(true).
                                or(arel_table[:user_author].eq(true)).
                                or(arel_table[:owner].eq(true)))

  scope :authored_or_owned_by, lambda{ |subject|
    authored_or_owned.sent_by(subject)
  }

  before_create :follow_by_author_and_owner

  private

  # Updates the follower_count counter in the {ActivityObject}
  def change_follower_count
    return unless follow_changed?

    follow? ?
      activity_object.increment!(:follower_count) :
      activity_object.decrement!(:follower_count)
  end

  def follow_by_author_and_owner
    self.follow = true if author? || user_author? || owner?
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
social_stream-0.27.3 base/app/models/activity_action.rb
social_stream-0.27.2 base/app/models/activity_action.rb
social_stream-base-0.21.2 app/models/activity_action.rb
social_stream-0.27.1 base/app/models/activity_action.rb
social_stream-base-0.21.1 app/models/activity_action.rb
social_stream-0.27.0 base/app/models/activity_action.rb
social_stream-base-0.21.0 app/models/activity_action.rb
social_stream-0.26.2 base/app/models/activity_action.rb
social_stream-base-0.20.2 app/models/activity_action.rb
social_stream-0.26.1 base/app/models/activity_action.rb
social_stream-base-0.20.1 app/models/activity_action.rb
social_stream-0.26.0 base/app/models/activity_action.rb
social_stream-base-0.20.0 app/models/activity_action.rb