mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 05:36:21 +00:00
feat: enviar una sola vez el reporte remoto y volver a enviarlo si le agregamos reportes
This commit is contained in:
parent
30fd6c28ee
commit
5b53a9813f
7 changed files with 43 additions and 4 deletions
|
@ -35,6 +35,8 @@ class ActivityPubsController < ApplicationController
|
||||||
activity_pubs.distinct.pluck(:actor_id).each do |actor_id|
|
activity_pubs.distinct.pluck(:actor_id).each do |actor_id|
|
||||||
remote_flag = ActivityPub::RemoteFlag.find_or_initialize_by(actor_id: actor_id, site_id: site.id)
|
remote_flag = ActivityPub::RemoteFlag.find_or_initialize_by(actor_id: actor_id, site_id: site.id)
|
||||||
remote_flag.message = message
|
remote_flag.message = message
|
||||||
|
# Lo estamos actualizando, con lo que lo vamos a volver a enviar
|
||||||
|
remote_flag.requeue if remote_flag.persisted?
|
||||||
remote_flag.save
|
remote_flag.save
|
||||||
# XXX: Idealmente todas las ActivityPub que enviamos pueden
|
# XXX: Idealmente todas las ActivityPub que enviamos pueden
|
||||||
# cambiar de estado, pero chequeamos de todas formas.
|
# cambiar de estado, pero chequeamos de todas formas.
|
||||||
|
|
|
@ -13,10 +13,16 @@ class ActivityPub
|
||||||
self.priority = 30
|
self.priority = 30
|
||||||
|
|
||||||
def perform(remote_flag:)
|
def perform(remote_flag:)
|
||||||
|
return if remote_flag.can_queue?
|
||||||
|
|
||||||
|
remote_flag.queue!
|
||||||
|
|
||||||
client = remote_flag.site.social_inbox.client_for(remote_flag.actor&.content['inbox'])
|
client = remote_flag.site.social_inbox.client_for(remote_flag.actor&.content['inbox'])
|
||||||
response = client.post(endpoint: '', body: remote_flag.content)
|
response = client.post(endpoint: '', body: remote_flag.content)
|
||||||
|
|
||||||
raise 'No se pudo enviar el reporte' unless response.ok?
|
raise 'No se pudo enviar el reporte' unless response.ok?
|
||||||
|
|
||||||
|
remote_flag.send!
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
ExceptionNotifier.notify_exception(e, data: { remote_flag: remote_flag.id, response: response.parsed_response })
|
ExceptionNotifier.notify_exception(e, data: { remote_flag: remote_flag.id, response: response.parsed_response })
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -88,7 +88,7 @@ class ActivityPub < ApplicationRecord
|
||||||
transitions from: :rejected, to: :reported
|
transitions from: :rejected, to: :reported
|
||||||
|
|
||||||
before do
|
before do
|
||||||
ActivityPub::RemoteFlagJob.perform_later(remote_flag: remote_flag)
|
ActivityPub::RemoteFlagJob.perform_later(remote_flag: remote_flag) if remote_flag.waiting?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,27 @@
|
||||||
|
|
||||||
class ActivityPub
|
class ActivityPub
|
||||||
class RemoteFlag < ApplicationRecord
|
class RemoteFlag < ApplicationRecord
|
||||||
|
include AASM
|
||||||
|
include AasmEventsConcern
|
||||||
|
|
||||||
|
aasm do
|
||||||
|
state :waiting, initial: true
|
||||||
|
state :queued
|
||||||
|
state :sent
|
||||||
|
|
||||||
|
event :queue do
|
||||||
|
transitions from: :waiting, to: :queued
|
||||||
|
end
|
||||||
|
|
||||||
|
event :send do
|
||||||
|
transitions from: :queued, to: :sent
|
||||||
|
end
|
||||||
|
|
||||||
|
event :resend do
|
||||||
|
transitions from: :sent, to: :waiting
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
belongs_to :actor
|
belongs_to :actor
|
||||||
belongs_to :site
|
belongs_to :site
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ class ActorModeration < ApplicationRecord
|
||||||
transitions from: %i[blocked], to: :reported
|
transitions from: %i[blocked], to: :reported
|
||||||
|
|
||||||
before do
|
before do
|
||||||
ActivityPub::RemoteFlagJob.perform_later(remote_flag: remote_flag)
|
ActivityPub::RemoteFlagJob.perform_later(remote_flag: remote_flag) if remote_flag.waiting?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
8
db/migrate/20240305184854_add_state_to_remote_flags.rb
Normal file
8
db/migrate/20240305184854_add_state_to_remote_flags.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# Estado de los reportes remotos
|
||||||
|
class AddStateToRemoteFlags < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_column :activity_pub_remote_flags, :aasm_state, :string, null: false, default: 'waiting'
|
||||||
|
end
|
||||||
|
end
|
|
@ -556,7 +556,8 @@ CREATE TABLE public.activity_pub_remote_flags (
|
||||||
updated_at timestamp(6) without time zone NOT NULL,
|
updated_at timestamp(6) without time zone NOT NULL,
|
||||||
site_id bigint,
|
site_id bigint,
|
||||||
actor_id uuid,
|
actor_id uuid,
|
||||||
message text
|
message text,
|
||||||
|
aasm_state character varying DEFAULT 'waiting'::character varying NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -2697,6 +2698,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||||
('20240301181224'),
|
('20240301181224'),
|
||||||
('20240301194154'),
|
('20240301194154'),
|
||||||
('20240301202955'),
|
('20240301202955'),
|
||||||
('20240305164653');
|
('20240305164653'),
|
||||||
|
('20240305184854');
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue