From 85953c0836c84550c8f61218d0a5b284c0716d34 Mon Sep 17 00:00:00 2001 From: Alex S Date: Mon, 22 Apr 2019 16:16:19 +0700 Subject: [PATCH] fixes for tests --- .../web/mastodon_api/mastodon_api_controller.ex | 2 +- lib/pleroma/web/mastodon_api/views/status_view.ex | 11 +++++++++-- .../web/mastodon_api/mastodon_api_controller_test.exs | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 859cf9524..f5067e17e 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -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) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index b2ed023dc..57cb9fdcc 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -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) diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index a22944088..15bb02297 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -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)