# frozen_string_literal: true # Mantiene la relaciĆ³n entre Site y Actor class ActorModeration < ApplicationRecord include AASM include AasmEventsConcern IGNORED_EVENTS = [] IGNORED_STATES = [] belongs_to :site belongs_to :remote_flag, optional: true, class_name: 'ActivityPub::RemoteFlag' belongs_to :actor, class_name: 'ActivityPub::Actor' accepts_nested_attributes_for :remote_flag # Bloquea todes les Actores bloqueables def self.block_all! self.update_all(aasm_state: 'blocked', updated_at: Time.now) end def self.pause_all! self.update_all(aasm_state: 'paused', updated_at: Time.now) end aasm do state :paused, initial: true state :allowed state :blocked state :reported event :pause do transitions from: %i[allowed blocked reported], to: :paused before do pause_remotely! end end event :allow do transitions from: %i[paused blocked reported], to: :allowed before do allow_remotely! end end event :block do transitions from: %i[paused allowed], to: :blocked before do block_remotely! end end # Al reportar, necesitamos asociar una RemoteFlag para poder # enviarla. event :report do transitions from: %i[blocked], to: :reported before do ActivityPub::RemoteFlagJob.perform_later(remote_flag: remote_flag) if remote_flag.waiting? end end end def pause_remotely! raise unless actor.mention && site.social_inbox.allowlist.delete(list: [actor.mention]).ok? && site.social_inbox.blocklist.delete(list: [actor.mention]).ok? end def allow_remotely! raise unless actor.mention && site.social_inbox.allowlist.post(list: [actor.mention]).ok? && site.social_inbox.blocklist.delete(list: [actor.mention]).ok? end def block_remotely! raise unless actor.mention && site.social_inbox.allowlist.delete(list: [actor.mention]).ok? && site.social_inbox.blocklist.post(list: [actor.mention]).ok? end end