diff --git a/app/models/user.rb b/app/models/user.rb index d9c361efda42ef6445698ea192ca22f9ea3dadc7..bbf9c9bd5774f490b864bc50046f258827dc24a3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,10 +9,12 @@ class User key :friend_ids, Array key :pending_request_ids, Array key :visible_post_ids, Array + key :visible_person_ids, Array one :person, :class_name => 'Person', :foreign_key => :owner_id many :friends, :in => :friend_ids, :class_name => 'Person' + many :visible_people, :in => :visible_person_ids, :class_name => 'Person' # One of these needs to go many :pending_requests, :in => :pending_request_ids, :class_name => 'Request' many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' @@ -197,6 +199,8 @@ class User elsif object.is_a?(Comment) object.person = Diaspora::Parser.parse_or_find_person_from_xml( xml ).save if object.person.nil? + self.visible_people << object.person + self.save Rails.logger.debug("The person parsed from comment xml is #{object.person.inspect}") unless object.person.nil? object.person.save Rails.logger.debug("From: #{object.person.inspect}") if object.person @@ -244,7 +248,8 @@ class User def visible_person_by_id( id ) id = id.to_id return self.person if id == self.person.id - friends.detect{|x| x.id == id } + result = friends.detect{|x| x.id == id } + result = visible_people.detect{|x| x.id == id } unless result end def group_by_id( id ) diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 46943512f6de1d34f51610faf31cba8f03deada2..74ddfb8824b9ad0f4225358699275acbc21e3a92 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -135,7 +135,7 @@ describe User do end describe 'comments' do - it 'should correctly marshal to the downstream user' do + it 'should correctly marshal a stranger for the downstream user' do friend_users(@user, @group, @user3, @group3) post = @user.post :status_message, :message => "hello", :to => @group.id @@ -147,6 +147,8 @@ describe User do @user.receive comment.to_diaspora_xml @user.reload + commenter_id = @user2.person.id + @user2.person.delete @user2.delete comment_id = comment.id @@ -160,6 +162,7 @@ describe User do new_comment.person.should_not be_nil new_comment.person.profile.should_not be_nil + @user3.visible_person_by_id(commenter_id).should_not be_nil end end end