From 46793179db6e2f3ac95b722b5f9301448219dae8 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Wed, 8 Dec 2010 16:53:24 -0800 Subject: [PATCH] people#show displays shows public posts for non-contacts as well --- app/controllers/people_controller.rb | 4 +- app/views/people/show.html.haml | 76 ++++++++++++---------- config/locales/diaspora/en.yml | 1 + lib/diaspora/user/querying.rb | 15 +++++ public/stylesheets/sass/application.sass | 2 + spec/controllers/people_controller_spec.rb | 8 +++ spec/models/user/querying_spec.rb | 25 +++++++ 7 files changed, 94 insertions(+), 37 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index a6f530fba..0d84aa1e1 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -53,8 +53,9 @@ class PeopleController < ApplicationController @aspects_with_person = @contact.aspects end - @posts = current_user.visible_posts(:person_id => @person.id, :_type => "StatusMessage").paginate :page => params[:page], :order => 'created_at DESC' + @posts = current_user.posts_from(@person).paginate :page => params[:page] @post_hashes = hashes_for_posts @posts + respond_with @person, :locals => {:post_type => :all} else @@ -132,6 +133,7 @@ class PeopleController < ApplicationController } end end + def webfinger(account, opts = {}) Resque.enqueue(Jobs::SocketWebfinger, current_user.id, account, opts) end diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index d4d464709..491664192 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -20,45 +20,49 @@ = render :partial => 'people/profile_sidebar', :locals => {:person => @person, :is_contact => @is_contact} .span-15.last - - if @contact || current_user.person == @person - - if @posts.count > 0 - -if @post_type == :photos + - unless @contact || current_user.person == @person + - if current_user.has_incoming_request_from(@person) + .floating + %h3 + = t('.incoming_request') %h4 - = t('_photos') - = render 'photos/index', :photos => @posts - - else - %h4 - = t('.recent_posts') - = render 'shared/stream', :posts => @post_hashes - = will_paginate @posts - + = link_to t('.return_to_aspects'), aspects_manage_path + = t('.to_accept_or_ignore') + - else - %ul#stream - %li - %h3= t('.no_posts') + .floating + %h3 + = t('.not_connected', :name => @person.name) + + - unless pending_request_for(@person) + %h3 + .description + = t('.request_people') + + = render :partial =>'requests/new_request_to_person', :locals => {:aspects => @aspects, :destination_handle => @person.diaspora_handle} - - elsif current_user.has_incoming_request_from(@person) - .floating - %h3 - = t('.incoming_request') + - else + %h3 + .description + = t('.already_requested', :name => @person.name) + + - if @posts.count > 0 + -if @post_type == :photos %h4 - = link_to t('.return_to_aspects'), aspects_manage_path - = t('.to_accept_or_ignore') - + = t('_photos') + = render 'photos/index', :photos => @posts + - else + %h4 + - if @contact + = t('.recent_posts') + - else + = t('.recent_public_posts') + + = render 'shared/stream', :posts => @post_hashes + = will_paginate @posts + - else - .floating - %h3 - = t('.not_connected', :name => @person.name) - - - unless pending_request_for(@person) - %h3 - .description - = t('.request_people') - - = render :partial =>'requests/new_request_to_person', :locals => {:aspects => @aspects, :destination_handle => @person.diaspora_handle} - - - else - %h3 - .description - = t('.already_requested', :name => @person.name) + %ul#stream + %li + %h3= t('.no_posts') diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 4eff0acb1..7b4631963 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -317,6 +317,7 @@ en: does_not_exist: "Person does not exist!" not_connected: "You are not connected with this person" recent_posts: "Recent Posts" + recent_public_posts: "Recent Public Posts" edit: info_available_to: "This info will be available to whomever you connect with on Diaspora." your_profile: "Your profile" diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 7ffa1ba94..dd8ebbde7 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -96,6 +96,21 @@ module Diaspora def request_for(to_person) Request.from(self.person).to(to_person).first end + + def posts_from(person) + post_ids = [] + + public_post_ids = Post.where(:person_id => person.id, :_type => "StatusMessage", :public => true).fields('id').all + public_post_ids.map!{ |p| p.id } + + directed_post_ids = self.visible_posts(:person_id => person.id, :_type => "StatusMessage") + directed_post_ids.map!{ |p| p.id } + + post_ids += public_post_ids + post_ids += directed_post_ids + + Post.all(:id.in => post_ids, :order => 'created_at desc') + end end end end diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 4daee7441..bccd4d3a3 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -1414,6 +1414,8 @@ ul.aspects .floating :position relative :padding 12px + :margin + :bottom 2em :background :color rgb(255,255,255) diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index cb53a3ad7..c03d58996 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -137,6 +137,14 @@ describe PeopleController do get :show, :id => user2.person.id response.should be_success end + + it "renders with public posts of a non-contact" do + user2 = make_user + status_message = user2.post(:status_message, :message => "hey there", :to => 'all', :public => true) + + get :show, :id => user2.person.id + response.body.should include status_message.message + end end describe '#webfinger' do diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index a9af5ab96..b9f6c9aca 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -229,4 +229,29 @@ describe User do end end + describe '#posts_from' do + let!(:user3) {make_user} + let!(:aspect3) {user3.aspects.create(:name => "bros")} + + let!(:public_message) {user3.post(:status_message, :message => "hey there", :to => 'all', :public => true)} + let!(:private_message) {user3.post(:status_message, :message => "hey there", :to => aspect3.id)} + + it 'displays public posts for a non-contact' do + user.posts_from(user3.person).should include public_message + end + + it 'does not display private posts for a non-contact' do + user.posts_from(user3.person).should_not include private_message + end + + it 'displays private and public posts for a non-contact after connecting' do + connect_users(user, aspect, user3, aspect3) + new_message = user3.post(:status_message, :message => "hey there", :to => aspect3.id) + + user.reload + + user.posts_from(user3.person).should include public_message + user.posts_from(user3.person).should include new_message + end + end end