Refactor, add beginnings of websub client subscriptions.
This commit is contained in:
parent
57bd59e407
commit
c5fa682c31
6 changed files with 93 additions and 7 deletions
32
lib/pleroma/web/federator/federator.ex
Normal file
32
lib/pleroma/web/federator/federator.ex
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
defmodule Pleroma.Web.Federator do
|
||||
alias Pleroma.User
|
||||
require Logger
|
||||
|
||||
@websub_verifier Application.get_env(:pleroma, :websub_verifier)
|
||||
|
||||
def handle(:publish, activity) do
|
||||
Logger.debug("Running publish for #{activity.data["id"]}")
|
||||
with actor when not is_nil(actor) <- User.get_cached_by_ap_id(activity.data["actor"]) do
|
||||
Pleroma.Web.Websub.publish(Pleroma.Web.OStatus.feed_path(actor), actor, activity)
|
||||
end
|
||||
end
|
||||
|
||||
def handle(:verify_websub, websub) do
|
||||
Logger.debug("Running websub verification for #{websub.id} (#{websub.topic}, #{websub.callback})")
|
||||
@websub_verifier.verify(websub)
|
||||
end
|
||||
|
||||
def handle(type, payload) do
|
||||
Logger.debug("Unknown task: #{type}")
|
||||
{:error, "Don't know what do do with this"}
|
||||
end
|
||||
|
||||
def enqueue(type, payload) do
|
||||
# for now, just run immediately in a new process.
|
||||
if Mix.env == :test do
|
||||
handle(type, payload)
|
||||
else
|
||||
spawn(fn -> handle(type, payload) end)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue