diff --git a/app/models/user.rb b/app/models/user.rb index 556a14641..2332f08d2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -347,7 +347,7 @@ class User < ActiveRecord::Base ######### Posts and Such ############### def retract(target) - retraction = Retraction.for(target, self) + retraction = Retraction.for(target) retraction.defer_dispatch(self) retraction.perform end diff --git a/lib/diaspora/federated/retraction.rb b/lib/diaspora/federated/retraction.rb index a68fcccfa..caa494964 100644 --- a/lib/diaspora/federated/retraction.rb +++ b/lib/diaspora/federated/retraction.rb @@ -14,17 +14,9 @@ class Retraction @target = target end - def self.for(target, sender=nil) - federation_retraction = case target - when Diaspora::Relayable - Diaspora::Federation::Entities.relayable_retraction(target, sender) - when Post - Diaspora::Federation::Entities.signed_retraction(target, sender) - else - Diaspora::Federation::Entities.retraction_data_for(target) - end - - new(federation_retraction, target.subscribers.select(&:remote?), target) + def self.for(target) + federation_retraction_data = Diaspora::Federation::Entities.retraction_data_for(target) + new(federation_retraction_data, target.subscribers.select(&:remote?), target) end def defer_dispatch(user, include_target_author=true) diff --git a/lib/diaspora/federation/entities.rb b/lib/diaspora/federation/entities.rb index bab9624b7..8286fef62 100644 --- a/lib/diaspora/federation/entities.rb +++ b/lib/diaspora/federation/entities.rb @@ -165,16 +165,6 @@ module Diaspora ) end - # @deprecated - def self.relayable_retraction(target, sender) - DiasporaFederation::Entities::RelayableRetraction.new( - target_guid: target.guid, - target_type: Mappings.entity_name_for(target), - target: related_entity(target), - author: sender.diaspora_handle - ).to_h - end - def self.reshare(reshare) DiasporaFederation::Entities::Reshare.new( root_author: reshare.root_diaspora_id, @@ -189,10 +179,6 @@ module Diaspora def self.retraction(retraction) case retraction.data[:target_type] - when "Comment", "Like", "PollParticipation" - DiasporaFederation::Entities::RelayableRetraction.new(retraction.data) - when "Post" - DiasporaFederation::Entities::SignedRetraction.new(retraction.data) when "Contact" DiasporaFederation::Entities::Contact.new(retraction.data) else @@ -214,16 +200,6 @@ module Diaspora end end - # @deprecated - def self.signed_retraction(target, sender) - DiasporaFederation::Entities::SignedRetraction.new( - target_guid: target.guid, - target_type: Mappings.entity_name_for(target), - target: related_entity(target), - author: sender.diaspora_handle - ).to_h - end - def self.status_message(status_message) DiasporaFederation::Entities::StatusMessage.new( author: status_message.diaspora_handle, diff --git a/lib/diaspora/federation/receive.rb b/lib/diaspora/federation/receive.rb index 15c3d2caf..6fd7f34bc 100644 --- a/lib/diaspora/federation/receive.rb +++ b/lib/diaspora/federation/receive.rb @@ -151,7 +151,7 @@ module Diaspora when Diaspora::Relayable if object.parent.author.local? parent_author = object.parent.author.owner - retraction = Retraction.for(object, parent_author) + retraction = Retraction.for(object) retraction.defer_dispatch(parent_author, false) retraction.perform else @@ -265,7 +265,7 @@ module Diaspora parent_author = relayable.parent.author.owner return unless parent_author && parent_author.ignored_people.include?(relayable.author) - retraction = Retraction.for(relayable, parent_author) + retraction = Retraction.for(relayable) Diaspora::Federation::Dispatcher.build(parent_author, retraction, subscribers: [relayable.author]).dispatch raise Diaspora::Federation::AuthorIgnored diff --git a/spec/lib/diaspora/federated/retraction_spec.rb b/spec/lib/diaspora/federated/retraction_spec.rb index ee5e0f485..ff5d11ab8 100644 --- a/spec/lib/diaspora/federated/retraction_spec.rb +++ b/spec/lib/diaspora/federated/retraction_spec.rb @@ -4,13 +4,13 @@ describe Retraction do let(:post) { alice.post(:status_message, text: "destroy!", public: true) } - let(:retraction) { Retraction.for(post, alice) } + let(:retraction) { Retraction.for(post) } describe "#subscribers" do it "contains all remote-subscribers of target object" do post = local_luke.post(:status_message, text: "destroy!", public: true) - retraction = Retraction.for(post, local_luke) + retraction = Retraction.for(post) expect(retraction.subscribers).to eq([remote_raphael]) end @@ -18,25 +18,25 @@ describe Retraction do describe "#data" do it "contains the hash with all data from the federation-retraction" do - federation_retraction = Diaspora::Federation::Entities.signed_retraction(post, alice) + federation_retraction_data = Diaspora::Federation::Entities.retraction_data_for(post) - expect(retraction.data).to eq(federation_retraction.to_h) + expect(retraction.data).to eq(federation_retraction_data) end end describe ".for" do it "creates a retraction for a post" do - expect(Diaspora::Federation::Entities).to receive(:signed_retraction).with(post, alice) + expect(Diaspora::Federation::Entities).to receive(:retraction_data_for).with(post) - Retraction.for(post, alice) + Retraction.for(post) end it "creates a retraction for a relayable" do comment = FactoryGirl.create(:comment, author: alice.person, post: post) - expect(Diaspora::Federation::Entities).to receive(:relayable_retraction).with(comment, alice) + expect(Diaspora::Federation::Entities).to receive(:retraction_data_for).with(comment) - Retraction.for(comment, alice) + Retraction.for(comment) end it "creates a retraction for a contact" do @@ -44,20 +44,21 @@ describe Retraction do expect(Diaspora::Federation::Entities).to receive(:retraction_data_for).with(contact) - Retraction.for(contact, contact.user) + Retraction.for(contact) end end describe ".defer_dispatch" do it "queues a job to send the retraction later" do post = local_luke.post(:status_message, text: "destroy!", public: true) - federation_retraction = Diaspora::Federation::Entities.signed_retraction(post, local_luke) + retraction = Retraction.for(post) + federation_retraction = Diaspora::Federation::Entities.retraction(retraction) expect(Workers::DeferredRetraction).to receive(:perform_async).with( local_luke.id, federation_retraction.to_h, [remote_raphael.id], service_types: [] ) - Retraction.for(post, local_luke).defer_dispatch(local_luke) + retraction.defer_dispatch(local_luke) end it "adds service metadata to queued job for deletion" do @@ -66,47 +67,50 @@ describe Retraction do facebook = Services::Facebook.new(access_token: "facebook") alice.services << twitter << facebook - federation_retraction = Diaspora::Federation::Entities.signed_retraction(post, alice) + retraction = Retraction.for(post) + federation_retraction = Diaspora::Federation::Entities.retraction(retraction) expect(Workers::DeferredRetraction).to receive(:perform_async).with( alice.id, federation_retraction.to_h, [], service_types: ["Services::Twitter"], tweet_id: "123" ) - Retraction.for(post, alice).defer_dispatch(alice) + retraction.defer_dispatch(alice) end it "queues also a job if subscribers is empty" do - federation_retraction = Diaspora::Federation::Entities.signed_retraction(post, alice) + retraction = Retraction.for(post) + federation_retraction = Diaspora::Federation::Entities.retraction(retraction) expect(Workers::DeferredRetraction).to receive(:perform_async).with( alice.id, federation_retraction.to_h, [], service_types: [] ) - Retraction.for(post, alice).defer_dispatch(alice) + retraction.defer_dispatch(alice) end it "queues a job with empty opts for non-StatusMessage" do post = local_luke.post(:status_message, text: "hello", public: true) comment = local_luke.comment!(post, "destroy!") - federation_retraction = Diaspora::Federation::Entities.relayable_retraction(comment, local_luke) + retraction = Retraction.for(comment) + federation_retraction = Diaspora::Federation::Entities.retraction(retraction) expect(Workers::DeferredRetraction).to receive(:perform_async).with( local_luke.id, federation_retraction.to_h, [remote_raphael.id], {} ) - Retraction.for(comment, local_luke).defer_dispatch(local_luke) + retraction.defer_dispatch(local_luke) end it "uses the author of the target parent as sender for a comment-retraction if the parent is local" do post = local_luke.post(:status_message, text: "hello", public: true) comment = local_leia.comment!(post, "destroy!") - federation_retraction = Diaspora::Federation::Entities.relayable_retraction(comment, local_leia) + federation_retraction = Diaspora::Federation::Entities.retraction(comment) expect(Workers::DeferredRetraction).to receive(:perform_async).with( local_luke.id, federation_retraction.to_h, [remote_raphael.id], {} ) - Retraction.for(comment, local_leia).defer_dispatch(local_leia) + Retraction.for(comment).defer_dispatch(local_leia) end context "relayable" do @@ -114,23 +118,25 @@ describe Retraction do let(:comment) { FactoryGirl.create(:comment, post: post, author: remote_raphael) } it "sends retraction to target author if deleted by parent author" do - federation_retraction = Diaspora::Federation::Entities.relayable_retraction(comment, local_luke) + retraction = Retraction.for(comment) + federation_retraction = Diaspora::Federation::Entities.retraction(retraction) expect(Workers::DeferredRetraction).to receive(:perform_async).with( local_luke.id, federation_retraction.to_h, [remote_raphael.id], {} ) - Retraction.for(comment, local_luke).defer_dispatch(local_luke) + retraction.defer_dispatch(local_luke) end it "don't sends retraction back to target author if relayed by parent author" do - federation_retraction = Diaspora::Federation::Entities.relayable_retraction(comment, local_luke) + retraction = Retraction.for(comment) + federation_retraction = Diaspora::Federation::Entities.retraction(retraction) expect(Workers::DeferredRetraction).to receive(:perform_async).with( local_luke.id, federation_retraction.to_h, [], {} ) - Retraction.for(comment, local_luke).defer_dispatch(local_luke, false) + retraction.defer_dispatch(local_luke, false) end end end @@ -138,29 +144,29 @@ describe Retraction do describe "#perform" do it "destroys the target object" do expect(post).to receive(:destroy!) - Retraction.for(post, alice).perform + Retraction.for(post).perform end end describe "#public?" do it "returns true for a public post" do - expect(Retraction.for(post, alice).public?).to be_truthy + expect(Retraction.for(post).public?).to be_truthy end it "returns true for a public comment if parent post is local" do comment = bob.comment!(post, "destroy!") - expect(Retraction.for(comment, bob).public?).to be_truthy + expect(Retraction.for(comment).public?).to be_truthy end it "returns false for a public comment if parent post is not local" do remote_post = FactoryGirl.create(:status_message, author: remote_raphael) comment = alice.comment!(remote_post, "destroy!") - expect(Retraction.for(comment, alice).public?).to be_falsey + expect(Retraction.for(comment).public?).to be_falsey end it "returns false for a private target" do private_post = alice.post(:status_message, text: "destroy!", to: alice.aspects.first.id) - expect(Retraction.for(private_post, alice).public?).to be_falsey + expect(Retraction.for(private_post).public?).to be_falsey end end end diff --git a/spec/lib/diaspora/federation/receive_spec.rb b/spec/lib/diaspora/federation/receive_spec.rb index 3da798df1..1bff8ddad 100644 --- a/spec/lib/diaspora/federation/receive_spec.rb +++ b/spec/lib/diaspora/federation/receive_spec.rb @@ -507,9 +507,9 @@ describe Diaspora::Federation::Receive do target_type: "Comment" ) - comment_retraction = Retraction.for(remote_comment, alice) + comment_retraction = Retraction.for(remote_comment) - expect(Retraction).to receive(:for).with(instance_of(Comment), alice).and_return(comment_retraction) + expect(Retraction).to receive(:for).with(instance_of(Comment)).and_return(comment_retraction) expect(comment_retraction).to receive(:defer_dispatch).with(alice, false) expect(comment_retraction).to receive(:perform).and_call_original expect_any_instance_of(Comment).to receive(:destroy!).and_call_original diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f12f0390c..719129c78 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -778,7 +778,7 @@ describe User, :type => :model do context "posts" do it "sends a retraction" do - expect(Retraction).to receive(:for).with(post, bob).and_return(retraction) + expect(Retraction).to receive(:for).with(post).and_return(retraction) expect(retraction).to receive(:defer_dispatch).with(bob) expect(retraction).to receive(:perform) diff --git a/spec/shared_behaviors/dispatcher.rb b/spec/shared_behaviors/dispatcher.rb index 1d87d8c24..b168465d8 100644 --- a/spec/shared_behaviors/dispatcher.rb +++ b/spec/shared_behaviors/dispatcher.rb @@ -17,7 +17,7 @@ shared_examples "a dispatcher" do opts = {service_types: "Services::Twitter", tweet_id: "123"} expect(Workers::DeletePostFromService).to receive(:perform_async).with(twitter.id, opts) - retraction = Retraction.for(post, alice) + retraction = Retraction.for(post) Diaspora::Federation::Dispatcher.build(alice, retraction, opts).dispatch end @@ -35,7 +35,7 @@ shared_examples "a dispatcher" do it "does not deliver a Retraction of a Comment to services" do expect(Workers::DeletePostFromService).not_to receive(:perform_async) - retraction = Retraction.for(comment, alice) + retraction = Retraction.for(comment) Diaspora::Federation::Dispatcher.build(alice, retraction).dispatch end end