activitypub transmogrifier: rewrite incoming hashtags
[akkoma] / lib / pleroma / web / salmon / salmon.ex
index 806f3c3c07066ca56de1758bc94821a4c1361eac..ab0f97d5544e10dd059c799fc3871449e3c83a15 100644 (file)
@@ -29,7 +29,8 @@ defmodule Pleroma.Web.Salmon do
     with [data, _, _, _, _] <- decode(salmon),
          doc <- XML.parse_document(data),
          uri when not is_nil(uri) <- XML.string_from_xpath("/entry/author[1]/uri", doc),
-         {:ok, %{info: %{"magic_key" => magic_key}}} <- Pleroma.Web.OStatus.find_or_make_user(uri) do
+         {:ok, public_key} <- User.get_public_key_for_ap_id(uri),
+         magic_key <- encode_key(public_key) do
       {:ok, magic_key}
     end
   end
@@ -138,17 +139,18 @@ defmodule Pleroma.Web.Salmon do
     {:ok, salmon}
   end
 
-  def remote_users(%{data: %{"to" => to}}) do
+  def remote_users(%{data: %{"to" => to} = data}) do
+    to = to ++ (data["cc"] || [])
     to
     |> Enum.map(fn(id) -> User.get_cached_by_ap_id(id) end)
     |> Enum.filter(fn(user) -> user && !user.local end)
   end
 
   defp send_to_user(%{info: %{"salmon" => salmon}}, feed, poster) do
-    with {:ok, %{status_code: code}} <- poster.(salmon, feed, [{"Content-Type", "application/magic-envelope+xml"}], timeout: 10000, recv_timeout: 20000) do
+    with {:ok, %{status_code: code}} <- poster.(salmon, feed, [{"Content-Type", "application/magic-envelope+xml"}], timeout: 10000, recv_timeout: 20000, hackney: [pool: :default]) do
       Logger.debug(fn -> "Pushed to #{salmon}, code #{code}" end)
     else
-      e -> Logger.debug(fn -> "Pushing salmon to #{salmon} failed, #{inspect(e)}" end)
+      e -> Logger.debug(fn -> "Pushing Salmon to #{salmon} failed, #{inspect(e)}" end)
     end
   end
 
@@ -176,7 +178,7 @@ defmodule Pleroma.Web.Salmon do
       remote_users(activity)
       |> Enum.each(fn(remote_user) ->
         Task.start(fn ->
-          Logger.debug(fn -> "sending salmon to #{remote_user.ap_id}" end)
+          Logger.debug(fn -> "Sending Salmon to #{remote_user.ap_id}" end)
           send_to_user(remote_user, feed, poster)
         end)
       end)