diff --git a/app/models/user/connecting.rb b/app/models/user/connecting.rb index 7dddd0b7b..643aff303 100644 --- a/app/models/user/connecting.rb +++ b/app/models/user/connecting.rb @@ -31,7 +31,11 @@ class User def disconnect(contact) logger.info "event=disconnect user=#{diaspora_handle} target=#{contact.person.diaspora_handle}" - # TODO: send retraction + if contact.person.local? + contact.person.owner.disconnected_by(contact.user.person) + else + Retraction.for(contact).defer_dispatch(self) + end contact.aspect_memberships.delete_all diff --git a/lib/diaspora/federation/entities.rb b/lib/diaspora/federation/entities.rb index 96562a1aa..7694a5b85 100644 --- a/lib/diaspora/federation/entities.rb +++ b/lib/diaspora/federation/entities.rb @@ -200,12 +200,23 @@ module Diaspora end def self.retraction(target) - DiasporaFederation::Entities::Retraction.new( - target_guid: target.is_a?(User) ? target.person.guid : target.guid, - target_type: target.is_a?(User) ? Person.to_s : target.class.base_class.to_s, - target: related_entity(target), - author: target.diaspora_handle - ) + case target + when Contact + author = target.user.diaspora_handle + DiasporaFederation::Entities::Retraction.new( + target_guid: target.user.guid, + target_type: Person.to_s, + target: DiasporaFederation::Entities::RelatedEntity.new(author: author, local: true), + author: author + ) + else + DiasporaFederation::Entities::Retraction.new( + target_guid: target.guid, + target_type: target.class.base_class.to_s, + target: related_entity(target), + author: target.diaspora_handle + ) + end end # @deprecated diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index 1161f9643..c37b92936 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -41,8 +41,6 @@ describe User::Connecting, type: :model do end it "removes notitications" do - skip # TODO - alice.share_with(eve.person, alice.aspects.first) expect(Notifications::StartedSharing.where(recipient_id: eve.id).first).not_to be_nil eve.disconnected_by(alice.person) @@ -79,10 +77,22 @@ describe User::Connecting, type: :model do expect(contact).to be_sharing end - it "dispatches a retraction" do - skip # TODO + it "dispatches a retraction for local person" do + contact = bob.contact_for(eve.person) - bob.disconnect bob.contact_for(eve.person) + expect(contact.person.owner).to receive(:disconnected_by).with(bob.person) + + bob.disconnect(contact) + end + + it "dispatches a retraction for remote person" do + contact = local_leia.contact_for(remote_raphael) + retraction = double + + expect(Retraction).to receive(:for).with(contact).and_return(retraction) + expect(retraction).to receive(:defer_dispatch).with(local_leia) + + local_leia.disconnect(contact) end it "should remove the contact from all aspects they are in" do