diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index c011ca8..05e8a2b 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -9,13 +9,11 @@ class ProfileController < PublicController def index @activities = @profile.tracked_actions.paginate(:per_page => 30, :page => params[:page]) - @network_activities = [] @wall_items = [] - if !@profile.is_a?(Person) - @network_activities = @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) - elsif logged_in? && current_person.follows?(@profile) - @network_activities = @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) - @wall_items = @profile.scraps_received.not_replies.paginate(:per_page => 30, :page => params[:page]) if @profile.is_a?(Person) + @network_activities = !@profile.is_a?(Person) ? @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) : [] + if logged_in? && current_person.follows?(@profile) + @network_activities = @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) if @network_activities.empty? + @wall_items = @profile.scraps_received.not_replies.paginate(:per_page => 30, :page => params[:page]) end @tags = profile.article_tags unless profile.display_info_to?(user) diff --git a/app/models/person.rb b/app/models/person.rb index 9d47bd1..aa2afd7 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -17,7 +17,6 @@ class Person < Profile has_many :mailings - has_many :scraps_received, :class_name => 'Scrap', :foreign_key => :receiver_id, :order => "updated_at DESC" has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id named_scope :more_popular, @@ -35,11 +34,6 @@ class Person < Profile self.user.destroy if self.user end - def scraps(scrap=nil) - scrap = scrap.is_a?(Scrap) ? scrap.id : scrap - scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap) - end - def can_control_scrap?(scrap) begin !self.scraps(scrap).nil? diff --git a/app/models/profile.rb b/app/models/profile.rb index 72c74bb..4a48ced 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -91,12 +91,18 @@ class Profile < ActiveRecord::Base has_many :action_tracker_notifications, :foreign_key => 'profile_id' has_many :tracked_notifications, :through => :action_tracker_notifications, :source => :action_tracker, :order => 'updated_at DESC' + has_many :scraps_received, :class_name => 'Scrap', :foreign_key => :receiver_id, :order => "updated_at DESC" # FIXME ugly workaround def self.human_attribute_name(attrib) _(self.superclass.human_attribute_name(attrib)) end + def scraps(scrap=nil) + scrap = scrap.is_a?(Scrap) ? scrap.id : scrap + scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap) + end + class_inheritable_accessor :extra_index_methods self.extra_index_methods = [] diff --git a/app/models/scrap.rb b/app/models/scrap.rb index b384710..065de4d 100644 --- a/app/models/scrap.rb +++ b/app/models/scrap.rb @@ -2,7 +2,7 @@ class Scrap < ActiveRecord::Base validates_presence_of :content validates_presence_of :sender_id, :receiver_id - belongs_to :receiver, :class_name => 'Person', :foreign_key => 'receiver_id' + belongs_to :receiver, :class_name => 'Profile', :foreign_key => 'receiver_id' belongs_to :sender, :class_name => 'Person', :foreign_key => 'sender_id' has_many :replies, :class_name => 'Scrap', :foreign_key => 'scrap_id', :dependent => :destroy belongs_to :root, :class_name => 'Scrap', :foreign_key => 'scrap_id' @@ -11,12 +11,12 @@ class Scrap < ActiveRecord::Base named_scope :not_replies, :conditions => {:scrap_id => nil} - track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.receiver != s.sender} + track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.receiver != s.sender}, :custom_target => :action_tracker_target track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.receiver == s.sender} after_create do |scrap| scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil? - Scrap::Notifier.deliver_mail(scrap) unless scrap.sender == scrap.receiver + Scrap::Notifier.deliver_mail(scrap) if !scrap.receiver.is_a?(Community) && !(scrap.sender == scrap.receiver) end before_validation :strip_all_html_tags @@ -26,6 +26,10 @@ class Scrap < ActiveRecord::Base self.content = sanitizer.sanitize(self.content, :tags => []) end + def action_tracker_target + self.receiver.is_a?(Community) ? self.receiver : self + end + class Notifier < ActionMailer::Base def mail(scrap) sender, receiver = scrap.sender, scrap.receiver diff --git a/app/views/profile/_common.rhtml b/app/views/profile/_common.rhtml index 37b0f04..8b394b5 100644 --- a/app/views/profile/_common.rhtml +++ b/app/views/profile/_common.rhtml @@ -1,53 +1,63 @@ - <% unless @action %> - <% cache_timeout(profile.cache_key + '-profile-general-info', 4.hours.from_now) do %> -