Add sender
This commit is contained in:
parent
20a3ed9e71
commit
fa350aa551
5 changed files with 85 additions and 25 deletions
|
@ -1,9 +1,10 @@
|
|||
defmodule NullaWeb.InboxController do
|
||||
use NullaWeb, :controller
|
||||
alias Nulla.ActivityPub
|
||||
alias Nulla.Snowflake
|
||||
alias Nulla.HTTPSignature
|
||||
alias Nulla.Sender
|
||||
alias Nulla.Utils
|
||||
alias Nulla.Models.User
|
||||
alias Nulla.Models.Actor
|
||||
alias Nulla.Models.Relation
|
||||
alias Nulla.Models.Activity
|
||||
|
@ -109,24 +110,15 @@ defmodule NullaWeb.InboxController do
|
|||
}),
|
||||
{:ok, _relation} <-
|
||||
Relation.get_or_create_relation(local_actor.id, remote_actor.id, followed_by: true) do
|
||||
activity = %Activity{accept_activity | object: Jason.decode!(accept_activity.object)}
|
||||
body = Jason.encode!(ActivityPub.activity(activity))
|
||||
headers = HTTPSignature.make_headers(body, remote_actor_json["inbox"], local_actor)
|
||||
request = Finch.build(:post, remote_actor_json["inbox"], headers, body)
|
||||
user = User.get_user(id: local_actor.id)
|
||||
|
||||
case Finch.request(request, Nulla.Finch) do
|
||||
{:ok, %Finch.Response{status: code}} when code in 200..299 ->
|
||||
IO.puts("Accept delivered successfully")
|
||||
:ok
|
||||
|
||||
{:ok, %Finch.Response{status: code, body: resp}} ->
|
||||
IO.inspect({:error, code, resp}, label: "Failed to deliver Accept")
|
||||
{:error, {:http_error, code}}
|
||||
|
||||
{:error, reason} ->
|
||||
IO.inspect(reason, label: "Finch delivery failed")
|
||||
{:error, reason}
|
||||
end
|
||||
Sender.send_activity(
|
||||
:post,
|
||||
remote_actor.inbox,
|
||||
accept_activity,
|
||||
local_actor.publicKey["id"],
|
||||
user.privateKeyPem
|
||||
)
|
||||
|
||||
send_resp(conn, 200, "")
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue