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
Global feeds omit inactive users
Michael Hartl (author)
Tue Apr 29 16:10:24 -0700 2008
commit  6edd7ce5c1f1cfacc2855d6a53bff59e1a77dbc5
tree    33eac02a3599b9215ddd1fb0b7c1263cd0ae3ea8
parent  6092094362f6c97177c6c88d583ac2d4d27858c8
...
20
21
22
 
 
 
 
 
 
23
24
 
 
 
 
 
25
26
...
20
21
22
23
24
25
26
27
28
29
 
30
31
32
33
34
35
36
0
@@ -20,7 +20,17 @@ class Activity < ActiveRecord::Base
0
   GLOBAL_FEED_SIZE = 10
0
 
0
   # Return a feed drawn from all activities.
0
+ # The fancy SQL is to keep inactive people out of feeds.
0
+ # It's hard to do that entirely, but this way deactivated users
0
+ # won't be the person in "<person> has <done something>".
0
+ #
0
+ # This is especially useful for sites that require email verifications.
0
+ # Their 'connected with admin' item won't show up until they verify.
0
   def self.global_feed
0
- find(:all, :order => 'created_at DESC', :limit => GLOBAL_FEED_SIZE)
0
+ find(:all,
0
+ :joins => "INNER JOIN people p ON activities.person_id = p.id",
0
+ :conditions => ["p.deactivated = ?", false],
0
+ :order => 'activities.created_at DESC',
0
+ :limit => GLOBAL_FEED_SIZE)
0
   end
0
 end
...
3
4
5
 
6
7
8
9
10
 
11
12
13
14
15
16
 
17
18
19
...
25
26
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
29
30
...
3
4
5
6
7
8
9
10
 
11
12
13
14
15
16
 
17
18
19
20
...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
0
@@ -3,17 +3,18 @@ require File.dirname(__FILE__) + '/../spec_helper'
0
 describe Activity do
0
   before(:each) do
0
     @person = people(:quentin)
0
+ @commenter = people(:aaron)
0
   end
0
 
0
   it "should delete a post activity along with its parent item" do
0
     @post = ForumPost.create(:body => "Hey there", :topic => topics(:one),
0
- :person => people(:quentin))
0
+ :person => @person)
0
     destroy_should_remove_activity(@post)
0
   end
0
   
0
   it "should delete a comment activity along with its parent item" do
0
     @comment = @person.comments.create(:body => "Hey there",
0
- :commenter => people(:aaron))
0
+ :commenter => @commenter)
0
     destroy_should_remove_activity(@comment)
0
   end
0
   
0
@@ -25,6 +26,22 @@ describe Activity do
0
     destroy_should_remove_activity(@connection, :breakup)
0
   end
0
   
0
+ before(:each) do
0
+ # Create an activity.
0
+ @person.comments.create(:body => "Hey there",
0
+ :commenter => @commenter)
0
+ end
0
+
0
+ it "should have a nonempty global feed" do
0
+ Activity.global_feed.should_not be_empty
0
+ end
0
+
0
+ it "should not show activities for users who are inactive" do
0
+ @commenter.toggle!(:deactivated)
0
+ @commenter.should be_deactivated
0
+ Activity.global_feed.should be_empty
0
+ end
0
+
0
   private
0
   
0
   # TODO: do this in a more RSpecky way.

Comments

    No one has commented yet.