Return "audio" info in mastodon api.
[akkoma] / lib / pleroma / web / activity_pub / utils.ex
index 51fac6fe27beacb21552577c5baf7aa8a921ba72..a25b27aabde0b3035c57693aaeadf4ca1962bcf3 100644 (file)
@@ -5,6 +5,26 @@ defmodule Pleroma.Web.ActivityPub.Utils do
   alias Ecto.{Changeset, UUID}
   import Ecto.Query
 
+  def make_json_ld_header do
+    %{
+      "@context" => [
+        "https://www.w3.org/ns/activitystreams",
+        "https://w3id.org/security/v1",
+        %{
+          "manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
+          "sensitive" => "as:sensitive",
+          "Hashtag" => "as:Hashtag",
+          "ostatus" => "http://ostatus.org#",
+          "atomUri" => "ostatus:atomUri",
+          "inReplyToAtomUri" => "ostatus:inReplyToAtomUri",
+          "conversation" => "ostatus:conversation",
+          "toot" => "http://joinmastodon.org/ns#",
+          "Emoji" => "toot:Emoji"
+        }
+      ]
+    }
+  end
+
   def make_date do
     DateTime.utc_now() |> DateTime.to_iso8601
   end
@@ -29,7 +49,12 @@ defmodule Pleroma.Web.ActivityPub.Utils do
   Enqueues an activity for federation if it's local
   """
   def maybe_federate(%Activity{local: true} = activity) do
-    Pleroma.Web.Federator.enqueue(:publish, activity)
+    priority = case activity.data["type"] do
+                 "Delete" -> 10
+                 "Create" -> 1
+                 _ -> 5
+               end
+    Pleroma.Web.Federator.enqueue(:publish, activity, priority)
     :ok
   end
   def maybe_federate(_), do: :ok
@@ -63,7 +88,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
   @doc """
   Inserts a full object if it is contained in an activity.
   """
-  def insert_full_object(%{"object" => object_data}) when is_map(object_data) do
+  def insert_full_object(%{"object" => %{"type" => type} = object_data}) when is_map(object_data) and type in ["Note"] do
     with {:ok, _} <- Object.create(object_data) do
       :ok
     end
@@ -104,6 +129,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
       "actor" => ap_id,
       "object" => id,
       "to" => [actor.follower_address, object.data["actor"]],
+      "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
       "context" => object.data["context"]
     }
 
@@ -145,6 +171,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
       "type" => "Follow",
       "actor" => follower_id,
       "to" => [followed_id],
+      "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
       "object" => followed_id
     }
 
@@ -172,6 +199,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
       "actor" => ap_id,
       "object" => id,
       "to" => [user.follower_address, object.data["actor"]],
+      "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
       "context" => object.data["context"]
     }
 
@@ -200,7 +228,6 @@ defmodule Pleroma.Web.ActivityPub.Utils do
 
   def make_create_data(params, additional) do
     published = params.published || make_date()
-
     %{
       "type" => "Create",
       "to" => params.to |> Enum.uniq,