2017-04-26 16:33:10 +00:00
|
|
|
defmodule Pleroma.Web.Federator do
|
|
|
|
alias Pleroma.User
|
2017-05-01 12:07:29 +00:00
|
|
|
alias Pleroma.Web.WebFinger
|
2017-04-26 16:33:10 +00:00
|
|
|
require Logger
|
|
|
|
|
2017-04-28 13:45:10 +00:00
|
|
|
@websub Application.get_env(:pleroma, :websub)
|
2017-04-26 16:33:10 +00:00
|
|
|
|
|
|
|
def handle(:publish, activity) do
|
2017-05-05 10:07:38 +00:00
|
|
|
Logger.debug(fn -> "Running publish for #{activity.data["id"]}" end)
|
2017-04-26 16:33:10 +00:00
|
|
|
with actor when not is_nil(actor) <- User.get_cached_by_ap_id(activity.data["actor"]) do
|
2017-05-05 10:07:38 +00:00
|
|
|
Logger.debug(fn -> "Sending #{activity.data["id"]} out via websub" end)
|
2017-04-26 16:33:10 +00:00
|
|
|
Pleroma.Web.Websub.publish(Pleroma.Web.OStatus.feed_path(actor), actor, activity)
|
2017-05-01 11:14:58 +00:00
|
|
|
|
2017-05-01 12:07:29 +00:00
|
|
|
{:ok, actor} = WebFinger.ensure_keys_present(actor)
|
2017-05-05 10:07:38 +00:00
|
|
|
Logger.debug(fn -> "Sending #{activity.data["id"]} out via salmon" end)
|
2017-05-01 11:14:58 +00:00
|
|
|
Pleroma.Web.Salmon.publish(actor, activity)
|
2017-04-26 16:33:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def handle(:verify_websub, websub) do
|
2017-05-05 10:07:38 +00:00
|
|
|
Logger.debug(fn -> "Running websub verification for #{websub.id} (#{websub.topic}, #{websub.callback})" end)
|
2017-04-28 13:45:10 +00:00
|
|
|
@websub.verify(websub)
|
2017-04-26 16:33:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def handle(type, payload) do
|
2017-05-05 10:07:38 +00:00
|
|
|
Logger.debug(fn -> "Unknown task: #{type}" end)
|
2017-04-26 16:33:10 +00:00
|
|
|
{: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
|