fix: Process Accept activities

This commit is contained in:
Ro 2024-10-11 01:17:08 +00:00
parent 54bc877f0a
commit caf6e0b166
3 changed files with 16 additions and 7 deletions

View file

@ -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]

View file

@ -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}

View file

@ -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")