Fix
This commit is contained in:
parent
2729f0e25d
commit
198f8e7e83
4 changed files with 18 additions and 23 deletions
|
@ -77,8 +77,6 @@ defmodule Nulla.Actors.Actor do
|
||||||
:followers,
|
:followers,
|
||||||
:inbox,
|
:inbox,
|
||||||
:outbox,
|
:outbox,
|
||||||
:featured,
|
|
||||||
:featuredTags,
|
|
||||||
:preferredUsername,
|
:preferredUsername,
|
||||||
:url,
|
:url,
|
||||||
:publicKey,
|
:publicKey,
|
||||||
|
|
|
@ -45,22 +45,7 @@ defmodule Nulla.Relations.Relation do
|
||||||
:remote_actor_id
|
:remote_actor_id
|
||||||
])
|
])
|
||||||
|> maybe_put_id()
|
|> maybe_put_id()
|
||||||
|> validate_required([
|
|> validate_required([:local_actor_id, :remote_actor_id])
|
||||||
:following,
|
|
||||||
:followed_by,
|
|
||||||
:showing_replies,
|
|
||||||
:showings_reblogs,
|
|
||||||
:notifying,
|
|
||||||
:muting,
|
|
||||||
:muting_notifications,
|
|
||||||
:blocking,
|
|
||||||
:blocked_by,
|
|
||||||
:domain_blocking,
|
|
||||||
:requested,
|
|
||||||
:note,
|
|
||||||
:local_actor_id,
|
|
||||||
:remote_actor_id
|
|
||||||
])
|
|
||||||
|> unique_constraint([:local_actor_id, :remote_actor_id])
|
|> unique_constraint([:local_actor_id, :remote_actor_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -91,10 +91,20 @@ defmodule NullaWeb.ActivityPub.InboxController do
|
||||||
with local_actor <- Actors.get_actor_by(ap_id: target_uri),
|
with local_actor <- Actors.get_actor_by(ap_id: target_uri),
|
||||||
{:ok, remote_actor_json} <- Utils.fetch_remote_actor(actor_uri),
|
{:ok, remote_actor_json} <- Utils.fetch_remote_actor(actor_uri),
|
||||||
:ok <- HTTPSignature.verify(conn, remote_actor_json["publicKey"]["publicKeyPem"]) do
|
:ok <- HTTPSignature.verify(conn, remote_actor_json["publicKey"]["publicKeyPem"]) do
|
||||||
|
ap_id = remote_actor_json["id"]
|
||||||
|
username = remote_actor_json["preferredUsername"]
|
||||||
|
domain = URI.parse(remote_actor_json["id"]).host
|
||||||
|
|
||||||
remote_actor =
|
remote_actor =
|
||||||
case Actors.get_actor_by(ap_id: remote_actor_json["id"]) do
|
case Actors.get_actor_by(ap_id: ap_id) do
|
||||||
nil ->
|
nil ->
|
||||||
case Actors.create_actor(remote_actor_json) do
|
params =
|
||||||
|
remote_actor_json
|
||||||
|
|> Map.put("ap_id", ap_id)
|
||||||
|
|> Map.delete("id")
|
||||||
|
|> Map.put("acct", "#{username}@#{domain}")
|
||||||
|
|
||||||
|
case Actors.create_actor(params) do
|
||||||
{:ok, actor} -> actor
|
{:ok, actor} -> actor
|
||||||
{:error, error} -> {:error, error}
|
{:error, error} -> {:error, error}
|
||||||
end
|
end
|
||||||
|
@ -103,6 +113,8 @@ defmodule NullaWeb.ActivityPub.InboxController do
|
||||||
actor
|
actor
|
||||||
end
|
end
|
||||||
|
|
||||||
|
domain = NullaWeb.Endpoint.host()
|
||||||
|
|
||||||
with {:ok, follow_activity} <-
|
with {:ok, follow_activity} <-
|
||||||
Activities.create_activity(%{
|
Activities.create_activity(%{
|
||||||
ap_id: follow_id,
|
ap_id: follow_id,
|
||||||
|
@ -113,7 +125,7 @@ defmodule NullaWeb.ActivityPub.InboxController do
|
||||||
{:ok, accept_activity} <-
|
{:ok, accept_activity} <-
|
||||||
Activities.create_activity(%{
|
Activities.create_activity(%{
|
||||||
id: accept_id,
|
id: accept_id,
|
||||||
ap_id: "https://#{local_actor.domain}/activities/accept/#{accept_id}",
|
ap_id: "https://#{domain}/activities/accept/#{accept_id}",
|
||||||
type: "Accept",
|
type: "Accept",
|
||||||
actor: local_actor.ap_id,
|
actor: local_actor.ap_id,
|
||||||
object: Jason.encode!(follow_activity)
|
object: Jason.encode!(follow_activity)
|
||||||
|
@ -134,7 +146,7 @@ defmodule NullaWeb.ActivityPub.InboxController do
|
||||||
end
|
end
|
||||||
|
|
||||||
relation ->
|
relation ->
|
||||||
Relations.update_relation(relation, %{followed_by: true})
|
{:ok, Relations.update_relation(relation, %{followed_by: true})}
|
||||||
end
|
end
|
||||||
|
|
||||||
Sender.send_activity(
|
Sender.send_activity(
|
||||||
|
|
|
@ -15,7 +15,7 @@ defmodule Nulla.Repo.Migrations.CreateActors do
|
||||||
add :featuredTags, :string
|
add :featuredTags, :string
|
||||||
add :preferredUsername, :string
|
add :preferredUsername, :string
|
||||||
add :name, :string
|
add :name, :string
|
||||||
add :summary, :string
|
add :summary, :text
|
||||||
add :url, :string
|
add :url, :string
|
||||||
add :manuallyApprovesFollowers, :boolean, default: false, null: false
|
add :manuallyApprovesFollowers, :boolean, default: false, null: false
|
||||||
add :discoverable, :boolean, default: true, null: false
|
add :discoverable, :boolean, default: true, null: false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue