public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Search Repo:
Piotr Jakubowski (author)
Tue Jul 01 00:31:01 -0700 2008
Michael Hartl (committer)
Tue Jul 01 12:17:04 -0700 2008
insoshi / lib / activity_logger.rb
100644 26 lines (25 sloc) 1.147 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module ActivityLogger
 
  # Add an activity to the feeds of a person's contacts.
  # Usually, we only add to the feeds of the contacts, not the person himself.
  # For example, if a person makes a forum post, the activity shows up in
  # his contacts' feeds but not his.
  # The :include_person option is to handle the case when add_activities
  # should include the person as well. This happens when
  # someone comments on a person's blog post or wall. In that case, when
  # adding activities to the contacts of the wall's or post's owner,
  # we should include the owner as well, so that he sees in his feed
  # that a comment has been made.
  def add_activities(options = {})
    person = options[:person]
    include_person = options[:include_person]
    activity = options[:activity] ||
               Activity.create!(:item => options[:item], :person => person)
    person.contacts.each do |c|
      # Prevent duplicate entries in the feed.
      c.activities << activity unless c.activities.include?(activity)
    end
    if include_person
      person.activities << activity unless person.activities.include?(activity)
    end
  end
end