Move visible_posts defaults into a defaults hash, mostly
This commit is contained in:
parent
158401e17d
commit
9aad7810c0
1 changed files with 10 additions and 5 deletions
|
|
@ -13,15 +13,20 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible_posts(opts = {})
|
def visible_posts(opts = {})
|
||||||
opts = opts.dup
|
defaults = {
|
||||||
opts[:type] ||= ['StatusMessage', 'Photo']
|
:type => ['StatusMessage', 'Photo'],
|
||||||
opts[:limit] ||= 15
|
:order => 'updated_at DESC',
|
||||||
opts[:order] ||= 'updated_at DESC'
|
:limit => 15,
|
||||||
|
:hidden => false
|
||||||
|
}
|
||||||
|
opts = defaults.merge(opts)
|
||||||
|
|
||||||
order_field = opts[:order].split.first.to_sym
|
order_field = opts[:order].split.first.to_sym
|
||||||
opts[:hidden] ||= false
|
|
||||||
order_with_table = 'posts.' + opts[:order]
|
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.at(opts[:max_time]) if opts[:max_time].is_a?(Integer)
|
||||||
opts[:max_time] ||= Time.now + 1
|
opts[:max_time] ||= Time.now + 1
|
||||||
|
|
||||||
select_clause ='DISTINCT posts.id, posts.updated_at AS updated_at, posts.created_at AS created_at'
|
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})
|
posts_from_others = Post.joins(:contacts).where( :post_visibilities => {:hidden => opts[:hidden]}, :contacts => {:user_id => self.id})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue