# frozen_string_literal: true # Mantiene la relaciĆ³n entre Site y Actor class ActorModeration < ApplicationRecord include AASM belongs_to :site belongs_to :actor, class_name: 'ActivityPub::Actor' 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 event :reported do transitions from: %i[blocked], to: :reported end end def pause_remotely! raise AASM::InvalidTransition 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 AASM::InvalidTransition 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 AASM::InvalidTransition unless actor.mention && site.social_inbox.allowlist.delete(list: [actor.mention]).ok? && site.social_inbox.blocklist.post(list: [actor.mention]).ok? end end