Class: Socializer::Activity

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ObjectTypeBase
Defined in:
app/models/socializer/activity.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ObjectTypeBase

#guid

Class Method Details

.stream(options = {}) ⇒ Object

Selects the activites that either the person made, that is public from a person in one of his circle, or that is shared to one of the circles he is part of.

  • options[:provider] - nil, activities, people, circles, groups

  • options[:actor_id] - unique identifier of the previously typed provider

  • options[:viewer_id] - who wants to see the activity stream

    Activity.stream(provider: nil, actor_id: current_user.id, viewer_id: current_user.id)



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/models/socializer/activity.rb', line 47

def self.stream(options = {})
  options.assert_valid_keys(:provider, :actor_id, :viewer_id)

  provider  = options.delete(:provider)
  actor_uid = options.delete(:actor_id)
  viewer_id = options.delete(:viewer_id)

  viewer_id = Person.find(viewer_id).guid

  query = build_query(viewer_id)

  case provider
  when nil
    # this is your dashboard. display everything about people in circles and yourself.
    query.uniq
  when 'activities'
    # we only want to display a single activity. make sure the viewer is allowed to do so.
    activity_id = actor_uid
    query.where { id.eq(activity_id) }.uniq
  when 'people'
    # this is a user profile. display everything about him that you are allowed to see
    person_id = Person.find(actor_uid).guid
    query.where { actor_id.eq(person_id) }.uniq
  when 'circles'
    # FIXME: Should display notes even if circle has no members and the owner is viewing it.
    #        Notes still don't show after adding people to the circles.

    circles_sql  = Circle.select { id }.where { (id.eq actor_uid) & (author_id.eq viewer_id) }
    followed_sql = Tie.select { contact_id }.where { circle_id.in(circles_sql) }

    query.where { actor_id.in(followed_sql) }.uniq
  when 'groups'
    # this is a group. display everything that was posted to this group as audience
    group_id = Group.find(actor_uid).guid
    # query.where(audiences: {activity_object_id: group_id}).uniq
    query.where { audiences.activity_object_id.eq(group_id) }.uniq
  else
    fail 'Unknown stream provider.'
  end
end

Instance Method Details

#actorObject



27
28
29
# File 'app/models/socializer/activity.rb', line 27

def actor
  @actor ||= activitable_actor.activitable
end

#commentsObject



23
24
25
# File 'app/models/socializer/activity.rb', line 23

def comments
  @comments ||= children.joins(:activitable_object).where { activitable_object.activitable_type.eq('Socializer::Comment') }
end

#objectObject



31
32
33
# File 'app/models/socializer/activity.rb', line 31

def object
  @object ||= activitable_object.activitable
end

#targetObject



35
36
37
# File 'app/models/socializer/activity.rb', line 35

def target
  @target ||= activitable_target.activitable
end