Added some more normalization calls all in mastodon api controller
authorrinpatch <rinpatch@sdf.org>
Wed, 17 Apr 2019 10:04:58 +0000 (13:04 +0300)
committerrinpatch <rinpatch@sdf.org>
Wed, 17 Apr 2019 10:04:58 +0000 (13:04 +0300)
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
lib/pleroma/web/mastodon_api/views/status_view.ex
test/web/mastodon_api/mastodon_api_controller_test.exs

index d6eb843f7c2a10b79117e62046b59b0f8adf8d3a..6458a3449e83374224f982acce466d3c14c67227 100644 (file)
@@ -127,7 +127,7 @@ defmodule Pleroma.Web.CommonAPI do
       in_reply_to ->
         # XXX: these heuristics should be moved out of MastodonAPI.
         with %Object{} = object <- Object.normalize(in_reply_to) do
-          Pleroma.Web.MastodonAPI.StatusView.get_visibility(object.data)
+          Pleroma.Web.MastodonAPI.StatusView.get_visibility(object)
         end
     end
   end
index 24a2d4cb9cd8db210d8e7918174b1a1adf8aa38b..d2e3da4496bb12e646201f1ba15b09dd2b9f08ba 100644 (file)
@@ -543,10 +543,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   end
 
   def bookmark_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
-    with %Activity{} = activity <- Activity.get_by_id(id),
+    with %Activity{} = activity <- Activity.get_by_id_with_object(id),
+         %Object{} = object <- Object.normalize(activity),
          %User{} = user <- User.get_by_nickname(user.nickname),
          true <- Visibility.visible_for_user?(activity, user),
-         {:ok, user} <- User.bookmark(user, activity.data["object"]["id"]) do
+         {:ok, user} <- User.bookmark(user, object.data["id"]) do
       conn
       |> put_view(StatusView)
       |> try_render("status.json", %{activity: activity, for: user, as: :activity})
index e4de5ecfb3726b7da261a2a6e022aae53278261a..03dc587d9ea5d63479e918e1356060f794f18e1a 100644 (file)
@@ -125,8 +125,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     }
   end
 
-  def render("status.json", %{activity: %{data: %{"object" => object}} = activity} = opts) do
-    object = Object.normalize(object)
+  def render("status.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
+    object = Object.normalize(activity)
 
     user = get_user(activity.data["actor"])
 
@@ -320,8 +320,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     end
   end
 
-  def get_reply_to(%{data: %{"object" => object}}, _) do
-    object = Object.normalize(object)
+  def get_reply_to(%{data: %{"object" => _object}} = activity, _) do
+    object = Object.normalize(activity)
 
     if object.data["inReplyTo"] && object.data["inReplyTo"] != "" do
       Activity.get_create_by_object_ap_id(object.data["inReplyTo"])
index f21cf677d1147bdf580ae9652bc8d71736337dd0..70ab92386ac31074fc8d232cf41dd899547f3146 100644 (file)
@@ -1879,7 +1879,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
     capture_log(fn ->
       conn =
         conn
-        |> get("/api/v1/search", %{"q" => activity.data["object"]["id"]})
+        |> get("/api/v1/search", %{"q" => Object.normalize(activity).id})
 
       assert results = json_response(conn, 200)