From aa4c20e404107723f8e4c8e5a8a409e8d335ce83 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 29 Mar 2011 17:09:09 -0700 Subject: [PATCH] pass post to comments partial. use sql in raw_visible_posts --- app/controllers/aspects_controller.rb | 2 +- app/views/comments/_comment.html.haml | 2 +- app/views/comments/_comments.haml | 10 +++++----- app/views/photos/show.html.haml | 2 +- app/views/shared/_stream_element.html.haml | 2 +- app/views/status_messages/show.html.haml | 2 +- lib/diaspora/user/querying.rb | 6 +++--- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index f50fae5c3..9912895e5 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -27,7 +27,7 @@ class AspectsController < ApplicationController @selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq @aspect_ids = @aspects.map { |a| a.id } @posts = current_user.raw_visible_posts(:by_members_of => @aspect_ids, :type => 'StatusMessage', :order => session[:sort_order] + ' DESC').includes( - :comments, :likes, :dislikes).paginate(:page => params[:page], :per_page => 15, :order => session[:sort_order] + ' DESC') + :comments, :mentions, :likes, :dislikes).paginate(:page => params[:page], :per_page => 15, :order => session[:sort_order] + ' DESC') @fakes = PostsFake.new(@posts) @contact_count = current_user.contacts.count diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml index 9fd2b83e1..c9af008d7 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml @@ -3,7 +3,7 @@ -# the COPYRIGHT file. %li.comment.posted{:data=>{:guid => comment.id}, :class => ("hidden" if(defined? hidden))} - - if current_user && (current_user.owns?(comment) || current_user.owns?(comment.post)) + - if current_user && (current_user.owns?(comment) || current_user.owns?(post)) .right.controls = link_to image_tag('deletelabel.png'), comment_path(comment), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete comment_delete", :title => t('delete') = person_image_link(comment.author) diff --git a/app/views/comments/_comments.haml b/app/views/comments/_comments.haml index 19f3cfa91..187d0aef7 100644 --- a/app/views/comments/_comments.haml +++ b/app/views/comments/_comments.haml @@ -10,14 +10,14 @@ = image_tag 'icons/spechbubble_2.png', :class => 'more_comments_icon' %b= comment_toggle(comments.size) -%ul.comments{:id => post_id, :class => ("hidden" if comments.size == 0 && !defined?(force_open) && !is_expanded)} +%ul.comments{:id => post.id, :class => ("hidden" if comments.size == 0 && !defined?(force_open) && !is_expanded)} -if comments.size > 3 .older_comments{:class => ("hidden inactive" if defined?(condensed) && condensed)} - = render :partial => 'comments/comment', :collection => comments[0..-4] - = render :partial => 'comments/comment', :collection => comments[-3, 3] + = render :partial => 'comments/comment', :collection => comments[0..-4], :locals => {:post => post} + = render :partial => 'comments/comment', :collection => comments[-3, 3], :locals => {:post => post} -else - = render :partial => 'comments/comment', :collection => comments + = render :partial => 'comments/comment', :collection => comments, :locals => {:post => post} - unless @commenting_disabled %li.comment.show - = new_comment_form(post_id, current_user) + = new_comment_form(post.id, current_user) diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 0d82dbcf4..4da938b0b 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -76,4 +76,4 @@ %div{:data=>{:guid=>@parent.id}} .likes_container = render "likes/likes", :post_id => @parent.id, :likes => @parent.likes, :dislikes => @parent.dislikes - = render "comments/comments", :post_id => @parent.id, :comments => @parent.comments, :always_expanded => true + = render "comments/comments", :post => @parent, :comments => @parent.comments, :always_expanded => true diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index eada69d58..25d923381 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -44,4 +44,4 @@ /.likes_container / = render "likes/likes", :post_id => post.id, :likes => post.likes, :dislikes => post.dislikes, :current_user => current_user - = render "comments/comments", :post_id => post.id, :comments => post.comments, :current_user => current_user, :condensed => true, :commenting_disabled => (defined?(@commenting_disabled) && @commenting_disabled) + = render "comments/comments", :post => post, :comments => post.comments, :current_user => current_user, :condensed => true, :commenting_disabled => (defined?(@commenting_disabled) && @commenting_disabled) diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml index 04e9bfdf0..34cbfe9e0 100644 --- a/app/views/status_messages/show.html.haml +++ b/app/views/status_messages/show.html.haml @@ -29,4 +29,4 @@ = t('_comments') #status_message_stream.stream.show %div{:data=>{:guid=>@status_message.id}} - = render "comments/comments", :post_id => @status_message.id, :comments => @status_message.comments, :always_expanded => true + = render "comments/comments", :post => @status_message, :comments => @status_message.comments, :always_expanded => true diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 461db41f5..f880a6188 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -13,7 +13,7 @@ module Diaspora def raw_visible_posts(opts = {}) opts[:type] ||= ['StatusMessage', 'Photo'] opts[:limit] ||= 20 - opts[:order] ||= 'created_at DESC' + opts[:order] ||= 'updated_at DESC' opts[:order] = '`posts`.' + opts[:order] posts_from_others = Post.joins(:contacts).where(:contacts => {:user_id => self.id}) @@ -25,8 +25,8 @@ module Diaspora posts_from_self = posts_from_self.where(:aspects => {:id => opts[:by_members_of]}) end - post_ids = posts_from_others.select('posts.id').limit(opts[:limit]).order(opts[:order]).map{|p| p.id} - post_ids += posts_from_self.select('posts.id').limit(opts[:limit]).order(opts[:order]).map{|p| p.id} + post_ids = Post.connection.execute(posts_from_others.select('posts.id').limit(opts[:limit]).order(opts[:order]).to_sql).map{|r| r.first} + post_ids += Post.connection.execute(posts_from_self.select('posts.id').limit(opts[:limit]).order(opts[:order]).to_sql).map{|r| r.first} Post.where(:id => post_ids, :pending => false, :type => opts[:type]).select('DISTINCT `posts`.*').limit(opts[:limit]) end