MastodonAPI: Stream fixes.
[akkoma] / lib / pleroma / web / activity_pub / activity_pub.ex
index 1624c6545b31e0af5fd1a7683431a3c1eb13a751..5cbf14868e2c39f71b386fc9fe35a8656f43753a 100644 (file)
@@ -22,6 +22,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     with create_data <- make_create_data(%{to: to, actor: actor, published: published, context: context, object: object}, additional),
          {:ok, activity} <- insert(create_data, local),
          :ok <- maybe_federate(activity) do
+      if activity.data["type"] == "Create" and Enum.member?(activity.data["to"], "https://www.w3.org/ns/activitystreams#Public") do
+        Pleroma.Web.Streamer.stream("public", activity)
+        if local do
+          Pleroma.Web.Streamer.stream("public:local", activity)
+        end
+      end
       {:ok, activity}
     end
   end
@@ -156,6 +162,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   end
   defp restrict_favorited_by(query, _), do: query
 
+  defp restrict_media(query, %{"only_media" => val}) when val == "true" or val == "1" do
+    from activity in query,
+      where: fragment("not (? #> '{\"object\",\"attachment\"}' = ?)", activity.data, ^[])
+  end
+  defp restrict_media(query, _), do: query
+
   # Only search through last 100_000 activities by default
   defp restrict_recent(query, %{"whole_db" => true}), do: query
   defp restrict_recent(query, _) do
@@ -188,6 +200,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     |> restrict_favorited_by(opts)
     |> restrict_recent(opts)
     |> restrict_blocked(opts)
+    |> restrict_media(opts)
     |> Repo.all
     |> Enum.reverse
   end