Contact retraction

This commit is contained in:
Benjamin Neff 2016-06-03 06:00:56 +02:00
parent 89fbcf7c56
commit 65ba573a3b
3 changed files with 37 additions and 12 deletions

View file

@ -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

View file

@ -200,13 +200,24 @@ module Diaspora
end
def self.retraction(target)
case target
when Contact
author = target.user.diaspora_handle
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_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
def self.signed_retraction(target, sender)

View file

@ -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