Use ContactRetraction for stop sharing with someone
This commit is contained in:
parent
e2a40bb643
commit
c2b9b8ab54
7 changed files with 40 additions and 27 deletions
|
|
@ -34,8 +34,7 @@ class User
|
|||
if contact.person.local?
|
||||
contact.person.owner.disconnected_by(contact.user.person)
|
||||
else
|
||||
contact.receiving = false
|
||||
Retraction.for(contact).defer_dispatch(self)
|
||||
ContactRetraction.for(contact).defer_dispatch(self)
|
||||
end
|
||||
|
||||
contact.aspect_memberships.delete_all
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ module Workers
|
|||
class DeferredRetraction < Base
|
||||
sidekiq_options queue: :high
|
||||
|
||||
def perform(user_id, retraction_data, recipient_ids, opts)
|
||||
def perform(user_id, retraction_class, retraction_data, recipient_ids, opts)
|
||||
user = User.find(user_id)
|
||||
subscribers = Person.where(id: recipient_ids)
|
||||
object = Retraction.new(retraction_data.deep_symbolize_keys, subscribers)
|
||||
object = retraction_class.constantize.new(retraction_data.deep_symbolize_keys, subscribers)
|
||||
opts = HashWithIndifferentAccess.new(opts)
|
||||
|
||||
Diaspora::Federation::Dispatcher.build(user, object, opts).dispatch
|
||||
|
|
|
|||
|
|
@ -6,5 +6,6 @@ module Diaspora
|
|||
module Federated
|
||||
require "diaspora/federated/base"
|
||||
require "diaspora/federated/retraction"
|
||||
require "diaspora/federated/contact_retraction"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
18
lib/diaspora/federated/contact_retraction.rb
Normal file
18
lib/diaspora/federated/contact_retraction.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
class ContactRetraction < Retraction
|
||||
def self.entity_class
|
||||
DiasporaFederation::Entities::Contact
|
||||
end
|
||||
|
||||
def self.retraction_data_for(target)
|
||||
Diaspora::Federation::Entities.contact(target).to_h
|
||||
end
|
||||
|
||||
def self.for(target)
|
||||
target.receiving = false
|
||||
super
|
||||
end
|
||||
|
||||
def public?
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
@ -14,14 +14,27 @@ class Retraction
|
|||
@target = target
|
||||
end
|
||||
|
||||
def self.entity_class
|
||||
DiasporaFederation::Entities::Retraction
|
||||
end
|
||||
|
||||
def self.retraction_data_for(target)
|
||||
DiasporaFederation::Entities::Retraction.new(
|
||||
target_guid: target.guid,
|
||||
target: Diaspora::Federation::Entities.related_entity(target),
|
||||
target_type: Diaspora::Federation::Mappings.entity_name_for(target),
|
||||
author: target.diaspora_handle
|
||||
).to_h
|
||||
end
|
||||
|
||||
def self.for(target)
|
||||
federation_retraction_data = Diaspora::Federation::Entities.retraction_data_for(target)
|
||||
federation_retraction_data = retraction_data_for(target)
|
||||
new(federation_retraction_data, target.subscribers.select(&:remote?), target)
|
||||
end
|
||||
|
||||
def defer_dispatch(user, include_target_author=true)
|
||||
subscribers = dispatch_subscribers(include_target_author)
|
||||
Workers::DeferredRetraction.perform_async(user.id, data, subscribers.map(&:id), service_opts(user))
|
||||
Workers::DeferredRetraction.perform_async(user.id, self.class.to_s, data, subscribers.map(&:id), service_opts(user))
|
||||
end
|
||||
|
||||
def perform
|
||||
|
|
@ -31,7 +44,7 @@ class Retraction
|
|||
end
|
||||
|
||||
def public?
|
||||
data[:target] && data[:target][:public]
|
||||
data[:target][:public]
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -178,26 +178,7 @@ module Diaspora
|
|||
end
|
||||
|
||||
def self.retraction(retraction)
|
||||
case retraction.data[:target_type]
|
||||
when "Contact"
|
||||
DiasporaFederation::Entities::Contact.new(retraction.data)
|
||||
else
|
||||
DiasporaFederation::Entities::Retraction.new(retraction.data)
|
||||
end
|
||||
end
|
||||
|
||||
def self.retraction_data_for(target)
|
||||
case target
|
||||
when Contact
|
||||
contact(target).to_h.tap {|data| data[:target_type] = "Contact" }
|
||||
else
|
||||
DiasporaFederation::Entities::Retraction.new(
|
||||
target_guid: target.guid,
|
||||
target_type: Mappings.entity_name_for(target),
|
||||
target: related_entity(target),
|
||||
author: target.diaspora_handle
|
||||
).to_h
|
||||
end
|
||||
retraction.class.entity_class.new(retraction.data)
|
||||
end
|
||||
|
||||
def self.status_message(status_message)
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ module Diaspora
|
|||
Profile => :profile,
|
||||
Reshare => :reshare,
|
||||
Retraction => :retraction,
|
||||
ContactRetraction => :retraction,
|
||||
StatusMessage => :status_message
|
||||
}.freeze
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue