diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9cbf813e7..7352e0219 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -48,4 +48,14 @@ class ApplicationController < ActionController::Base I18n.locale = request.compatible_language_from AVAILABLE_LANGUAGE_CODES end end + + def similar_people contact + aspect_ids = contact.aspect_ids + contacts = Contact.all(:user_id => current_user.id, + :person_id.ne => contact.person.id, + :aspect_ids.in => aspect_ids, + :limit => 5, + :order => 'updated_at desc') + contacts.collect!{ |contact| contact.person } + end end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 78d0f2662..e498e8bd5 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -55,6 +55,7 @@ class PeopleController < ApplicationController if @contact @aspects_with_person = @contact.aspects + @similar_people = similar_people @contact end if (@person != current_user.person) && (!@contact || @contact.pending) @@ -152,4 +153,5 @@ class PeopleController < ApplicationController def webfinger(account, opts = {}) Resque.enqueue(Jobs::SocketWebfinger, current_user.id, account, opts) end + end diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 5caa2b3ed..890cb8bc1 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -23,6 +23,7 @@ class PhotosController < ApplicationController if @contact @aspects_with_person = @contact.aspects + @similar_people = similar_people @contact end @posts = current_user.raw_visible_posts.all(:_type => 'Photo', :person_id => @person.id, :order => 'created_at DESC').paginate :page => params[:page], :order => 'created_at DESC' diff --git a/app/views/people/_profile_sidebar.html.haml b/app/views/people/_profile_sidebar.html.haml index f2cc51f57..58a505ef3 100644 --- a/app/views/people/_profile_sidebar.html.haml +++ b/app/views/people/_profile_sidebar.html.haml @@ -41,7 +41,7 @@ %h3 #{t('.bio')} = markdownify(person.profile.bio, :newlines => true) - %li + %li.span-8.last .span-4 %h3 #{t('.gender')} = person.profile.gender diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index f0c417485..a78f15bc9 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -19,7 +19,16 @@ = link_to t('_photos'), person_photos_path(@person) .span-8.append-1.last - = render :partial => 'people/profile_sidebar', :locals => {:person => @person, :contact => @contact} + = render :partial => 'people/profile_sidebar', :locals => {:person => @person, :contact => @contact } + + - if @contact && @similar_people.count > 0 + .span-8.last + %hr{:style=>"width:300px;"} + .section.contact_pictures + %h4 + = t('.similar_contacts') + - for person in @similar_people + = person_image_link person .span-15.last - unless @contact || current_user.person == @person diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index eff256ef5..6b8194dcc 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -346,6 +346,7 @@ en: not_connected: "You are not sharing with %{name}" recent_posts: "Recent Posts" recent_public_posts: "Recent Public Posts" + similar_contacts: "similar contacts" edit: info_available_to: "This info will be available to whomever you connect with on Diaspora." your_profile: "Your profile" diff --git a/public/javascripts/view.js b/public/javascripts/view.js index 26d79e5a8..edb3f8ca1 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -156,7 +156,7 @@ var View = { avatars: { bind: function() { - $("#left_pane img.avatar, #manage_aspect_zones img.avatar").tipsy({ + $(".contact_pictures img.avatar, #manage_aspect_zones img.avatar").tipsy({ live: true }); } diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 571a0ae02..9c678e200 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -590,8 +590,7 @@ ul.comments :padding 0 ul#profile_information - :margin - :top 1em + :margin 1em 0 > li :margin :bottom 2em diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index d86b973a6..24cafb5c7 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -14,6 +14,59 @@ describe PeopleController do sign_in :user, user end + describe '#similar_people' do + before do + @contacts = [] + @aspect1 = user.aspects.create(:name => "foos") + @aspect2 = user.aspects.create(:name => "bars") + + 3.times do + @contacts << Contact.create(:user => user, :person => Factory.create(:person)) + end + end + + it 'returns people in mutual aspects' do + @contacts[0].aspects << @aspect1 + @contacts[1].aspects << @aspect1 + @contacts[0].save + @contacts[1].save + + @controller.similar_people(@contacts[0]).should include(@contacts[1].person) + end + + it 'does not return people in non-mutual aspects' do + @contacts[0].aspects << @aspect1 + @contacts[1].aspects << @aspect1 + @contacts[0].save + @contacts[1].save + + @controller.similar_people(@contacts[0]).should_not include(@contacts[2].person) + end + + it 'does not return the original contacts person' do + @contacts[0].aspects << @aspect1 + @contacts[1].aspects << @aspect1 + @contacts[0].save + @contacts[1].save + + @controller.similar_people(@contacts[0]).should_not include(@contacts[0].person) + end + + it 'returns at max 5 similar people' do + @contacts[0].aspects << @aspect1 + @contacts[0].save + + 20.times do + c = Contact.create(:user => user, :person => Factory.create(:person)) + c.aspects << @aspect1 + c.save + @contacts << c + end + + @controller.similar_people(@contacts[0]).count.should == 5 + end + end + describe '#share_with' do before do @person = Factory.create(:person)