Fix activity_representer to work with User.get_or_fetch returning tuple.
authorPhil Hagelberg <phil@hagelb.org>
Mon, 28 Oct 2019 02:02:19 +0000 (19:02 -0700)
committerPhil Hagelberg <phil@hagelb.org>
Sun, 10 Nov 2019 02:06:51 +0000 (18:06 -0800)
lib/pleroma/web/ostatus/ostatus_controller.ex
lib/pleroma/web/static_fe/activity_representer.ex

index 76a244d0ffc304be6682e8ef2835480fe0cb8680..ab5fdbc785d73250567de53b0c5fc4b072113182 100644 (file)
@@ -81,7 +81,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
     else
       with {_, %Activity{} = activity} <- {:activity, Activity.get_by_id_with_object(id)},
            {_, true} <- {:public?, Visibility.is_public?(activity)},
-             %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
+           %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
         cond do
           format == "html" && activity.data["type"] == "Create" ->
             %Object{} = object = Object.normalize(activity)
index e383b8415f96903207e97d8b7ec71939646fca44..9bee732d512337af84388dbe506bdafbc2de4505 100644 (file)
@@ -9,20 +9,19 @@ defmodule Pleroma.Web.StaticFE.ActivityRepresenter do
   alias Pleroma.Web.ActivityPub.Visibility
   alias Pleroma.Web.Router.Helpers
 
-  def prepare_activity(%User{} = user, %Object{} = object, activity_id) do
+  def prepare_activity(%User{} = user, %Activity{} = activity) do
+    object = Object.normalize(activity.data["object"])
+
     %{}
     |> set_user(user)
     |> set_object(object)
     |> set_title(object)
     |> set_content(object)
-    |> set_link(activity_id)
+    |> set_link(activity.id)
     |> set_published(object)
     |> set_attachments(object)
   end
 
-  def prepare_activity(%User{} = user, %Activity{} = activity),
-    do: prepare_activity(user, Object.normalize(activity.data["object"]), activity.id)
-
   defp set_user(data, %User{} = user), do: Map.put(data, :user, user)
 
   defp set_object(data, %Object{} = object), do: Map.put(data, :object, object)
@@ -52,10 +51,8 @@ defmodule Pleroma.Web.StaticFE.ActivityRepresenter do
   def represent(activity_id) do
     with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id(activity_id),
          true <- Visibility.is_public?(activity),
-         %Object{} = object <- Object.normalize(activity.data["object"]),
-         %User{} = user <- User.get_or_fetch(activity.data["actor"]),
-         data <- prepare_activity(user, object, activity_id) do
-      {:ok, data}
+         {:ok, %User{} = user} <- User.get_or_fetch(activity.data["actor"]) do
+      {:ok, prepare_activity(user, activity)}
     else
       e ->
         {:error, e}