activitypub transmogrifier: handle activity lookup failure
authorWilliam Pitcock <nenolod@dereferenced.org>
Wed, 13 Jun 2018 22:14:53 +0000 (22:14 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Wed, 13 Jun 2018 22:19:38 +0000 (22:19 +0000)
with the introduction of MRF, it is possible that an activity may be orphaned from it's parent, if
an activity in the chain was rejected by the active MRF policies.  accordingly, handle this in the
same way as any other orphaned activity.

closes #156

lib/pleroma/web/activity_pub/transmogrifier.ex

index e7a3420d2d17f077b5a8efad5dc08288b71eb786..4c27a5704890364f2b218f40ab2d03ea1e4083c8 100644 (file)
@@ -30,14 +30,19 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
       when not is_nil(in_reply_to_id) do
     case ActivityPub.fetch_object_from_id(in_reply_to_id) do
       {:ok, replied_object} ->
-        activity = Activity.get_create_activity_by_object_ap_id(replied_object.data["id"])
-
-        object
-        |> Map.put("inReplyTo", replied_object.data["id"])
-        |> Map.put("inReplyToAtomUri", object["inReplyToAtomUri"] || in_reply_to_id)
-        |> Map.put("inReplyToStatusId", activity.id)
-        |> Map.put("conversation", replied_object.data["context"] || object["conversation"])
-        |> Map.put("context", replied_object.data["context"] || object["conversation"])
+        with %Activity{} = activity <-
+               Activity.get_create_activity_by_object_ap_id(replied_object.data["id"]) do
+          object
+          |> Map.put("inReplyTo", replied_object.data["id"])
+          |> Map.put("inReplyToAtomUri", object["inReplyToAtomUri"] || in_reply_to_id)
+          |> Map.put("inReplyToStatusId", activity.id)
+          |> Map.put("conversation", replied_object.data["context"] || object["conversation"])
+          |> Map.put("context", replied_object.data["context"] || object["conversation"])
+        else
+          e ->
+            Logger.error("Couldn't fetch #{object["inReplyTo"]} #{inspect(e)}")
+            object
+        end
 
       e ->
         Logger.error("Couldn't fetch #{object["inReplyTo"]} #{inspect(e)}")