Merge branch 'feature/configdb-mix-tasks' into 'develop'
[akkoma] / lib / pleroma / activity.ex
index 3b01f5e316a0b83d55b99ceba9d563aac60c8e41..07982331257d5c27ae22b324a6af9d9b07342812 100644 (file)
@@ -14,12 +14,11 @@ defmodule Pleroma.Activity do
   alias Pleroma.ReportNote
   alias Pleroma.ThreadMute
   alias Pleroma.User
+  alias Pleroma.Web.ActivityPub.ActivityPub
 
   import Ecto.Changeset
   import Ecto.Query
 
-  require Pleroma.Constants
-
   @type t :: %__MODULE__{}
   @type actor :: String.t()
 
@@ -155,6 +154,18 @@ defmodule Pleroma.Activity do
 
   def get_bookmark(_, _), do: nil
 
+  def get_report(activity_id) do
+    opts = %{
+      type: "Flag",
+      skip_preload: true,
+      preload_report_notes: true
+    }
+
+    ActivityPub.fetch_activities_query([], opts)
+    |> where(id: ^activity_id)
+    |> Repo.one()
+  end
+
   def change(struct, params \\ %{}) do
     struct
     |> cast(params, [:data, :recipients])
@@ -183,6 +194,19 @@ defmodule Pleroma.Activity do
     end
   end
 
+  def get_by_id_with_user_actor(id) do
+    case FlakeId.flake_id?(id) do
+      true ->
+        Activity
+        |> where([a], a.id == ^id)
+        |> with_preloaded_user_actor()
+        |> Repo.one()
+
+      _ ->
+        nil
+    end
+  end
+
   def get_by_id_with_object(id) do
     Activity
     |> where(id: ^id)
@@ -346,11 +370,14 @@ defmodule Pleroma.Activity do
     activity.id in actor.pinned_activities
   end
 
-  def local_only?(activity) do
-    recipients = Enum.concat(activity.data["to"], Map.get(activity.data, "cc", []))
-    public = Pleroma.Constants.as_public()
-    local = Pleroma.Constants.as_local_public()
-
-    Enum.member?(recipients, local) and not Enum.member?(recipients, public)
+  @spec get_by_object_ap_id_with_object(String.t()) :: t() | nil
+  def get_by_object_ap_id_with_object(ap_id) when is_binary(ap_id) do
+    ap_id
+    |> Queries.by_object_id()
+    |> with_preloaded_object()
+    |> first()
+    |> Repo.one()
   end
+
+  def get_by_object_ap_id_with_object(_), do: nil
 end