fixes for tests
authorAlex S <alex.strizhakov@gmail.com>
Mon, 22 Apr 2019 09:16:19 +0000 (16:16 +0700)
committerAlex S <alex.strizhakov@gmail.com>
Thu, 25 Apr 2019 06:46:40 +0000 (13:46 +0700)
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 859cf9524a75c5d2509f2f728bcdf44a7214d842..f5067e17e788e037f7d1e691dc115ab14164037f 100644 (file)
@@ -280,7 +280,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
       |> ActivityPub.contain_timeline(user)
       |> Enum.reverse()
 
-    user = Repo.preload(user, :bookmarks)
+    user = Repo.preload(user, bookmarks: :activity)
 
     conn
     |> add_link_headers(:home_timeline, activities)
index b2ed023dc82c7efe9207ec92aaed3de845e8be4c..57cb9fdcc465d404613f54d61f99c304e9d39f60 100644 (file)
@@ -85,7 +85,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
 
     activity_object = Object.normalize(activity)
     favorited = opts[:for] && opts[:for].ap_id in (activity_object.data["likes"] || [])
-    bookmarked = opts[:for] && activity_object.data["id"] in opts[:for].bookmarks
+
+    bookmarked =
+      opts[:for] && Ecto.assoc_loaded?(opts[:for].bookmarks) &&
+        Enum.any?(opts[:for].bookmarks, fn b ->
+          b.activity_id == activity.id or b.activity.data["object"]["id"] == object
+        end)
 
     mentions =
       activity.recipients
@@ -150,7 +155,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
 
     bookmarked =
       opts[:for] && Ecto.assoc_loaded?(opts[:for].bookmarks) &&
-        Enum.any?(opts[:for].bookmarks, fn b -> b.activity_id == activity.id end)
+        Enum.any?(opts[:for].bookmarks, fn b ->
+          b.activity_id == activity.id
+        end)
 
     attachment_data = object.data["attachment"] || []
     attachments = render_many(attachment_data, StatusView, "attachment.json", as: :attachment)
index a229440887a5bd3aa487536608091ce285e58ca7..15bb0229706a30802007ef58080f6d4d2ecbc0c8 100644 (file)
@@ -1022,7 +1022,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
       user2 = insert(:user)
       user3 = insert(:user)
       CommonAPI.favorite(activity.id, user2)
-      {:ok, user2} = User.bookmark(user2, activity.data["object"]["id"])
+      {:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id)
       {:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)
       {:ok, _, _object} = CommonAPI.repeat(activity.id, user2)