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?
|
if contact.person.local?
|
||||||
contact.person.owner.disconnected_by(contact.user.person)
|
contact.person.owner.disconnected_by(contact.user.person)
|
||||||
else
|
else
|
||||||
contact.receiving = false
|
ContactRetraction.for(contact).defer_dispatch(self)
|
||||||
Retraction.for(contact).defer_dispatch(self)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
contact.aspect_memberships.delete_all
|
contact.aspect_memberships.delete_all
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ module Workers
|
||||||
class DeferredRetraction < Base
|
class DeferredRetraction < Base
|
||||||
sidekiq_options queue: :high
|
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)
|
user = User.find(user_id)
|
||||||
subscribers = Person.where(id: recipient_ids)
|
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)
|
opts = HashWithIndifferentAccess.new(opts)
|
||||||
|
|
||||||
Diaspora::Federation::Dispatcher.build(user, object, opts).dispatch
|
Diaspora::Federation::Dispatcher.build(user, object, opts).dispatch
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,6 @@ module Diaspora
|
||||||
module Federated
|
module Federated
|
||||||
require "diaspora/federated/base"
|
require "diaspora/federated/base"
|
||||||
require "diaspora/federated/retraction"
|
require "diaspora/federated/retraction"
|
||||||
|
require "diaspora/federated/contact_retraction"
|
||||||
end
|
end
|
||||||
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
|
@target = target
|
||||||
end
|
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)
|
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)
|
new(federation_retraction_data, target.subscribers.select(&:remote?), target)
|
||||||
end
|
end
|
||||||
|
|
||||||
def defer_dispatch(user, include_target_author=true)
|
def defer_dispatch(user, include_target_author=true)
|
||||||
subscribers = dispatch_subscribers(include_target_author)
|
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
|
end
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
|
|
@ -31,7 +44,7 @@ class Retraction
|
||||||
end
|
end
|
||||||
|
|
||||||
def public?
|
def public?
|
||||||
data[:target] && data[:target][:public]
|
data[:target][:public]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
|
|
@ -178,26 +178,7 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.retraction(retraction)
|
def self.retraction(retraction)
|
||||||
case retraction.data[:target_type]
|
retraction.class.entity_class.new(retraction.data)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.status_message(status_message)
|
def self.status_message(status_message)
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ module Diaspora
|
||||||
Profile => :profile,
|
Profile => :profile,
|
||||||
Reshare => :reshare,
|
Reshare => :reshare,
|
||||||
Retraction => :retraction,
|
Retraction => :retraction,
|
||||||
|
ContactRetraction => :retraction,
|
||||||
StatusMessage => :status_message
|
StatusMessage => :status_message
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue