diff --git a/fly.toml b/fly.toml index 78693f1..e0ca97f 100644 --- a/fly.toml +++ b/fly.toml @@ -21,9 +21,9 @@ kill_signal = 'SIGTERM' [http_service] internal_port = 8080 force_https = true - auto_stop_machines = 'stop' + auto_stop_machines = false auto_start_machines = true - min_machines_running = 0 + min_machines_running = 1 processes = ['app'] [http_service.concurrency] diff --git a/lib/postland/activities.ex b/lib/postland/activities.ex index 2f9d8bd..2929a79 100644 --- a/lib/postland/activities.ex +++ b/lib/postland/activities.ex @@ -23,11 +23,20 @@ defmodule Postland.Activities do |> Repo.insert() end - def cause_effects(%Activity{actor_id: actor_id, type: "Accept", data: %{"object" => %{"type" => "Follow"}}} = activity) do + def cause_effects(%Activity{type: "Accept", data: %{"object" => %{"type" => "Follow", "id" => follow_id}}} = activity) do + pattern = ~r|/follows/([^/]+)| + + actor_id = case Regex.run(pattern, follow_id) do + [_, encoded_actor_id] -> + dbg(encoded_actor_id) + Base.url_decode64!(encoded_actor_id, padding: false) + + _other -> + nil + end + case Follows.get(Postland.my_actor_id(), actor_id) do nil -> - # TODO: Need to handle the scenario where the we're following has an alias (/@foobar becomes /users/foobar by the time - # they Accept) Logger.warning("Got accept for a follow we don't have in the db: #{actor_id}") {:ok, activity} diff --git a/lib/postland/follows.ex b/lib/postland/follows.ex index a1ed31c..8daa6d4 100644 --- a/lib/postland/follows.ex +++ b/lib/postland/follows.ex @@ -20,8 +20,8 @@ defmodule Postland.Follows do end def send_follow_request(to_actor_id) do - encoded_followee = Base.url_encode64(to_actor_id) - encoded_follower = Base.url_encode64(Postland.my_actor_id()) + encoded_followee = Base.url_encode64(to_actor_id, padding: false) + encoded_follower = Base.url_encode64(Postland.my_actor_id(), padding: false) {:ok, actor} = ActivityPub.fetch_actor(to_actor_id) inbox = Map.get(actor, "inbox")