From 0f6e0b7288ca3350250d2d9f6842ab9dcc02634f Mon Sep 17 00:00:00 2001 From: Benjamin Neff <benjamin@coding4coffee.ch> Date: Tue, 14 Jun 2016 18:08:14 +0200 Subject: [PATCH] send the profile to remote persons on start shareing with them --- app/models/user.rb | 4 ++-- app/models/user/connecting.rb | 2 +- spec/models/user/connecting_spec.rb | 12 ++++++++++-- spec/models/user_spec.rb | 4 ++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index f608ee848a..b187a9ea3b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -394,8 +394,8 @@ class User < ActiveRecord::Base update_profile( self.profile.from_omniauth_hash( user_info ) ) end - def deliver_profile_update - Diaspora::Federation::Dispatcher.defer_dispatch(self, profile) + def deliver_profile_update(opts={}) + Diaspora::Federation::Dispatcher.defer_dispatch(self, profile, opts) end def basic_profile_present? diff --git a/app/models/user/connecting.rb b/app/models/user/connecting.rb index 643aff3039..0781745f46 100644 --- a/app/models/user/connecting.rb +++ b/app/models/user/connecting.rb @@ -19,12 +19,12 @@ class User if needs_dispatch Diaspora::Federation::Dispatcher.defer_dispatch(self, contact) + deliver_profile_update(subscriber_ids: [person.id]) unless person.local? end Notifications::StartedSharing.where(recipient_id: id, target: person.id, unread: true) .update_all(unread: false) - deliver_profile_update contact end diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index c37b929364..8b8262dd28 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -167,9 +167,17 @@ describe User::Connecting, type: :model do alice.share_with(eve.person, aspect2) end - it "posts profile" do + it "delivers profile for remote persons" do allow(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch) - expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, alice.profile) + expect(Diaspora::Federation::Dispatcher) + .to receive(:defer_dispatch).with(alice, alice.profile, subscriber_ids: [remote_raphael.id]) + + alice.share_with(remote_raphael, alice.aspects.first) + end + + it "does not deliver profile for remote persons" do + allow(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch) + expect(Diaspora::Federation::Dispatcher).not_to receive(:defer_dispatch).with(alice, alice.profile, anything) alice.share_with(eve.person, alice.aspects.first) end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index dcd5ff4778..8ba7a391ed 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -494,12 +494,12 @@ describe User, :type => :model do it "dispatches the profile when tags are set" do @params = {tag_string: '#what #hey'} - expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, alice.profile) + expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, alice.profile, {}) expect(alice.update_profile(@params)).to be true end it "sends a profile to their contacts" do - expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, alice.profile) + expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, alice.profile, {}) expect(alice.update_profile(@params)).to be true end -- GitLab