Skip to content

Instantly share code, notes, and snippets.

@jimsynz
Created September 3, 2010 04:30
Show Gist options
  • Save jimsynz/563420 to your computer and use it in GitHub Desktop.
Save jimsynz/563420 to your computer and use it in GitHub Desktop.
class Personal < Cluster
def posts
begin
if UserSession.find && UserSession.find.record == creator
# It's our favourite user:
# Show the posts in clusters they follow,
# posts that mention their nickname
# and posts in their own timeline.
pt = Post.arel_table
mt = Mention.arel_table
ct = Connection.arel_table
following = ct.where(ct[:type].eq('Follow')).where(ct[:user_id].eq(creator.id)).project('DISTINCT(connections.cluster_id)')
my_posts = pt.where(pt[:cluster_id].eq(id)).project(pt[:id])
following_posts = pt.where(pt[:cluster_id].in(following)).where(pt[:is_public].eq('t')).project(pt[:id])
mention_posts = mt.join(pt).on(mt[:post_id].eq(pt[:id])).where(mt[:cluster_id].eq(id)).where(pt[:type].eq('Notice').not).project(pt[:id])
composite_posts = pt.where(pt[:id].in(following_posts).or(pt[:id].in(mention_posts)).or(pt[:id].in(my_posts))).project("DISTINCT(posts.id)")
Post.where(:id => composite_posts)
else
super
end
rescue
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment