f489ed837b812e6346a3605c6e4523ca75b2074d
[akkoma] / lib / pleroma / web / federator / federator.ex
1 defmodule Pleroma.Web.Federator do
2 alias Pleroma.User
3 require Logger
4
5 @websub_verifier Application.get_env(:pleroma, :websub_verifier)
6
7 def handle(:publish, activity) do
8 Logger.debug("Running publish for #{activity.data["id"]}")
9 with actor when not is_nil(actor) <- User.get_cached_by_ap_id(activity.data["actor"]) do
10 Pleroma.Web.Websub.publish(Pleroma.Web.OStatus.feed_path(actor), actor, activity)
11 end
12 end
13
14 def handle(:verify_websub, websub) do
15 Logger.debug("Running websub verification for #{websub.id} (#{websub.topic}, #{websub.callback})")
16 @websub_verifier.verify(websub)
17 end
18
19 def handle(type, payload) do
20 Logger.debug("Unknown task: #{type}")
21 {:error, "Don't know what do do with this"}
22 end
23
24 def enqueue(type, payload) do
25 # for now, just run immediately in a new process.
26 if Mix.env == :test do
27 handle(type, payload)
28 else
29 spawn(fn -> handle(type, payload) end)
30 end
31 end
32 end