2023-08-29 20:43:19 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-02-16 17:54:50 +00:00
|
|
|
require 'distributed_press/v1/social/client'
|
|
|
|
|
2023-08-29 20:43:19 +00:00
|
|
|
class Site
|
|
|
|
# Agrega soporte para Social Distributed Press en los sitios
|
|
|
|
module SocialDistributedPress
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2024-02-23 15:53:56 +00:00
|
|
|
has_encrypted :private_key_pem
|
2023-08-29 20:49:25 +00:00
|
|
|
|
2024-02-20 20:15:43 +00:00
|
|
|
has_many :activity_pubs
|
2024-02-26 15:27:56 +00:00
|
|
|
has_many :instance_moderations
|
2024-02-28 20:34:34 +00:00
|
|
|
has_many :actor_moderations
|
2024-02-27 16:43:46 +00:00
|
|
|
has_many :fediblock_states
|
2024-02-27 19:39:02 +00:00
|
|
|
has_many :instances, through: :instance_moderations
|
2024-03-01 18:04:07 +00:00
|
|
|
has_many :remote_flags, class_name: 'ActivityPub::RemoteFlag'
|
2024-02-20 20:15:43 +00:00
|
|
|
|
2023-08-29 20:49:25 +00:00
|
|
|
before_save :generate_private_key_pem!, unless: :private_key_pem?
|
|
|
|
|
2024-03-21 21:12:12 +00:00
|
|
|
def moderation_enabled?
|
|
|
|
deploy_social_inbox.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def deploy_social_inbox
|
|
|
|
@deploy_social_inbox ||= deploys.find_by(type: 'DeploySocialDistributedPress')
|
|
|
|
end
|
|
|
|
|
|
|
|
def moderation_checked!
|
|
|
|
deploy_social_inbox.touch
|
|
|
|
end
|
|
|
|
|
|
|
|
# @return [Bool]
|
|
|
|
def moderation_needed?
|
|
|
|
return false unless moderation_enabled?
|
|
|
|
|
|
|
|
last_activity_pub = activity_pubs.order(updated_at: :desc).first&.updated_at
|
|
|
|
|
|
|
|
return false if last_activity_pub.blank?
|
|
|
|
|
|
|
|
last_activity_pub > deploy_social_inbox.updated_at
|
|
|
|
end
|
|
|
|
|
2024-02-16 17:54:50 +00:00
|
|
|
# @return [SocialInbox]
|
|
|
|
def social_inbox
|
|
|
|
@social_inbox ||= SocialInbox.new(site: self)
|
|
|
|
end
|
|
|
|
|
2024-03-01 18:04:07 +00:00
|
|
|
# Obtiene el hostname de la API de Sutty
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
def social_inbox_hostname
|
|
|
|
Rails.application.routes.default_url_options[:host].sub('panel', 'api')
|
|
|
|
end
|
|
|
|
|
2023-08-29 20:49:25 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
# Genera la llave privada y la almacena
|
|
|
|
#
|
|
|
|
# @return [nil]
|
|
|
|
def generate_private_key_pem!
|
2024-02-16 17:54:50 +00:00
|
|
|
self.private_key_pem ||= DistributedPress::V1::Social::Client.new(
|
|
|
|
public_key_url: nil,
|
2024-02-17 17:11:17 +00:00
|
|
|
key_size: 2048
|
|
|
|
).private_key.export
|
2023-08-29 20:49:25 +00:00
|
|
|
end
|
2023-08-29 20:43:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|