2024-02-16 17:54:50 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'distributed_press/v1/social/client'
|
2024-02-16 19:01:17 +00:00
|
|
|
require 'distributed_press/v1/social/hook'
|
2024-02-16 17:54:50 +00:00
|
|
|
|
|
|
|
# Gestiona la Social Inbox de un sitio
|
|
|
|
class SocialInbox
|
|
|
|
# @return [Site]
|
|
|
|
attr_reader :site
|
|
|
|
|
|
|
|
# @param :site [Site]
|
|
|
|
def initialize(site:)
|
|
|
|
@site = site
|
|
|
|
end
|
|
|
|
|
|
|
|
# @return [String]
|
|
|
|
def actor
|
|
|
|
@actor ||=
|
|
|
|
begin
|
|
|
|
user = site.config.dig('activity_pub', 'username')
|
|
|
|
user ||= hostname.split('.', 2).first
|
|
|
|
|
|
|
|
"@#{user}@#{hostname}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# @return [DistributedPress::V1::Social::Client]
|
|
|
|
def client
|
|
|
|
@client ||= DistributedPress::V1::Social::Client.new(
|
|
|
|
url: site.config.dig('activity_pub', 'url'),
|
|
|
|
public_key_url: public_key_url,
|
|
|
|
private_key_pem: site.private_key_pem,
|
|
|
|
logger: Rails.logger,
|
|
|
|
cache_store: :redis
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2024-02-16 19:01:17 +00:00
|
|
|
# @return [DistributedPress::V1::Social::Hook]
|
|
|
|
def hook
|
|
|
|
@hook ||= DistributedPress::V1::Social::Hook.new(client: client, actor: actor)
|
|
|
|
end
|
|
|
|
|
2024-02-16 17:54:50 +00:00
|
|
|
# @return [String]
|
|
|
|
def public_key_url
|
|
|
|
@public_key_url ||= URI("https://#{hostname}").tap do |uri|
|
|
|
|
uri.path = '/about.jsonld'
|
|
|
|
uri.fragment = 'main-key'
|
|
|
|
end.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def hostname
|
|
|
|
@hostname ||=
|
|
|
|
begin
|
|
|
|
host = site.config.dig('activity_pub', 'hostname')
|
|
|
|
host ||= site.hostname
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|