update copyright years to 2019
[akkoma] / lib / pleroma / web / salmon / salmon.ex
index 10542fd00d88c830e6bf3462d613e75a01db0dfa..e41657da1a95cabb8e81651570a9270bcf53b638 100644 (file)
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
 defmodule Pleroma.Web.Salmon do
   @httpoison Application.get_env(:pleroma, :httpoison)
 
@@ -157,19 +161,21 @@ defmodule Pleroma.Web.Salmon do
     |> Enum.filter(fn user -> user && !user.local end)
   end
 
-  defp send_to_user(%{info: %{"salmon" => salmon}}, feed, poster) do
-    with {:ok, %{status_code: code}} <-
+  # push an activity to remote accounts
+  #
+  defp send_to_user(%{info: %{salmon: salmon}}, feed, poster),
+    do: send_to_user(salmon, feed, poster)
+
+  defp send_to_user(url, feed, poster) when is_binary(url) do
+    with {:ok, %{status: code}} <-
            poster.(
-             salmon,
+             url,
              feed,
-             [{"Content-Type", "application/magic-envelope+xml"}],
-             timeout: 10000,
-             recv_timeout: 20000,
-             hackney: [pool: :default]
+             [{"Content-Type", "application/magic-envelope+xml"}]
            ) do
-      Logger.debug(fn -> "Pushed to #{salmon}, code #{code}" end)
+      Logger.debug(fn -> "Pushed to #{url}, code #{code}" end)
     else
-      e -> Logger.debug(fn -> "Pushing Salmon to #{salmon} failed, #{inspect(e)}" end)
+      e -> Logger.debug(fn -> "Pushing Salmon to #{url} failed, #{inspect(e)}" end)
     end
   end
 
@@ -183,17 +189,23 @@ defmodule Pleroma.Web.Salmon do
     "Undo",
     "Delete"
   ]
-  def publish(user, activity, poster \\ &@httpoison.post/4)
 
-  def publish(%{info: %{"keys" => keys}} = user, %{data: %{"type" => type}} = activity, poster)
+  @doc """
+  Publishes an activity to remote accounts
+  """
+  @spec publish(User.t(), Pleroma.Activity.t(), Pleroma.HTTP.t()) :: none
+  def publish(user, activity, poster \\ &@httpoison.post/3)
+
+  def publish(%{info: %{keys: keys}} = user, %{data: %{"type" => type}} = activity, poster)
       when type in @supported_activities do
-    feed =
-      ActivityRepresenter.to_simple_form(activity, user, true)
-      |> ActivityRepresenter.wrap_with_entry()
-      |> :xmerl.export_simple(:xmerl_xml)
-      |> to_string
+    feed = ActivityRepresenter.to_simple_form(activity, user, true)
 
     if feed do
+      feed =
+        ActivityRepresenter.wrap_with_entry(feed)
+        |> :xmerl.export_simple(:xmerl_xml)
+        |> to_string
+
       {:ok, private, _} = keys_from_pem(keys)
       {:ok, feed} = encode(private, feed)