disconnect when receiving a Contact with sharing=false
This commit is contained in:
parent
2367be3f66
commit
f58167c154
2 changed files with 35 additions and 1 deletions
|
|
@ -21,7 +21,12 @@ module Diaspora
|
||||||
|
|
||||||
def self.contact(entity)
|
def self.contact(entity)
|
||||||
recipient = Person.find_by(diaspora_handle: entity.recipient).owner
|
recipient = Person.find_by(diaspora_handle: entity.recipient).owner
|
||||||
Contact.create_or_update_sharing_contact(recipient, author_of(entity))
|
if entity.sharing.to_s == "true"
|
||||||
|
Contact.create_or_update_sharing_contact(recipient, author_of(entity))
|
||||||
|
else
|
||||||
|
recipient.disconnected_by(author_of(entity))
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.conversation(entity)
|
def self.conversation(entity)
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,35 @@ describe Diaspora::Federation::Receive do
|
||||||
|
|
||||||
expect(Diaspora::Federation::Receive.contact(contact_entity)).to be_nil
|
expect(Diaspora::Federation::Receive.contact(contact_entity)).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "sharing=false" do
|
||||||
|
let(:unshare_contact_entity) {
|
||||||
|
FactoryGirl.build(
|
||||||
|
:contact_entity,
|
||||||
|
author: sender.diaspora_handle,
|
||||||
|
recipient: alice.diaspora_handle,
|
||||||
|
sharing: "false"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
it "disconnects, if currently connected" do
|
||||||
|
alice.contacts.find_or_initialize_by(person_id: sender.id, receiving: true, sharing: true).save!
|
||||||
|
|
||||||
|
received = Diaspora::Federation::Receive.contact(unshare_contact_entity)
|
||||||
|
expect(received).to be_nil
|
||||||
|
|
||||||
|
contact = alice.contacts.find_by!(person_id: sender.id)
|
||||||
|
|
||||||
|
expect(contact).not_to be_nil
|
||||||
|
expect(contact.sharing).to be_falsey
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does nothing, if already disconnected" do
|
||||||
|
received = Diaspora::Federation::Receive.contact(unshare_contact_entity)
|
||||||
|
expect(received).to be_nil
|
||||||
|
expect(alice.contacts.find_by(person_id: sender.id)).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".conversation" do
|
describe ".conversation" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue