# frozen_string_literal: true # Mantiene la relación entre Site y Actor class ActorModeration < ApplicationRecord IGNORED_EVENTS = %i[remove] IGNORED_STATES = %i[removed] include AASM include AasmEventsConcern 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 aasm do state :paused, initial: true state :allowed state :blocked state :reported state :removed event :pause do transitions from: %i[allowed blocked reported], to: :paused before do pause_remotely! end end # Al permitir una cuenta se permiten todos los comentarios # pendientes de moderación que ya hizo. event :allow do transitions from: %i[paused blocked reported], to: :allowed before do allow_remotely! site.activity_pubs.paused.where(actor_id: self.actor_id).approve_all! end end # Al bloquear una cuenta se bloquean todos los comentarios # pendientes de moderación que hizo. event :block do transitions from: %i[paused allowed], to: :blocked before do block_remotely! site.activity_pubs.paused.where(actor_id: self.actor_id).reject_all! 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 # Si un perfil es eliminado remotamente, tenemos que dejar de # mostrarlo y todas sus actividades. event :remove do transitions to: :removed before do site.activity_pubs.where(actor_id: self.actor_id).remove_all! 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