5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 01:26:22 +00:00
panel/app/models/activity_pub/remote_flag.rb

61 lines
1.6 KiB
Ruby
Raw Normal View History

2024-03-01 18:51:54 +00:00
# frozen_string_literal: true
class ActivityPub
class RemoteFlag < ApplicationRecord
IGNORED_EVENTS = [].freeze
IGNORED_STATES = [].freeze
include AASM
aasm do
state :waiting, initial: true
state :queued
state :sent
event :queue do
transitions from: :waiting, to: :queued
end
2024-03-06 17:12:04 +00:00
event :report do
transitions from: :queued, to: :sent
end
event :resend do
transitions from: :sent, to: :waiting
end
end
2024-03-13 14:15:31 +00:00
# Definir eventos en masa
include AasmEventsConcern
2024-03-01 18:51:54 +00:00
belongs_to :actor
belongs_to :site
2024-03-05 17:18:06 +00:00
has_one :actor_moderation
has_many :activity_pubs
# XXX: source_type es obligatorio para el `through`
has_many :objects, through: :activity_pubs, source_type: 'ActivityPub::Object::Note'
2024-03-01 18:51:54 +00:00
# Genera la actividad a enviar
def content
{
'@context' => 'https://www.w3.org/ns/activitystreams',
2024-05-02 19:05:35 +00:00
'id' => Rails.application.routes.url_helpers.v1_activity_pub_remote_flag_url(self,
host: site.social_inbox_hostname),
2024-03-01 18:51:54 +00:00
'type' => 'Flag',
'actor' => main_site.social_inbox.actor_id,
2024-03-01 18:51:54 +00:00
'content' => message.to_s,
'object' => [actor.uri] + objects.pluck(:uri)
2024-03-01 18:51:54 +00:00
}
end
# Este es el sitio principal que actúa como origen del reporte.
# Tiene que tener la Social Inbox habilitada al mismo tiempo.
#
# @return [Site]
def main_site
2024-05-02 19:05:35 +00:00
@main_site ||= Site.find(ENV.fetch('PANEL_ACTOR_SITE_ID', 1))
end
2024-03-01 18:51:54 +00:00
end
end