Class: ActivityObject

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Properties
Defined in:
app/models/activity_object.rb,
app/models/activity_object/properties.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

Defined Under Namespace

Modules: Properties

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Properties

#add_holder_object_id=

Methods included from Properties::HolderMethods

#holder_methods

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



234
235
236
# File 'app/models/activity_object.rb', line 234

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

#action_from(actor) ⇒ Object

Return the Action model to an Actor



217
218
219
# File 'app/models/activity_object.rb', line 217

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

#actor!Object



212
213
214
# File 'app/models/activity_object.rb', line 212

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

#acts_as_actor?Boolean

Does this ActivityObject has Actor?

Returns:

  • (Boolean)


208
209
210
# File 'app/models/activity_object.rb', line 208

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)


187
188
189
190
191
192
193
# File 'app/models/activity_object.rb', line 187

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



227
228
229
230
231
232
# File 'app/models/activity_object.rb', line 227

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



201
202
203
204
205
# File 'app/models/activity_object.rb', line 201

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

#post_activityObject

The activity in which this activity_object was created



222
223
224
# File 'app/models/activity_object.rb', line 222

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



132
133
134
135
# File 'app/models/activity_object.rb', line 132

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



139
140
141
142
# File 'app/models/activity_object.rb', line 139

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



145
146
147
148
# File 'app/models/activity_object.rb', line 145

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)


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

def represented_author?
  author_id != user_author_id
end