common api: use Object.normalize() instead of Object.get_by_ap_id() directly.
authorWilliam Pitcock <nenolod@dereferenced.org>
Mon, 18 Jun 2018 21:08:12 +0000 (21:08 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Wed, 27 Jun 2018 13:07:35 +0000 (13:07 +0000)
lib/pleroma/web/common_api/common_api.ex

index 8845419c2461081e7c2a04b2f34eef99ecdc604d..3f18a68e8a9e527b723ac23625f3959c4a8d5788 100644 (file)
@@ -7,7 +7,7 @@ defmodule Pleroma.Web.CommonAPI do
 
   def delete(activity_id, user) do
     with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id),
-         %Object{} = object <- Object.get_by_ap_id(object_id),
+         %Object{} = object <- Object.normalize(object_id),
          true <- user.info["is_moderator"] || user.ap_id == object.data["actor"],
          {:ok, delete} <- ActivityPub.delete(object) do
       {:ok, delete}
@@ -16,7 +16,7 @@ defmodule Pleroma.Web.CommonAPI do
 
   def repeat(id_or_ap_id, user) do
     with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id),
-         object <- Object.get_by_ap_id(activity.data["object"]["id"]) do
+         object <- Object.normalize(activity.data["object"]["id"]) do
       ActivityPub.announce(user, object)
     else
       _ ->
@@ -26,7 +26,7 @@ defmodule Pleroma.Web.CommonAPI do
 
   def unrepeat(id_or_ap_id, user) do
     with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id),
-         object <- Object.get_by_ap_id(activity.data["object"]["id"]) do
+         object <- Object.normalize(activity.data["object"]["id"]) do
       ActivityPub.unannounce(user, object)
     else
       _ ->
@@ -37,7 +37,7 @@ defmodule Pleroma.Web.CommonAPI do
   def favorite(id_or_ap_id, user) do
     with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id),
          false <- activity.data["actor"] == user.ap_id,
-         object <- Object.get_by_ap_id(activity.data["object"]["id"]) do
+         object <- Object.normalize(activity.data["object"]["id"]) do
       ActivityPub.like(user, object)
     else
       _ ->
@@ -48,7 +48,7 @@ defmodule Pleroma.Web.CommonAPI do
   def unfavorite(id_or_ap_id, user) do
     with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id),
          false <- activity.data["actor"] == user.ap_id,
-         object <- Object.get_by_ap_id(activity.data["object"]["id"]) do
+         object <- Object.normalize(activity.data["object"]["id"]) do
       ActivityPub.unlike(user, object)
     else
       _ ->