Merge branch 'develop' into preload-data
[akkoma] / lib / pleroma / web / activity_pub / object_validators / like_validator.ex
index d9ee079957afa7fb4928fe800b6e6658d7e3b55c..034f25492d5affab99bda6d113bc58c29c950419 100644 (file)
@@ -20,8 +20,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidator do
     field(:object, Types.ObjectID)
     field(:actor, Types.ObjectID)
     field(:context, :string)
-    field(:to, {:array, :string}, default: [])
-    field(:cc, {:array, :string}, default: [])
+    field(:to, Types.Recipients, default: [])
+    field(:cc, Types.Recipients, default: [])
   end
 
   def cast_and_validate(data) do
@@ -44,11 +44,25 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidator do
   def fix_after_cast(cng) do
     cng
     |> fix_recipients()
+    |> fix_context()
+  end
+
+  def fix_context(cng) do
+    object = get_field(cng, :object)
+
+    with nil <- get_field(cng, :context),
+         %Object{data: %{"context" => context}} <- Object.get_cached_by_ap_id(object) do
+      cng
+      |> put_change(:context, context)
+    else
+      _ ->
+        cng
+    end
   end
 
   def fix_recipients(cng) do
-    to = get_field(cng, :to) || []
-    cc = get_field(cng, :cc) || []
+    to = get_field(cng, :to)
+    cc = get_field(cng, :cc)
     object = get_field(cng, :object)
 
     with {[], []} <- {to, cc},