Some refactoring.
This commit is contained in:
parent
c48c381e90
commit
7269c51f3a
|
@ -6,24 +6,24 @@ defmodule Pleroma.Web.Federator do
|
||||||
@websub Application.get_env(:pleroma, :websub)
|
@websub Application.get_env(:pleroma, :websub)
|
||||||
|
|
||||||
def handle(:publish, activity) do
|
def handle(:publish, activity) do
|
||||||
Logger.debug("Running publish for #{activity.data["id"]}")
|
Logger.debug(fn -> "Running publish for #{activity.data["id"]}" end)
|
||||||
with actor when not is_nil(actor) <- User.get_cached_by_ap_id(activity.data["actor"]) do
|
with actor when not is_nil(actor) <- User.get_cached_by_ap_id(activity.data["actor"]) do
|
||||||
Logger.debug("Sending #{activity.data["id"]} out via websub")
|
Logger.debug(fn -> "Sending #{activity.data["id"]} out via websub" end)
|
||||||
Pleroma.Web.Websub.publish(Pleroma.Web.OStatus.feed_path(actor), actor, activity)
|
Pleroma.Web.Websub.publish(Pleroma.Web.OStatus.feed_path(actor), actor, activity)
|
||||||
|
|
||||||
{:ok, actor} = WebFinger.ensure_keys_present(actor)
|
{:ok, actor} = WebFinger.ensure_keys_present(actor)
|
||||||
Logger.debug("Sending #{activity.data["id"]} out via salmon")
|
Logger.debug(fn -> "Sending #{activity.data["id"]} out via salmon" end)
|
||||||
Pleroma.Web.Salmon.publish(actor, activity)
|
Pleroma.Web.Salmon.publish(actor, activity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle(:verify_websub, websub) do
|
def handle(:verify_websub, websub) do
|
||||||
Logger.debug("Running websub verification for #{websub.id} (#{websub.topic}, #{websub.callback})")
|
Logger.debug(fn -> "Running websub verification for #{websub.id} (#{websub.topic}, #{websub.callback})" end)
|
||||||
@websub.verify(websub)
|
@websub.verify(websub)
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle(type, payload) do
|
def handle(type, payload) do
|
||||||
Logger.debug("Unknown task: #{type}")
|
Logger.debug(fn -> "Unknown task: #{type}" end)
|
||||||
{:error, "Don't know what do do with this"}
|
{:error, "Don't know what do do with this"}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,7 @@ def gather_user_info(username) do
|
||||||
{:ok, feed_data} <- Websub.gather_feed_data(webfinger_data["topic"]) do
|
{:ok, feed_data} <- Websub.gather_feed_data(webfinger_data["topic"]) do
|
||||||
{:ok, Map.merge(webfinger_data, feed_data) |> Map.put("fqn", username)}
|
{:ok, Map.merge(webfinger_data, feed_data) |> Map.put("fqn", username)}
|
||||||
else e ->
|
else e ->
|
||||||
Logger.debug("Couldn't gather info for #{username}")
|
Logger.debug(fn -> "Couldn't gather info for #{username}" end)
|
||||||
{:error, e}
|
{:error, e}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,7 +48,8 @@ def object(conn, %{"uuid" => uuid}) do
|
||||||
activity = Activity.get_create_activity_by_object_ap_id(id)
|
activity = Activity.get_create_activity_by_object_ap_id(id)
|
||||||
user = User.get_cached_by_ap_id(activity.data["actor"])
|
user = User.get_cached_by_ap_id(activity.data["actor"])
|
||||||
|
|
||||||
response = ActivityRepresenter.to_simple_form(activity, user, true)
|
response = activity
|
||||||
|
|> ActivityRepresenter.to_simple_form(user, true)
|
||||||
|> ActivityRepresenter.wrap_with_entry
|
|> ActivityRepresenter.wrap_with_entry
|
||||||
|> :xmerl.export_simple(:xmerl_xml)
|
|> :xmerl.export_simple(:xmerl_xml)
|
||||||
|> to_string
|
|> to_string
|
||||||
|
|
|
@ -101,8 +101,13 @@ def encode(private_key, doc) do
|
||||||
|> Enum.map(&Base.url_encode64/1)
|
|> Enum.map(&Base.url_encode64/1)
|
||||||
|> Enum.join(".")
|
|> Enum.join(".")
|
||||||
|
|
||||||
signature = :public_key.sign(signed_text, :sha256, private_key) |> to_string |> Base.url_encode64
|
signature = signed_text
|
||||||
doc_base64= doc |> Base.url_encode64
|
|> :public_key.sign(:sha256, private_key)
|
||||||
|
|> to_string
|
||||||
|
|> Base.url_encode64
|
||||||
|
|
||||||
|
doc_base64 = doc
|
||||||
|
|> Base.url_encode64
|
||||||
|
|
||||||
# Don't need proper xml building, these strings are safe to leave unescaped
|
# Don't need proper xml building, these strings are safe to leave unescaped
|
||||||
salmon = """
|
salmon = """
|
||||||
|
@ -143,11 +148,11 @@ def publish(%{info: %{"keys" => keys}} = user, activity, poster) do
|
||||||
|
|
||||||
remote_users(activity)
|
remote_users(activity)
|
||||||
|> Enum.each(fn(remote_user) ->
|
|> Enum.each(fn(remote_user) ->
|
||||||
Logger.debug("sending salmon to #{remote_user.ap_id}")
|
Logger.debug(fn -> "sending salmon to #{remote_user.ap_id}" end)
|
||||||
send_to_user(remote_user, feed, poster)
|
send_to_user(remote_user, feed, poster)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish(%{id: id}, _, _), do: Logger.debug("Keys missing for user #{id}")
|
def publish(%{id: id}, _, _), do: Logger.debug(fn -> "Keys missing for user #{id}" end)
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,7 @@ def add_attachments(text, attachments) do
|
||||||
Enum.join([text | attachment_text], "<br>")
|
Enum.join([text | attachment_text], "<br>")
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_status(user = %User{}, data = %{"status" => status}) do
|
def create_status(%User{} = user, %{"status" => status} = data) do
|
||||||
attachments = attachments_from_ids(data["media_ids"])
|
attachments = attachments_from_ids(data["media_ids"])
|
||||||
context = ActivityPub.generate_context_id
|
context = ActivityPub.generate_context_id
|
||||||
mentions = parse_mentions(status)
|
mentions = parse_mentions(status)
|
||||||
|
@ -122,8 +122,7 @@ def fetch_conversation(user, id) do
|
||||||
statuses <- activities |> activities_to_statuses(%{for: user})
|
statuses <- activities |> activities_to_statuses(%{for: user})
|
||||||
do
|
do
|
||||||
statuses
|
statuses
|
||||||
else e ->
|
else _e ->
|
||||||
IO.inspect(e)
|
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -102,8 +102,8 @@ def finger(account, getter \\ &HTTPoison.get/3) do
|
||||||
{:ok, data}
|
{:ok, data}
|
||||||
else
|
else
|
||||||
e ->
|
e ->
|
||||||
Logger.debug("Couldn't finger #{account}.")
|
Logger.debug(fn -> "Couldn't finger #{account}." end)
|
||||||
Logger.debug(inspect(e))
|
Logger.debug(fn -> inspect(e) end)
|
||||||
{:error, e}
|
{:error, e}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,7 +49,7 @@ def publish(topic, user, activity) do
|
||||||
|> to_string
|
|> to_string
|
||||||
|
|
||||||
signature = sign(sub.secret || "", response)
|
signature = sign(sub.secret || "", response)
|
||||||
Logger.debug("Pushing to #{sub.callback}")
|
Logger.debug(fn -> "Pushing to #{sub.callback}" end)
|
||||||
|
|
||||||
HTTPoison.post(sub.callback, response, [
|
HTTPoison.post(sub.callback, response, [
|
||||||
{"Content-Type", "application/atom+xml"},
|
{"Content-Type", "application/atom+xml"},
|
||||||
|
@ -196,8 +196,8 @@ def request_subscription(websub, poster \\ &HTTPoison.post/3, timeout \\ 10_000)
|
||||||
change = Ecto.Changeset.change(websub, %{state: "rejected"})
|
change = Ecto.Changeset.change(websub, %{state: "rejected"})
|
||||||
{:ok, websub} = Repo.update(change)
|
{:ok, websub} = Repo.update(change)
|
||||||
|
|
||||||
Logger.debug("Couldn't confirm subscription: #{inspect(websub)}")
|
Logger.debug(fn -> "Couldn't confirm subscription: #{inspect(websub)}" end)
|
||||||
Logger.debug("error: #{inspect(e)}")
|
Logger.debug(fn -> "error: #{inspect(e)}" end)
|
||||||
|
|
||||||
{:error, websub}
|
{:error, websub}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue