diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index ec5bdbccd..3e4ac1f11 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -17,6 +17,7 @@ class AspectsController < ApplicationController @aspects = current_user.aspects.where(:id => params[:a_ids]) else @aspects = current_user.aspects + @contacts_sharing_with = current_user.contacts.sharing end #No aspect_listings on infinite scroll diff --git a/app/models/contact.rb b/app/models/contact.rb index e7d747ee9..87242f8a2 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -19,6 +19,10 @@ class Contact < ActiveRecord::Base validates_uniqueness_of :person_id, :scope => :user_id + scope :sharing, lambda { + where(:sharing => true) + } + def dispatch_request request = self.generate_request Postzord::Dispatch.new(self.user, request).post diff --git a/app/views/aspects/_aspect_listings.haml b/app/views/aspects/_aspect_listings.haml index 7e0d91bb7..7081b1c9f 100644 --- a/app/views/aspects/_aspect_listings.haml +++ b/app/views/aspects/_aspect_listings.haml @@ -12,3 +12,16 @@ - for aspect in aspects = render 'aspects/aspect', :aspect => aspect, :contacts => aspect.contacts + - if @contacts_sharing_with + %li{:class => ("dull" if @contacts_sharing_with.size == 0)} + .right + %b + = link_to t('contacts', :count => @contacts_sharing_with.size), edit_aspect_path(aspect), :rel => 'facebox', :class => 'contact-count' + %b + People sharing with you + %br + + - if @contacts_sharing_with.size > 0 + .contacts + - for contact in @contacts_sharing_with[0..15] + = person_image_link(contact.person) diff --git a/app/views/people/_profile_sidebar.html.haml b/app/views/people/_profile_sidebar.html.haml index a242e427e..d4455fa78 100644 --- a/app/views/people/_profile_sidebar.html.haml +++ b/app/views/people/_profile_sidebar.html.haml @@ -35,12 +35,16 @@ %br %hr{:style=>"width:300px;"} - - if user_signed_in? && contact.sharing? + - if user_signed_in? %br - %h4 - #{person.name} is sharing with you. + - if contact.sharing? + %h4 + #{person.name} is sharing with you. + - elsif contact.receiving? + %h4 + You are sharing with #{person.name} - -if user_signed_in? && ((contact.persisted? && contact.mutual?) || person == current_user.person || @incoming_request) + -if user_signed_in? && (contact.sharing? || person == current_user.person) %ul#profile_information - unless person.profile.bio.blank? %li diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 54ea641f2..80d070501 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -26,7 +26,7 @@ .span-15.last #author_info - if user_signed_in? - - if !@contact.receiving? #!(current_user.person == @person) && !(@contact.persisted? && !@contact.sharing?) + - if !@contact.receiving? .right = link_to t('.start_sharing'), {:controller => "contacts", diff --git a/lib/diaspora/user/connecting.rb b/lib/diaspora/user/connecting.rb index 0b65d8c68..9ddc3531d 100644 --- a/lib/diaspora/user/connecting.rb +++ b/lib/diaspora/user/connecting.rb @@ -28,7 +28,7 @@ module Diaspora if !contact.mutual? || opts[:force] contact.destroy else - contact.update_attributes(:sharing => false) + contact.update_attributes(:receiving => false) end posts.each do |p| diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 1b776391d..f7a32b7ad 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -44,19 +44,18 @@ describe Contact do contact.person = person contact.should_not be_valid end + end - it 'validates that sharing and aspect membership count are consistant' do - pending - person = Factory(:person) - - contact2 = alice.contacts.create(:person=>person) - contact2.should be_valid - - contact2.aspect_memberships.create(:aspect => alice.aspects.first) - contact2.should_not be_sharing - contact2.should_not be_valid - - + context 'scope' do + describe 'sharing' do + it 'returns contacts with sharing true' do + lambda { + alice.contacts.create!(:sharing => true, :person => Factory(:person)) + alice.contacts.create!(:sharing => false, :person => Factory(:person)) + }.should change{ + Contact.sharing.count + }.by(1) + end end end diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index 181982e88..7a1c94883 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -27,10 +27,10 @@ describe Diaspora::UserModules::Connecting do }.by(-1) end - it 'removes a contacts mutual flag' do - bob.contacts.find_by_person_id(alice.person.id).should be_mutual + it 'removes a contacts receiving flag' do + bob.contacts.find_by_person_id(alice.person.id).should be_receiving bob.remove_contact(bob.contact_for(alice.person)) - bob.contacts(true).find_by_person_id(alice.person.id).should_not be_mutual + bob.contacts(true).find_by_person_id(alice.person.id).should_not be_receiving end end