# frozen_string_literal: true # Mantiene la relación entre Site y Actor class ActorModeration < ApplicationRecord IGNORED_EVENTS = %i[remove].freeze IGNORED_STATES = %i[removed].freeze include AASM 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, before_enter: :pause_remotely! state :allowed, before_enter: :allow_remotely! state :blocked, before_enter: :block_remotely! state :reported state :removed error_on_all_events do |e| ExceptionNotifier.notify_exception(e, data: { site: site.name, actor: actor.uri, actor_moderation: id }) end event :pause do transitions from: %i[allowed blocked reported], to: :paused end # Al permitir una cuenta no se permiten todos los comentarios # pendientes de moderación que ya hizo. event :allow do transitions from: %i[paused blocked reported], to: :allowed end # Al bloquear una cuenta no se bloquean todos los comentarios # pendientes de moderación que hizo. event :block do transitions from: %i[paused allowed], to: :blocked end # Al reportar, necesitamos asociar una RemoteFlag para poder # enviarla. event :report do transitions from: %i[blocked], to: :reported after 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 after do site.activity_pubs.where(actor_id: actor_id).remove_all! end end end # Definir eventos en masa include AasmEventsConcern 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