activitypub: fix date header format
[akkoma] / lib / pleroma / web / activity_pub / utils.ex
index da6cca4ddd4052b93013b8c0c3b30a4fd88002b0..88f4779c8abe1aad455b24a5fc3714f5ce7f481a 100644 (file)
@@ -142,8 +142,14 @@ defmodule Pleroma.Web.ActivityPub.Utils do
     context = context || generate_id("contexts")
     changeset = Object.context_mapping(context)
 
-    with {:ok, object} <- Object.insert_or_get(changeset) do
-      object
+    case Repo.insert(changeset) do
+      {:ok, object} ->
+        object
+
+      # This should be solved by an upsert, but it seems ecto
+      # has problems accessing the constraint inside the jsonb.
+      {:error, _} ->
+        Object.get_cached_by_ap_id(context)
     end
   end
 
@@ -158,7 +164,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
         _ -> 5
       end
 
-    Pleroma.Web.Federator.enqueue(:publish, activity, priority)
+    Pleroma.Web.Federator.publish(activity, priority)
     :ok
   end
 
@@ -592,4 +598,20 @@ defmodule Pleroma.Web.ActivityPub.Utils do
     }
     |> Map.merge(additional)
   end
+
+  #### Flag-related helpers
+
+  def make_flag_data(params, additional) do
+    status_ap_ids = Enum.map(params.statuses || [], & &1.data["id"])
+    object = [params.account.ap_id] ++ status_ap_ids
+
+    %{
+      "type" => "Flag",
+      "actor" => params.actor.ap_id,
+      "content" => params.content,
+      "object" => object,
+      "context" => params.context
+    }
+    |> Map.merge(additional)
+  end
 end