2024-02-20 20:13:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
module Webhooks
|
|
|
|
# Recibe webhooks de la Social Inbox
|
|
|
|
#
|
|
|
|
# @see {https://www.w3.org/TR/activitypub/}
|
|
|
|
class SocialInboxController < BaseController
|
|
|
|
include Api::V1::Webhooks::Concerns::WebhookConcern
|
|
|
|
|
2024-03-16 17:15:32 +00:00
|
|
|
# Validar que el token sea correcto
|
|
|
|
before_action :usuarie
|
|
|
|
|
2024-02-20 20:13:42 +00:00
|
|
|
# Cuando una actividad ingresa en la cola de moderación, la
|
|
|
|
# recibimos por acá
|
|
|
|
#
|
2024-03-16 17:15:32 +00:00
|
|
|
# Vamos a recibir Create, Update, Delete, Follow, Undo,
|
|
|
|
# Announce, Like y obtener el objeto dentro de cada una para
|
|
|
|
# guardar un estado asociado al sitio.
|
2024-02-20 20:13:42 +00:00
|
|
|
#
|
|
|
|
# El objeto del estado puede ser un objeto o une actore,
|
|
|
|
# dependiendo de la actividad.
|
|
|
|
def moderationqueued
|
2024-03-16 17:15:32 +00:00
|
|
|
process! :paused
|
2024-02-28 20:52:24 +00:00
|
|
|
|
2024-02-20 20:13:42 +00:00
|
|
|
head :accepted
|
|
|
|
end
|
|
|
|
|
2024-02-22 21:42:20 +00:00
|
|
|
# Cuando la Social Inbox acepta una actividad, la recibimos
|
|
|
|
# igual y la guardamos por si cambiamos de idea.
|
2024-02-20 20:13:42 +00:00
|
|
|
def onapproved
|
2024-03-16 17:15:32 +00:00
|
|
|
process! :approved
|
2024-02-21 16:04:15 +00:00
|
|
|
|
2024-02-20 20:13:42 +00:00
|
|
|
head :accepted
|
|
|
|
end
|
|
|
|
|
2024-02-22 21:42:20 +00:00
|
|
|
# Cuando la Social Inbox rechaza una actividad, la recibimos
|
|
|
|
# igual y la guardamos por si cambiamos de idea.
|
2024-02-20 20:13:42 +00:00
|
|
|
def onrejected
|
2024-03-16 17:15:32 +00:00
|
|
|
process! :rejected
|
2024-02-21 16:06:06 +00:00
|
|
|
|
2024-02-20 20:13:42 +00:00
|
|
|
head :accepted
|
|
|
|
end
|
2024-02-20 20:15:43 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2024-03-16 17:15:32 +00:00
|
|
|
# Envía la actividad para procesamiento por separado.
|
2024-02-20 20:15:43 +00:00
|
|
|
#
|
2024-03-16 17:15:32 +00:00
|
|
|
# @param initial_state [Symbol]
|
|
|
|
def process!(initial_state)
|
|
|
|
::ActivityPub::ProcessJob.perform_later(site: site, body: request.raw_post, initial_state: initial_state)
|
2024-02-20 20:15:43 +00:00
|
|
|
end
|
2024-02-20 20:13:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|