diff --git a/app/models/comment.rb b/app/models/comment.rb index 372f3857143de0e17918394f952b2da42f589f9e..c2d3f29779ad85485837c87cd1cc5fbdecc68880 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -52,9 +52,9 @@ class Comment def subscribers(user) if user.owns?(self.post) - p = user.people_in_aspects(user.aspects_with_post(self.post_id)) + p = self.post.subscribers(user) elsif user.owns?(self) - p = [self.post.person] + p = [self.post.person] end p end diff --git a/app/models/jobs/post_to_services.rb b/app/models/jobs/post_to_services.rb index e29b1d609df1c15b7f3269a511d4bb32abb22e24..037de30f7eb4109e1c34009a79e7c4fd56af2d14 100644 --- a/app/models/jobs/post_to_services.rb +++ b/app/models/jobs/post_to_services.rb @@ -5,8 +5,9 @@ module Jobs def self.perform(user_id, post_id, url) user = User.find_by_id(user_id) post = Post.find_by_id(post_id) - user.post_to_services(post, url) + user.services.each do |s| + s.post(post, url) + end end end end - diff --git a/app/models/jobs/socket_webfinger.rb b/app/models/jobs/socket_webfinger.rb index 633f7b8e68bbd633d0b47e33dc90795cb755205a..91228c8d6622ec760efde37d3e5f193adc341e8c 100644 --- a/app/models/jobs/socket_webfinger.rb +++ b/app/models/jobs/socket_webfinger.rb @@ -5,8 +5,9 @@ module Jobs def self.perform(user_id, account, opts={}) finger = Webfinger.new(account) begin + user = User.find_by_id(user_id) result = finger.fetch - result.socket_to_uid(user_id, opts) + result.socket_to_uid(user, opts) rescue Diaspora::WebSocket.queue_to_user(user_id, {:class => 'people', diff --git a/app/models/notification.rb b/app/models/notification.rb index 2fbccc99e5d66d335448de93cfc426caee162680..b8f8f2e2f041a208abce7c81c2380c471dbadf89 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -29,8 +29,8 @@ class Notification :kind => kind, :person_id => person.id, :user_id => user.id) - n.socket_to_uid(user.id) if n n.email_the_user(object) unless user.disable_mail || !n + n.socket_to_uid(user) if n n end end diff --git a/app/models/user.rb b/app/models/user.rb index ea6da134dc15f620cf7902935d71c1818535419e..fb6ed9dc443265435292c9a0ad26fb062dc50744 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -157,7 +157,7 @@ class User self.raw_visible_posts << post self.save - post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to? :socket_to_uid + post.socket_to_uid(self, :aspect_ids => aspect_ids) if post.respond_to? :socket_to_uid target_aspects = aspects_from_ids(aspect_ids) target_aspects.each do |aspect| aspect.posts << post @@ -198,28 +198,6 @@ class User def dispatch_comment(comment) mailman = Postzord::Dispatch.new(self, comment) mailman.post - #if owns? comment.post - ##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 - - ##push to remote people - #push_to_people(comment, people_in_aspects(aspects, :type => 'remote')) - - #elsif owns? comment - ##push UPSTREAM (to poster) - #Rails.logger.info "event=dispatch_comment direction=upstream user=#{self.diaspora_handle} comment=#{comment.id}" - #push_to_people comment, [comment.post.person] - #end end ######### Mailer ####################### @@ -234,8 +212,8 @@ class User aspect_ids = aspects_with_post(post.id) aspect_ids.map! { |aspect| aspect.id.to_s } - post.unsocket_from_uid(self.id, :aspect_ids => aspect_ids) if post.respond_to? :unsocket_from_uid retraction = Retraction.for(post) + post.unsocket_from_uid(self, retraction, :aspect_ids => aspect_ids) if post.respond_to? :unsocket_from_uid mailman = Postzord::Dispatch.new(self, retraction) mailman.post diff --git a/lib/diaspora/user/receiving.rb b/lib/diaspora/user/receiving.rb index fac7e7d2336a43912d01f5715c3c8ac2e4dcf223..a9d8f053906bdc16bdee80ade262ac5ce717aa0f 100644 --- a/lib/diaspora/user/receiving.rb +++ b/lib/diaspora/user/receiving.rb @@ -59,8 +59,6 @@ module Diaspora receive_object(object, person) Rails.logger.info("event=receive status=complete recipient=#{self.diaspora_handle} sender=#{salmon_author.diaspora_handle} payload_type#{object.class}") - - return object end end @@ -92,7 +90,7 @@ module Diaspora end disconnected_by visible_person_by_id(retraction.post_id) else - retraction.perform self.id + retraction.perform self aspects = self.aspects_with_person(retraction.person) aspects.each{ |aspect| aspect.post_ids.delete(retraction.post_id.to_id) aspect.save @@ -138,7 +136,7 @@ module Diaspora dispatch_comment comment end - comment.socket_to_uid(self.id, :aspect_ids => comment.post.aspect_ids) + comment.socket_to_uid(self, :aspect_ids => comment.post.aspect_ids) comment end @@ -146,7 +144,7 @@ module Diaspora post.class.find_by_id(post.id) end - def receive_post post + def receive_post(post) #exsists locally, but you dont know about it #does not exsist locally, and you dont know about it @@ -191,7 +189,7 @@ module Diaspora aspect.posts << post aspect.save end - post.socket_to_uid(id, :aspect_ids => aspects.map{|x| x.id}) if (post.respond_to?(:socket_to_uid) && !self.owns?(post)) + post.socket_to_uid(self, :aspect_ids => aspects.map{|x| x.id}) if (post.respond_to?(:socket_to_uid) && !self.owns?(post)) post end end diff --git a/lib/diaspora/web_socket.rb b/lib/diaspora/web_socket.rb index c25bebf842451a70c8963260c0571db98d4052d1..04b14f6528f0bd6517aec663f7d4f429e4a2b4ae 100644 --- a/lib/diaspora/web_socket.rb +++ b/lib/diaspora/web_socket.rb @@ -49,12 +49,12 @@ module Diaspora end module Socketable - def socket_to_uid(id, opts={}) - SocketsController.new.outgoing(id, self, opts) + def socket_to_uid(user, opts={}) + SocketsController.new.outgoing(user, self, opts) end - def unsocket_from_uid(id, opts={}) - SocketsController.new.outgoing(id, Retraction.for(self), opts) + def unsocket_from_uid(user, retraction, opts={}) + SocketsController.new.outgoing(user, retraction, opts) end end end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 3ca7bc750a32294b3a81bb7fa2343b1eb4dab066..a109b9499bf3c99da34e9ff4d455a011c74e2496 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -98,10 +98,12 @@ describe Comment do end end - describe 'comment propagation' do + context 'comment propagation' do before do @person = Factory.create(:person) user.activate_contact(@person, Aspect.first(:id => aspect.id)) + @person3 = Factory.create(:person) + user.activate_contact(@person3, Aspect.first(:id => aspect.id)) @person2 = Factory.create(:person) @person_status = Factory.build(:status_message, :person => @person) @@ -119,17 +121,20 @@ describe Comment do Postzord::Dispatch.should_receive(:new).and_return(m) user.comment "yo", :on => @person_status end - - describe '#subscribers' do it 'returns the posts original audience, if the post is owned by the user' do + comment = user.build_comment "yo", :on => @person_status + comment.subscribers(user).should =~ [@person] end it 'returns the owner of the original post, if the user owns the comment' do + comment = user.build_comment "yo", :on => @user_status + comment.subscribers(user).should =~ [@person, @person3, user2.person] end end + context 'testing a method only used for testing' do it "should send a user's comment on a person's post to that person" do m = mock() m.stub!(:post) @@ -137,31 +142,7 @@ describe Comment do user.comment "yo", :on => @person_status end - - #context 'posts from a remote person' do - #before(:all) do - #stub_comment_signature_verification - #end - #before do - #@mailman = Postzord::Dipatch.new(user, @person_status) - #end - - #it 'should not send a comment a person made on his own post to anyone' do - #@mailman.should_not_receive(:deliver_to_local) - #comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status) - #user.receive comment.to_diaspora_xml, @person - #end - - #it 'should not send a comment a person made on a person post to anyone' do - #@mailman.should_not_receive(:deliver_to_local) - #comment = Comment.new(:person_id => @person2.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status) - #user.receive comment.to_diaspora_xml, @person - #end - - #after(:all) do - #unstub_mocha_stubs - #end - #end + end it 'should not clear the aspect post array on receiving a comment' do aspect.post_ids.include?(@user_status.id).should be true diff --git a/spec/models/jobs/post_to_services_spec.rb b/spec/models/jobs/post_to_services_spec.rb index 23b8751c5795cd376bd3b75bf77ef96e2c64c2ce..0d84516b5c97d6c2ecc6dcefff29d2e7316466d8 100644 --- a/spec/models/jobs/post_to_services_spec.rb +++ b/spec/models/jobs/post_to_services_spec.rb @@ -6,9 +6,10 @@ describe Jobs::PostToServices do aspect = user.aspects.create(:name => "yeah") post = user.post(:status_message, :message => 'foo', :to => aspect.id) User.stub!(:find_by_id).with(user.id.to_s).and_return(user) - user.stub!(:services).and_return([]) - user.should_receive(:post_to_services) + m = mock() url = "foobar" + m.should_receive(:post).with(anything, url) + user.stub!(:services).and_return([m]) Jobs::PostToServices.perform(user.id.to_s, post.id.to_s, url) end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 9369798358247f4b7c216dc16c99130d3b5ebf38..c69a155e8ce4225827f7b40a404ac0196362bf12 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -36,4 +36,13 @@ describe Post do post.mutable?.should == false end end + + describe '#subscribers' do + it 'returns the people contained in the aspects the post appears in' do + + post = @user.post :status_message, :message => "hello", :to => @aspect.id + + post.subscribers(@user).should =~ [] + end + end end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index b8a12571085eb32bed70d616e62dd40b029ac9e8..4a56b4fc8344156324982bdd338c023968647894 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -74,6 +74,20 @@ describe Profile do end end + describe '#subscribers' do + it 'returns all non-pending contacts for a user' do + user = make_user + aspect = user.aspects.create(:name => "zord") + person = Factory.create(:person) + user.activate_contact(person, Aspect.first(:id => aspect.id)) + + person2 = Factory.create(:person) + user.activate_contact(person2, Aspect.first(:id => aspect.id)) + + user.profile.subscribers(user).should =~ [person, person2] + end + end + describe 'date=' do let(:profile) { make_user.profile } diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index aaa1fc1e4f7c41e67940217eca25f9efcf2179dd..eb460588c6b7c05af9bbe91ea774368f2e6da1c4 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -80,6 +80,7 @@ describe Request do Request.from(@user).to(@user2.person).first.should == @request end end + describe '#notification_type' do before do @request = Request.instantiate(:from => @user.person, :to => @user2.person, :into => @aspect) @@ -94,6 +95,13 @@ describe Request do end end + describe '#subscribers' do + it 'returns an array with to field on a request' do + request = Request.instantiate(:from => @user.person, :to => @user2.person, :into => @aspect) + request.subscribers(@user).should =~ [@user2.person] + end + end + describe '.hashes_for_person' do before do @user = make_user diff --git a/spec/models/retraction_spec.rb b/spec/models/retraction_spec.rb index 78e21d05d211d2877fb98c2f9e198b2c7775b80f..0b7762505974b0e41a001087ed1e6ce49c226da7 100644 --- a/spec/models/retraction_spec.rb +++ b/spec/models/retraction_spec.rb @@ -20,14 +20,38 @@ describe Retraction do end end + describe '#subscribers' do + it 'returns the subscribers to the post for all objects other than person' do + retraction = Retraction.for(post) + obj = retraction.instance_variable_get(:@object) + wanted_subscribers = obj.subscribers(user) + obj.should_receive(:subscribers).with(user).and_return(wanted_subscribers) + retraction.subscribers(user).should =~ wanted_subscribers + end + + context 'hax' do + it 'barfs if the type is a person, and subscribers instance varabile is not set' do + retraction = Retraction.for(user) + obj = retraction.instance_variable_get(:@object) + + proc{retraction.subscribers(user)}.should raise_error + end + + it 'returns manually set subscribers' do + retraction = Retraction.for(user) + retraction.subscribers = "fooey" + retraction.subscribers(user).should == 'fooey' + end + end + end + describe 'dispatching' do - it 'should dispatch a message on delete' do + it 'should dispatch a retraction on delete' do Factory.create(:person) m = mock() m.should_receive(:post) - Postzord::Dispatch.should_receive(:new).and_return(m) + Postzord::Dispatch.should_receive(:new).with(instance_of(User), instance_of(Retraction)).and_return(m) post.destroy end end - end diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 515446cd513257779c8de50fa3f048c504d758f8..8750736a60c13861f91c05a9c516bfbbcc9d9a39 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -38,7 +38,7 @@ describe User do end it 'sockets the post to the poster' do - @post.should_receive(:socket_to_uid).with(user.id, anything) + @post.should_receive(:socket_to_uid).with(user, anything) user.add_to_streams(@post, @aspect_ids) end end