Stop adding statusnetConversationIds.
[akkoma] / lib / pleroma / web / activity_pub / activity_pub.ex
index 0d3360ee187c4773909748e76aef552eef050d1c..9441a37aba9b263b51a88176ff64590391fe00b7 100644 (file)
@@ -19,6 +19,28 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     Repo.insert(%Activity{data: map})
   end
 
+  def create(to, actor, context, object, additional \\ %{}, published \\ nil) do
+    published = published || make_date()
+
+    activity = %{
+      "type" => "Create",
+      "to" => to,
+      "actor" => actor.ap_id,
+      "object" => object,
+      "published" => published,
+      "context" => context
+    }
+    |> Map.merge(additional)
+
+    with {:ok, activity} <- insert(activity) do
+      if actor.local do
+        Pleroma.Web.Federator.enqueue(:publish, activity)
+       end
+
+      {:ok, activity}
+    end
+  end
+
   def like(%User{ap_id: ap_id} = user, %Object{data: %{ "id" => id}} = object) do
     cond do
       # There's already a like here, so return the original activity.
@@ -133,6 +155,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
       query
     end
 
+    query = if opts["actor_id"] do
+      from activity in query,
+        where: fragment("? @> ?", activity.data, ^%{actor: opts["actor_id"]})
+    else
+      query
+    end
+
     Repo.all(query)
     |> Enum.reverse
   end
@@ -167,7 +196,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     Repo.all(query)
   end
 
-  def upload(%Plug.Upload{} = file) do
+  def upload(file) do
     data = Upload.store(file)
     Repo.insert(%Object{data: data})
   end