Class: ActivityObject

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/activity_object.rb

Overview

The ActivityObject is any object that receives actions. Examples are creating post, liking a comment, contacting a user.

ActivityObject subtypes

All post, comment and user are objects. Social Stream privides 3 ActivityObject subtypes, Post, Comment and Actor. The application developer can define as many ActivityObject subtypes as required. Objects are added to config/initializers/social_stream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_activity_parent_idObject

Returns the value of attribute _activity_parent_id.



12
13
14
# File 'app/models/activity_object.rb', line 12

def _activity_parent_id
  @_activity_parent_id
end

Instance Method Details

#_activity_parentObject



197
198
199
# File 'app/models/activity_object.rb', line 197

def _activity_parent
  @_activity_parent ||= Activity.find(_activity_parent_id)
end

#action_from(actor) ⇒ Object

Return the Action model to an Actor



180
181
182
# File 'app/models/activity_object.rb', line 180

def action_from(actor)
  received_actions.sent_by(actor).first
end

#actor!Object



175
176
177
# File 'app/models/activity_object.rb', line 175

def actor!
  actor || raise("Unknown Actor for ActivityObject: #{ inspect }")
end

#acts_as_actor?Boolean

Does this ActivityObject has Actor?

Returns:

  • (Boolean)


171
172
173
# File 'app/models/activity_object.rb', line 171

def acts_as_actor?
  object_type == "Actor"
end

#authored_or_owned_by?(subject) ⇒ Boolean

subject was the author, user author or owner of this ActivityObject?

Returns:

  • (Boolean)


150
151
152
153
154
155
156
# File 'app/models/activity_object.rb', line 150

def authored_or_owned_by?(subject)
  return false if subject.blank?

  received_actions.
    merge(ActivityAction.authored_or_owned_by(subject)).
    any?
end

#build_post_activityObject

Build the post activity when this object is not saved



190
191
192
193
194
195
# File 'app/models/activity_object.rb', line 190

def build_post_activity
  Activity.new :author       => author,
               :user_author  => user_author,
               :owner        => owner,
               :relation_ids => relation_ids
end

#objectObject

The object of this activity object



164
165
166
167
168
# File 'app/models/activity_object.rb', line 164

def object
  subtype_instance.is_a?(Actor) ?
    subtype_instance.subject :
    subtype_instance
end

#post_activityObject

The activity in which this activity_object was created



185
186
187
# File 'app/models/activity_object.rb', line 185

def post_activity
  activities.includes(:activity_verb).where('activity_verbs.name' => 'post').first
end

#received_action_by(actor_id) ⇒ Object

Obtain the ActivityAction between this ActivityObject and the Actor identified by actor_id



97
98
99
100
# File 'app/models/activity_object.rb', line 97

def received_action_by(actor_id)
  received_actions.
    find{ |a| a.actor_id == actor_id }
end

#received_action_by!(actor_id) ⇒ Object

Obtain received_action_by(actor_id) or create it if it does not exist



104
105
106
107
# File 'app/models/activity_object.rb', line 104

def received_action_by!(actor_id)
  received_action_by(actor_id) ||
    received_actions.build(:actor_id  => actor_id)
end

#received_role_action(role) ⇒ Object

Get the first ActivityAction that has activated the role flag



110
111
112
113
# File 'app/models/activity_object.rb', line 110

def received_role_action(role)
  received_actions.
    find{ |a| a.__send__ "#{ role }?" }
end

#represented_author?Boolean

Was the author represented when this ActivityObject was created?

Returns:

  • (Boolean)


159
160
161
# File 'app/models/activity_object.rb', line 159

def represented_author?
  author_id != user_author_id
end