Skip to content

Commit

Permalink
Wall refactorization
Browse files Browse the repository at this point in the history
  • Loading branch information
atd committed Mar 29, 2011
1 parent 5d11570 commit 66654d6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api_controller.rb
Expand Up @@ -26,7 +26,7 @@ def activity_atom_feed
end

@page = params[:page]
@activities = current_user.home_wall.paginate(:page => params[:page], :per_page => 10)
@activities = current_user.wall(:home).paginate(:page => params[:page], :per_page => 10)
respond_to do |format|
format.atom
end
Expand Down
30 changes: 15 additions & 15 deletions app/models/activity.rb
Expand Up @@ -5,7 +5,9 @@
# the relation in which the activity is transferred
#
# == Wall
# The Activity.wall(ties) scope provides all the activities attached to a set of ties
# The Activity.wall(type, ties) scope provides all the activities attached to a set of ties
#
# There are two types of wall, :home and :profile. Check {Actor#wall} for more information
#
class Activity < ActiveRecord::Base
has_ancestry
Expand All @@ -28,21 +30,19 @@ class Activity < ActiveRecord::Base

after_create :like_direct_object

scope :home_wall, lambda { |ties|
select("DISTINCT activities.*").
roots.
joins(:tie_activities).
where('tie_activities.tie_id' => ties).
order("created_at desc")
}
scope :wall, lambda { |type, ties|
q = select("DISTINCT activities.*").
roots.
joins(:tie_activities).
where('tie_activities.tie_id' => ties).
order("created_at desc")

# Profile wall is composed by original TieActivities. Not original are copies for followers
if type == :profile
q = q.where('tie_activities.original' => true)
end

scope :profile_wall, lambda { |ties|
select("DISTINCT activities.*").
roots.
joins(:tie_activities).
where('tie_activities.tie_id' => ties).
where('tie_activities.original' => true).
order("created_at desc")
q
}

# After an activity is created, it is associated to ties
Expand Down
36 changes: 22 additions & 14 deletions app/models/actor.rb
Expand Up @@ -257,23 +257,31 @@ def pending_ties
:receiver_id => i }
end

# The set of activities in the wall of this actor, includes all the activities
# from the ties the actor has access to
# The set of {Activity activities} in the wall of this {Actor}.
#
def home_wall
Activity.home_wall ties
end

# The set of activities in the wall profile of this actor, includes the activities
# from the ties of this actor that can be read by user
# There are two types of walls:
# home:: includes all the {Activity activities} from this {Actor} and their followed {Actor actors}
# See {Permission permissions} for more information on the following support
# profile:: The set of activities in the wall profile of this {Actor}, it includes only the
# activities from the ties of this actor that can be read by the subject
#
def profile_wall(user)
# FIXME: show public activities
return [] if user.blank?

Activity.profile_wall ties.allowing(user, 'read', 'activity')
end
# Options:
# :for:: the subject that is accessing the wall
#
def wall(type, options = {})
case type
when :home
Activity.wall :home, ties
when :profile
# FIXME: show public activities
return [] if options[:for].blank?

Activity.wall :profile, ties.allowing(options[:for], 'read', 'activity')
else
raise "Wall type not supported: #{ type }"
end
end

def logo
avatar!.logo
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/groups/show.html.erb
Expand Up @@ -14,5 +14,5 @@
</div>

<%= render :partial => "activities/activities",
:locals => { :activities => @group.profile_wall(current_subject),
:locals => { :activities => @group.wall(:profile, :for => current_subject),
:owner => @group } %>
2 changes: 1 addition & 1 deletion app/views/home/index.html.erb
Expand Up @@ -17,5 +17,5 @@
<% end %>
<%= render :partial => "activities/activities",
:locals => { :activities => current_subject.home_wall,
:locals => { :activities => current_subject.wall(:home),
:owner => current_subject } %>
2 changes: 1 addition & 1 deletion app/views/users/show.html.erb
Expand Up @@ -14,5 +14,5 @@
:locals => { :user => @user } %>
<%= render :partial => "activities/activities",
:locals => { :activities => @user.profile_wall(current_subject),
:locals => { :activities => @user.wall(:profile, :for => current_subject),
:owner => @user } %>

0 comments on commit 66654d6

Please sign in to comment.