handle already following more gracefully
This commit is contained in:
parent
d7ad3da610
commit
7bc76058a6
|
@ -1,14 +1,9 @@
|
|||
defmodule Vonbraun.Control do
|
||||
require Logger
|
||||
alias Vonbraun.ActivityPub.Object
|
||||
alias Vonbraun.ActivityPubReq
|
||||
alias Vonbraun.Ecto.Schema.Actor
|
||||
|
||||
defp self_id() do
|
||||
domain = Application.fetch_env!(:vonbraun, :domain)
|
||||
nickname = Application.fetch_env!(:vonbraun, :nickname)
|
||||
"https://#{domain}/users/#{nickname}"
|
||||
end
|
||||
|
||||
@spec follow(String.t()) ::
|
||||
:ok
|
||||
| {:error,
|
||||
|
@ -23,25 +18,7 @@ defmodule Vonbraun.Control do
|
|||
{:parse_inbox, inbox = %URI{}} <- {:parse_inbox, URI.parse(raw_inbox)},
|
||||
{:pending, {:ok, %{:blocks_me => nil, :following_state => "pending"}}} <-
|
||||
{:pending, Actor.mark_pending_follow(followee_actor_id, "pending")} do
|
||||
domain = Application.fetch_env!(:vonbraun, :domain)
|
||||
# Is it a bad idea making this absolute?
|
||||
activity_id = "https://#{domain}/id/follow:#{URI.encode(followee_actor_id)}"
|
||||
|
||||
payload =
|
||||
%{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => activity_id,
|
||||
"to" => [
|
||||
followee_actor_id
|
||||
],
|
||||
"cc" => [],
|
||||
"bcc" => [],
|
||||
"bto" => [],
|
||||
"type" => "Follow",
|
||||
"actor" => self_id(),
|
||||
"object" => followee_actor_id
|
||||
}
|
||||
|> Jason.encode!()
|
||||
payload = Object.follow_activity(followee_actor_id) |> Jason.encode!()
|
||||
|
||||
case ActivityPubReq.post(inbox, payload) do
|
||||
{:ok, %{:status => status, :body => body}} when status >= 200 and status <= 299 ->
|
||||
|
|
Loading…
Reference in New Issue