2024-02-20 17:44:52 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# = Actor =
|
|
|
|
#
|
|
|
|
# Actor es la entidad que realiza acciones en ActivityPub
|
|
|
|
#
|
|
|
|
# @todo Obtener el perfil dinámicamente
|
2024-02-21 15:46:38 +00:00
|
|
|
class ActivityPub
|
|
|
|
class Actor < ApplicationRecord
|
|
|
|
include ActivityPub::Concerns::JsonLdConcern
|
2024-02-20 17:44:52 +00:00
|
|
|
|
2024-02-21 15:46:38 +00:00
|
|
|
belongs_to :instance
|
2024-02-28 20:34:34 +00:00
|
|
|
has_many :actor_moderation
|
2024-02-21 15:46:38 +00:00
|
|
|
has_many :activity_pubs, as: :object
|
2024-02-24 16:04:52 +00:00
|
|
|
has_many :activities
|
2024-03-01 18:04:07 +00:00
|
|
|
has_many :remote_flags
|
2024-02-28 20:58:00 +00:00
|
|
|
|
2024-03-06 20:15:21 +00:00
|
|
|
# Les actores son únicxs a toda la base de datos
|
2024-03-06 20:45:21 +00:00
|
|
|
validates :uri, presence: true, url: true, uniqueness: true
|
2024-03-06 20:15:21 +00:00
|
|
|
|
2024-03-16 20:53:29 +00:00
|
|
|
before_save :mentionize!
|
|
|
|
|
2024-02-28 20:58:00 +00:00
|
|
|
# Obtiene el nombre de la Actor como mención, solo si obtuvimos el
|
|
|
|
# contenido de antemano.
|
|
|
|
#
|
|
|
|
# @return [String, nil]
|
2024-03-16 20:53:29 +00:00
|
|
|
def mentionize!
|
|
|
|
return if mention.present?
|
2024-02-28 20:58:00 +00:00
|
|
|
return if content['preferredUsername'].blank?
|
|
|
|
return if instance.blank?
|
|
|
|
|
2024-03-16 20:53:29 +00:00
|
|
|
self.mention ||= "@#{content['preferredUsername']}@#{instance.hostname}"
|
2024-02-28 20:58:00 +00:00
|
|
|
end
|
2024-03-06 18:54:47 +00:00
|
|
|
|
|
|
|
def object
|
2024-03-19 15:39:41 +00:00
|
|
|
@object ||= ActivityPub::Object.lock.find_or_create_by(uri: uri)
|
2024-03-06 18:54:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def content
|
|
|
|
object.content
|
|
|
|
end
|
2024-02-21 15:46:38 +00:00
|
|
|
end
|
2024-02-20 17:44:52 +00:00
|
|
|
end
|