5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 08:56:22 +00:00

feat: aprobar o rechazar en segundo plano

This commit is contained in:
f 2024-03-16 19:16:30 -03:00
parent 769eae6157
commit a65a9f2f50
No known key found for this signature in database
2 changed files with 26 additions and 13 deletions

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
class ActivityPub
class InboxJob < ApplicationJob
self.priority = 10
# @param :site [Site]
# @param :activity [String]
# @param :action [Symbol]
def perform(site:, activity:, action:)
response = site.social_inbox.inbox.public_send(action, id: activity)
raise response.body unless response.ok?
end
end
end

View file

@ -47,9 +47,9 @@ class ActivityPub < ApplicationRecord
# Todavía no hay una decisión sobre el objeto
state :paused, initial: true
# Le usuarie aprobó el objeto
state :approved, before_enter: :allow_remotely!
state :approved
# Le usuarie rechazó el objeto
state :rejected, before_enter: :reject_remotely!
state :rejected
# Le usuarie reportó el objeto
state :reported
# Le actore eliminó el objeto
@ -84,11 +84,19 @@ class ActivityPub < ApplicationRecord
# webhook a modo de confirmación.
event :approve do
transitions from: %i[paused], to: :approved
after do
ActivityPub::InboxJob.perform_later(site: site, activity: activities.first.uri, action: :accept)
end
end
# La actividad fue rechazada
event :reject do
transitions from: %i[paused], to: :rejected
after do
ActivityPub::InboxJob.perform_later(site: site, activity: activities.first.uri, action: :reject)
end
end
# Solo podemos reportarla luego de rechazarla
@ -103,15 +111,4 @@ class ActivityPub < ApplicationRecord
# Definir eventos en masa
include AasmEventsConcern
# Lo que tenemos que aprobar o rechazar es la última actividad
# disponible, que según el scope por defecto, va a ser la primera de
# la lista.
def reject_remotely!
raise unless site.social_inbox.inbox.reject(id: activities.first.uri).ok?
end
def allow_remotely!
raise unless site.social_inbox.inbox.accept(id: activities.first.uri).ok?
end
end