From 7bc76058a6c0d66b0912f4c54c8235ebc8adfc05 Mon Sep 17 00:00:00 2001 From: Moon Man Date: Thu, 29 Aug 2024 13:15:47 +0000 Subject: [PATCH] handle already following more gracefully --- lib/vonbraun/control.ex | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/lib/vonbraun/control.ex b/lib/vonbraun/control.ex index 8dbc543..c5e8b20 100644 --- a/lib/vonbraun/control.ex +++ b/lib/vonbraun/control.ex @@ -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 ->