diff --git a/app/models/user.rb b/app/models/user.rb index e8a03e261..039f7225c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -304,11 +304,12 @@ class User #push DOWNSTREAM (to original audience) Rails.logger.info "event=dispatch_comment direction=downstream user=#{self.diaspora_handle} comment=#{comment.id}" aspects = aspects_with_post(comment.post_id) - + #just socket to local users, as the comment has already #been associated and saved by post owner # (we'll push to all of their aspects for now, the comment won't # show up via js where corresponding posts are not present) + people_in_aspects(aspects, :type => 'local').each do |person| comment.socket_to_uid(person.owner_id, :aspect_ids => 'all') end diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 1cadcc725..7ffa1ba94 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -63,12 +63,11 @@ module Diaspora people = Person.all(:id.in => person_ids) if opts[:type] == 'remote' - people.delete_if{ |p| !p.owner_id.blank? } + people.delete_if{ |p| !p.owner.blank? } elsif opts[:type] == 'local' - people.delete_if{ |p| p.owner_id.blank? } - else - people + people.delete_if{ |p| p.owner.blank? } end + people end def aspect_by_id( id ) diff --git a/lib/diaspora/user/receiving.rb b/lib/diaspora/user/receiving.rb index 62809085c..068b3b907 100644 --- a/lib/diaspora/user/receiving.rb +++ b/lib/diaspora/user/receiving.rb @@ -100,7 +100,7 @@ module Diaspora end def receive_comment comment - + commenter = comment.person unless comment.post.person == self.person || comment.verify_post_creator_signature @@ -121,8 +121,8 @@ module Diaspora #dispatch comment DOWNSTREAM, received it via UPSTREAM unless owns?(comment) - dispatch_comment comment comment.save + dispatch_comment comment end comment.socket_to_uid(self.id, :aspect_ids => comment.post.aspect_ids) diff --git a/spec/models/user/commenting_spec.rb b/spec/models/user/commenting_spec.rb new file mode 100644 index 000000000..d4e9e27eb --- /dev/null +++ b/spec/models/user/commenting_spec.rb @@ -0,0 +1,58 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' + +describe User do + + let!(:user1){make_user} + let!(:user2){make_user} + let!(:aspect1){user1.aspects.create(:name => 'heroes')} + let!(:aspect2){user2.aspects.create(:name => 'others')} + + before do + connect_users(user1, aspect1, user2, aspect2) + @post = user1.build_post(:status_message, :message => "hey", :to => aspect1.id) + @post.save + user1.dispatch_post(@post, :to => "all") + end + + describe '#dispatch_comment' do + + context 'post owners contact comments on post' do + it 'should not call receive on local users' do + pending 'need to call should_receive without it being destructive' + + user1.should_receive(:receive_comment) + user2.should_not_receive(:receive_comment) + user1.should_receive(:dispatch_comment) + + user1.reload + user2.reload + + comment = user2.build_comment "why so formal?", :on => @post + comment.save! + user2.dispatch_comment comment + end + end + + context 'post owner comments on own post' do + it 'should only dispatch once' do + pending 'need to call should_receive without it being destructive' + + user1.should_receive(:dispatch_comment).once + user2.should_not_receive(:receive_comment) + user2.should_not_receive(:dispatch_comment) + + user1.reload + user2.reload + + comment = user1.build_comment "why so serious?", :on => @post + comment.save + user1.dispatch_comment comment + end + end + + end +end diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index a03545736..a9af5ab96 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -130,14 +130,14 @@ describe User do end describe '#people_in_aspects' do - it 'should return people objects for a users contact in each aspect' do + it 'returns people objects for a users contact in each aspect' do people = user.people_in_aspects([first_aspect]) people.should == [user4.person] people = user.people_in_aspects([second_aspect]) people.should == [user2.person] end - it 'should return local/remote people objects for a users contact in each aspect' do + it 'returns local/remote people objects for a users contact in each aspect' do local_user1 = make_user local_user2 = make_user remote_user = make_user @@ -159,6 +159,14 @@ describe User do user.people_in_aspects([first_aspect], :type => 'remote').count.should == 1 user.people_in_aspects([first_aspect], :type => 'local').count.should == 3 end + + it 'does not return people not connected to user on same pod' do + local_user1 = make_user + local_user2 = make_user + local_user3 = make_user + + user.people_in_aspects([first_aspect]).count.should == 1 + end end end