diff --git a/app/models/post.rb b/app/models/post.rb index b6d8b08cba9db7f311a7d3f5a4b9f3f30f6cd439..8447a730b797d491b2a28a0ea44a1e70edcedc0f 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -86,7 +86,7 @@ class Post < ActiveRecord::Base local_post = Post.where(:guid => self.guid).first if local_post && local_post.author_id == self.author_id - known_post = user.visible_posts.where(:guid => self.guid).first + known_post = user.find_visible_post_by_id(self.guid, :key => :guid) if known_post if known_post.mutable? known_post.update_attributes(self.attributes) diff --git a/app/models/reshare.rb b/app/models/reshare.rb index d11d0a5d2f829943edd8a4ad0a4b8b73a7531f2c..2b89ccd9f6e4c936b40621aeb3ea9a834cb20eea 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -20,12 +20,9 @@ class Reshare < Post def receive(recipient, sender) local_reshare = Reshare.where(:guid => self.guid).first if local_reshare && local_reshare.root.author_id == recipient.person.id - if recipient.contact_for(sender) - local_reshare.receive(recipient, sender) - end - else - super(recipient, sender) + return unless recipient.has_contact_for?(sender) end + super(recipient, sender) end def comment_email_subject diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 7e0f6ef45b5509d3408b97d7eb0034a6050ae1e0..c34c0a37be6ad22340bf5fdf811e4217a92066d9 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -66,6 +66,12 @@ module Diaspora Contact.where(:user_id => self.id, :person_id => person_id).includes(:person => :profile).first end + # @param [Person] person + # @return [Boolean] whether person is a contact of this user + def has_contact_for?(person) + Contact.exists?(:user_id => self.id, :person_id => person.id) + end + def people_in_aspects(requested_aspects, opts={}) allowed_aspects = self.aspects & requested_aspects person_ids = contacts_in_aspects(allowed_aspects).collect{|contact| contact.person_id} diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index b9c075ddd6fe346977d144245aaf9e4314a010bb..91319f46041b6cd9f787684cac12018e39b76d32 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -26,19 +26,29 @@ describe Reshare do end describe "#receive" do + let(:receive) {@reshare.receive(@root.author.owner, @reshare.author)} before do @reshare = Factory.create(:reshare, :root => Factory(:status_message, :author => bob.person, :public => true)) @root = @reshare.root - @reshare.receive(@root.author.owner, @reshare.author) end it 'increments the reshare count' do + receive @root.resharers.count.should == 1 end it 'adds the resharer to the re-sharers of the post' do + receive @root.resharers.should include(@reshare.author) end + it 'does not error if the root author has a contact for the resharer' do + bob.share_with @reshare.author, bob.aspects.first + proc { + Timeout.timeout(5) do + receive #This doesn't ever terminate on my machine before it was fixed. + end + }.should_not raise_error + end end describe "XML" do