From 9aad7810c0cfe2df5137348ecade0148be0d348c Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Wed, 1 Jun 2011 12:24:07 -0700 Subject: [PATCH] Move visible_posts defaults into a defaults hash, mostly --- lib/diaspora/user/querying.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 9eaa425a7..ab932c34a 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -13,15 +13,20 @@ module Diaspora end def visible_posts(opts = {}) - opts = opts.dup - opts[:type] ||= ['StatusMessage', 'Photo'] - opts[:limit] ||= 15 - opts[:order] ||= 'updated_at DESC' + defaults = { + :type => ['StatusMessage', 'Photo'], + :order => 'updated_at DESC', + :limit => 15, + :hidden => false + } + opts = defaults.merge(opts) + order_field = opts[:order].split.first.to_sym - opts[:hidden] ||= false order_with_table = 'posts.' + opts[:order] + opts[:max_time] = Time.at(opts[:max_time]) if opts[:max_time].is_a?(Integer) opts[:max_time] ||= Time.now + 1 + select_clause ='DISTINCT posts.id, posts.updated_at AS updated_at, posts.created_at AS created_at' posts_from_others = Post.joins(:contacts).where( :post_visibilities => {:hidden => opts[:hidden]}, :contacts => {:user_id => self.id})