Salmon: Take both versions of public keys.
[akkoma] / lib / pleroma / web / activity_pub / activity_pub.ex
index a0b51da89eaaebaa6218b62eb1c0b06545c83324..fb33f2e3ef2eddfc6e637fab797673acc3d0a443 100644 (file)
@@ -129,12 +129,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   end
 
   def fetch_activities_for_context(context, opts \\ %{}) do
-    query = from activity in Activity,
-      where: fragment("?->>'type' = ? and ?->>'context' = ?", activity.data, "Create", activity.data, ^context),
-      order_by: [desc: :id]
+    public = ["https://www.w3.org/ns/activitystreams#Public"]
+    recipients = if opts["user"], do: [opts["user"].ap_id | opts["user"].following] ++ public, else: public
+
+    query = from activity in Activity
     query = query
       |> restrict_blocked(opts)
-      |> restrict_recipients(["https://www.w3.org/ns/activitystreams#Public"], opts["user"])
+      |> restrict_recipients(recipients, opts["user"])
+
+   query = from activity in query,
+      where: fragment("?->>'type' = ? and ?->>'context' = ?", activity.data, "Create", activity.data, ^context),
+      order_by: [desc: :id]
     Repo.all(query)
   end
 
@@ -280,20 +285,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   def publish(actor, activity) do
     {:ok, followers} = User.get_followers(actor)
 
-    remote_inboxes = Pleroma.Web.Salmon.remote_users(activity) ++ followers
+    remote_inboxes = (Pleroma.Web.Salmon.remote_users(activity) ++ followers)
     |> Enum.filter(fn (user) -> User.ap_enabled?(user) end)
     |> Enum.map(fn (%{info: %{"source_data" => data}}) ->
-      (data["endpoints"] && data["endpoints"]["sharedInbox"]) ||data["inbox"]
+      (data["endpoints"] && data["endpoints"]["sharedInbox"]) || data["inbox"]
     end)
     |> Enum.uniq
 
     {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
-
+    json = Poison.encode!(data)
     Enum.each remote_inboxes, fn(inbox) ->
       Logger.info("Federating #{activity.data["id"]} to #{inbox}")
       host = URI.parse(inbox).host
-      signature = Pleroma.Web.HTTPSignatures.sign(actor, %{host: host})
-      @httpoison.post(inbox, Poison.encode!(data), [{"Content-Type", "application/activity+json"}, {"signature", signature}])
+      signature = Pleroma.Web.HTTPSignatures.sign(actor, %{host: host, "content-length": byte_size(json)})
+      @httpoison.post(inbox, json, [{"Content-Type", "application/activity+json"}, {"signature", signature}])
     end
   end