mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 10:26:22 +00:00
feat: aprobar o rechazar en segundo plano
This commit is contained in:
parent
769eae6157
commit
a65a9f2f50
2 changed files with 26 additions and 13 deletions
16
app/jobs/activity_pub/inbox_job.rb
Normal file
16
app/jobs/activity_pub/inbox_job.rb
Normal 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
|
|
@ -47,9 +47,9 @@ class ActivityPub < ApplicationRecord
|
||||||
# Todavía no hay una decisión sobre el objeto
|
# Todavía no hay una decisión sobre el objeto
|
||||||
state :paused, initial: true
|
state :paused, initial: true
|
||||||
# Le usuarie aprobó el objeto
|
# Le usuarie aprobó el objeto
|
||||||
state :approved, before_enter: :allow_remotely!
|
state :approved
|
||||||
# Le usuarie rechazó el objeto
|
# Le usuarie rechazó el objeto
|
||||||
state :rejected, before_enter: :reject_remotely!
|
state :rejected
|
||||||
# Le usuarie reportó el objeto
|
# Le usuarie reportó el objeto
|
||||||
state :reported
|
state :reported
|
||||||
# Le actore eliminó el objeto
|
# Le actore eliminó el objeto
|
||||||
|
@ -84,11 +84,19 @@ class ActivityPub < ApplicationRecord
|
||||||
# webhook a modo de confirmación.
|
# webhook a modo de confirmación.
|
||||||
event :approve do
|
event :approve do
|
||||||
transitions from: %i[paused], to: :approved
|
transitions from: %i[paused], to: :approved
|
||||||
|
|
||||||
|
after do
|
||||||
|
ActivityPub::InboxJob.perform_later(site: site, activity: activities.first.uri, action: :accept)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# La actividad fue rechazada
|
# La actividad fue rechazada
|
||||||
event :reject do
|
event :reject do
|
||||||
transitions from: %i[paused], to: :rejected
|
transitions from: %i[paused], to: :rejected
|
||||||
|
|
||||||
|
after do
|
||||||
|
ActivityPub::InboxJob.perform_later(site: site, activity: activities.first.uri, action: :reject)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Solo podemos reportarla luego de rechazarla
|
# Solo podemos reportarla luego de rechazarla
|
||||||
|
@ -103,15 +111,4 @@ class ActivityPub < ApplicationRecord
|
||||||
|
|
||||||
# Definir eventos en masa
|
# Definir eventos en masa
|
||||||
include AasmEventsConcern
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue