diff options
Diffstat (limited to 'lib')
21 files changed, 214 insertions, 179 deletions
| diff --git a/lib/mix/tasks/pleroma/benchmark.ex b/lib/mix/tasks/pleroma/benchmark.ex index 6ab7fe8ef..dd2b9c8f2 100644 --- a/lib/mix/tasks/pleroma/benchmark.ex +++ b/lib/mix/tasks/pleroma/benchmark.ex @@ -67,8 +67,7 @@ defmodule Mix.Tasks.Pleroma.Benchmark do            Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{              activities: activities,              for: user, -            as: :activity, -            skip_relationships: true +            as: :activity            })          end        }, diff --git a/lib/pleroma/user_relationship.ex b/lib/pleroma/user_relationship.ex index 235ad427c..6dfdd2860 100644 --- a/lib/pleroma/user_relationship.ex +++ b/lib/pleroma/user_relationship.ex @@ -87,6 +87,22 @@ defmodule Pleroma.UserRelationship do          source_to_target_rel_types \\ nil,          target_to_source_rel_types \\ nil        ) + +  def dictionary( +        _source_users, +        _target_users, +        [] = _source_to_target_rel_types, +        [] = _target_to_source_rel_types +      ) do +    [] +  end + +  def dictionary( +        source_users, +        target_users, +        source_to_target_rel_types, +        target_to_source_rel_types +      )        when is_list(source_users) and is_list(target_users) do      source_user_ids = User.binary_id(source_users)      target_user_ids = User.binary_id(target_users) @@ -138,11 +154,16 @@ defmodule Pleroma.UserRelationship do    def view_relationships_option(%User{} = reading_user, actors, opts) do      {source_to_target_rel_types, target_to_source_rel_types} = -      if opts[:source_mutes_only] do -        # This option is used for rendering statuses (FE needs `muted` flag for each one anyways) -        {[:mute], []} -      else -        {[:block, :mute, :notification_mute, :reblog_mute], [:block, :inverse_subscription]} +      case opts[:subset] do +        :source_mutes -> +          # Used for statuses rendering (FE needs `muted` flag for each status when statuses load) +          {[:mute], []} + +        nil -> +          {[:block, :mute, :notification_mute, :reblog_mute], [:block, :inverse_subscription]} + +        unknown -> +          raise "Unsupported :subset option value: #{inspect(unknown)}"        end      user_relationships = @@ -153,7 +174,17 @@ defmodule Pleroma.UserRelationship do          target_to_source_rel_types        ) -    following_relationships = FollowingRelationship.all_between_user_sets([reading_user], actors) +    following_relationships = +      case opts[:subset] do +        :source_mutes -> +          [] + +        nil -> +          FollowingRelationship.all_between_user_sets([reading_user], actors) + +        unknown -> +          raise "Unsupported :subset option value: #{inspect(unknown)}" +      end      %{user_relationships: user_relationships, following_relationships: following_relationships}    end diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 9821173d0..80c4df0e2 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -22,6 +22,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do    alias Pleroma.Web.ActivityPub.Pipeline    alias Pleroma.Web.ActivityPub.Relay    alias Pleroma.Web.ActivityPub.Utils +  alias Pleroma.Web.AdminAPI    alias Pleroma.Web.AdminAPI.AccountView    alias Pleroma.Web.AdminAPI.ConfigView    alias Pleroma.Web.AdminAPI.ModerationLogView @@ -30,8 +31,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do    alias Pleroma.Web.AdminAPI.Search    alias Pleroma.Web.CommonAPI    alias Pleroma.Web.Endpoint +  alias Pleroma.Web.MastodonAPI    alias Pleroma.Web.MastodonAPI.AppView -  alias Pleroma.Web.MastodonAPI.StatusView    alias Pleroma.Web.OAuth.App    alias Pleroma.Web.Router @@ -280,8 +281,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do        })      conn -    |> put_view(Pleroma.Web.AdminAPI.StatusView) -    |> render("index.json", %{activities: activities, as: :activity, skip_relationships: false}) +    |> put_view(AdminAPI.StatusView) +    |> render("index.json", %{activities: activities, as: :activity})    end    def list_user_statuses(conn, %{"nickname" => nickname} = params) do @@ -299,8 +300,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do          })        conn -      |> put_view(StatusView) -      |> render("index.json", %{activities: activities, as: :activity, skip_relationships: false}) +      |> put_view(MastodonAPI.StatusView) +      |> render("index.json", %{activities: activities, as: :activity})      else        _ -> {:error, :not_found}      end @@ -829,14 +830,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do        })      conn -    |> put_view(Pleroma.Web.AdminAPI.StatusView) -    |> render("index.json", %{activities: activities, as: :activity, skip_relationships: false}) +    |> put_view(AdminAPI.StatusView) +    |> render("index.json", %{activities: activities, as: :activity})    end    def status_show(conn, %{"id" => id}) do      with %Activity{} = activity <- Activity.get_by_id(id) do        conn -      |> put_view(StatusView) +      |> put_view(MastodonAPI.StatusView)        |> render("show.json", %{activity: activity})      else        _ -> errors(conn, {:error, :not_found}) @@ -861,7 +862,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do        })        conn -      |> put_view(StatusView) +      |> put_view(MastodonAPI.StatusView)        |> render("show.json", %{activity: activity})      end    end diff --git a/lib/pleroma/web/admin_api/views/account_view.ex b/lib/pleroma/web/admin_api/views/account_view.ex index a16a3ebf0..46dadb5ee 100644 --- a/lib/pleroma/web/admin_api/views/account_view.ex +++ b/lib/pleroma/web/admin_api/views/account_view.ex @@ -6,7 +6,9 @@ defmodule Pleroma.Web.AdminAPI.AccountView do    use Pleroma.Web, :view    alias Pleroma.User +  alias Pleroma.Web.AdminAPI    alias Pleroma.Web.AdminAPI.AccountView +  alias Pleroma.Web.MastodonAPI    alias Pleroma.Web.MediaProxy    def render("index.json", %{users: users, count: count, page_size: page_size}) do @@ -119,6 +121,13 @@ defmodule Pleroma.Web.AdminAPI.AccountView do      }    end +  def merge_account_views(%User{} = user) do +    MastodonAPI.AccountView.render("show.json", %{user: user}) +    |> Map.merge(AdminAPI.AccountView.render("show.json", %{user: user})) +  end + +  def merge_account_views(_), do: %{} +    defp parse_error([]), do: ""    defp parse_error(errors) do diff --git a/lib/pleroma/web/admin_api/views/report_view.ex b/lib/pleroma/web/admin_api/views/report_view.ex index d50969b2a..f432b8c2c 100644 --- a/lib/pleroma/web/admin_api/views/report_view.ex +++ b/lib/pleroma/web/admin_api/views/report_view.ex @@ -7,10 +7,13 @@ defmodule Pleroma.Web.AdminAPI.ReportView do    alias Pleroma.HTML    alias Pleroma.User +  alias Pleroma.Web.AdminAPI    alias Pleroma.Web.AdminAPI.Report    alias Pleroma.Web.CommonAPI.Utils    alias Pleroma.Web.MastodonAPI.StatusView +  defdelegate merge_account_views(user), to: AdminAPI.AccountView +    def render("index.json", %{reports: reports}) do      %{        reports: @@ -41,8 +44,7 @@ defmodule Pleroma.Web.AdminAPI.ReportView do        statuses:          StatusView.render("index.json", %{            activities: statuses, -          as: :activity, -          skip_relationships: false +          as: :activity          }),        state: report.data["state"],        notes: render(__MODULE__, "index_notes.json", %{notes: report.report_notes}) @@ -70,11 +72,4 @@ defmodule Pleroma.Web.AdminAPI.ReportView do        created_at: Utils.to_masto_date(inserted_at)      }    end - -  defp merge_account_views(%User{} = user) do -    Pleroma.Web.MastodonAPI.AccountView.render("show.json", %{user: user}) -    |> Map.merge(Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})) -  end - -  defp merge_account_views(_), do: %{}  end diff --git a/lib/pleroma/web/admin_api/views/status_view.ex b/lib/pleroma/web/admin_api/views/status_view.ex index 3637dee24..500800be2 100644 --- a/lib/pleroma/web/admin_api/views/status_view.ex +++ b/lib/pleroma/web/admin_api/views/status_view.ex @@ -7,24 +7,19 @@ defmodule Pleroma.Web.AdminAPI.StatusView do    require Pleroma.Constants -  alias Pleroma.User -  alias Pleroma.Web.MastodonAPI.StatusView +  alias Pleroma.Web.AdminAPI +  alias Pleroma.Web.MastodonAPI + +  defdelegate merge_account_views(user), to: AdminAPI.AccountView    def render("index.json", opts) do      safe_render_many(opts.activities, __MODULE__, "show.json", opts)    end    def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do -    user = StatusView.get_user(activity.data["actor"]) +    user = MastodonAPI.StatusView.get_user(activity.data["actor"]) -    StatusView.render("show.json", opts) +    MastodonAPI.StatusView.render("show.json", opts)      |> Map.merge(%{account: merge_account_views(user)})    end - -  defp merge_account_views(%User{} = user) do -    Pleroma.Web.MastodonAPI.AccountView.render("show.json", %{user: user}) -    |> Map.merge(Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})) -  end - -  defp merge_account_views(_), do: %{}  end diff --git a/lib/pleroma/web/api_spec/helpers.ex b/lib/pleroma/web/api_spec/helpers.ex index 183df43ee..ee077a3f9 100644 --- a/lib/pleroma/web/api_spec/helpers.ex +++ b/lib/pleroma/web/api_spec/helpers.ex @@ -47,6 +47,15 @@ defmodule Pleroma.Web.ApiSpec.Helpers do      ]    end +  def embed_relationships_param do +    Operation.parameter( +      :embed_relationships, +      :query, +      :boolean, +      "Embed relationships into accounts (Pleroma extension)" +    ) +  end +    def empty_object_response do      Operation.response("Empty object", "application/json", %Schema{type: :object, example: %{}})    end diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex index 70069d6f9..c2a56b786 100644 --- a/lib/pleroma/web/api_spec/operations/account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/account_operation.ex @@ -156,7 +156,8 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do        description:          "Accounts which follow the given account, if network is not hidden by the account owner.",        parameters: -        [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ pagination_params(), +        [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ +          pagination_params() ++ [embed_relationships_param()],        responses: %{          200 => Operation.response("Accounts", "application/json", array_of_accounts())        } @@ -172,7 +173,8 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do        description:          "Accounts which the given account is following, if network is not hidden by the account owner.",        parameters: -        [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ pagination_params(), +        [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ +          pagination_params() ++ [embed_relationships_param()],        responses: %{200 => Operation.response("Accounts", "application/json", array_of_accounts())}      }    end diff --git a/lib/pleroma/web/api_spec/operations/search_operation.ex b/lib/pleroma/web/api_spec/operations/search_operation.ex index 6ea00a9a8..0dd908d7f 100644 --- a/lib/pleroma/web/api_spec/operations/search_operation.ex +++ b/lib/pleroma/web/api_spec/operations/search_operation.ex @@ -24,29 +24,30 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do        tags: ["Search"],        summary: "Search for matching accounts by username or display name",        operationId: "SearchController.account_search", -      parameters: [ -        Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for", -          required: true -        ), -        Operation.parameter( -          :limit, -          :query, -          %Schema{type: :integer, default: 40}, -          "Maximum number of results" -        ), -        Operation.parameter( -          :resolve, -          :query, -          %Schema{allOf: [BooleanLike], default: false}, -          "Attempt WebFinger lookup. Use this when `q` is an exact address." -        ), -        Operation.parameter( -          :following, -          :query, -          %Schema{allOf: [BooleanLike], default: false}, -          "Only include accounts that the user is following" -        ) -      ], +      parameters: +        [ +          Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for", +            required: true +          ), +          Operation.parameter( +            :limit, +            :query, +            %Schema{type: :integer, default: 40}, +            "Maximum number of results" +          ), +          Operation.parameter( +            :resolve, +            :query, +            %Schema{allOf: [BooleanLike], default: false}, +            "Attempt WebFinger lookup. Use this when `q` is an exact address." +          ), +          Operation.parameter( +            :following, +            :query, +            %Schema{allOf: [BooleanLike], default: false}, +            "Only include accounts that the user is following" +          ) +        ] ++ [embed_relationships_param()],        responses: %{          200 =>            Operation.response( @@ -65,40 +66,42 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do        security: [%{"oAuth" => ["read:search"]}],        operationId: "SearchController.search",        deprecated: true, -      parameters: [ -        Operation.parameter( -          :account_id, -          :query, -          FlakeID, -          "If provided, statuses returned will be authored only by this account" -        ), -        Operation.parameter( -          :type, -          :query, -          %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]}, -          "Search type" -        ), -        Operation.parameter(:q, :query, %Schema{type: :string}, "The search query", required: true), -        Operation.parameter( -          :resolve, -          :query, -          %Schema{allOf: [BooleanLike], default: false}, -          "Attempt WebFinger lookup" -        ), -        Operation.parameter( -          :following, -          :query, -          %Schema{allOf: [BooleanLike], default: false}, -          "Only include accounts that the user is following" -        ), -        Operation.parameter( -          :offset, -          :query, -          %Schema{type: :integer}, -          "Offset" -        ) -        | pagination_params() -      ], +      parameters: +        [ +          Operation.parameter( +            :account_id, +            :query, +            FlakeID, +            "If provided, statuses returned will be authored only by this account" +          ), +          Operation.parameter( +            :type, +            :query, +            %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]}, +            "Search type" +          ), +          Operation.parameter(:q, :query, %Schema{type: :string}, "The search query", +            required: true +          ), +          Operation.parameter( +            :resolve, +            :query, +            %Schema{allOf: [BooleanLike], default: false}, +            "Attempt WebFinger lookup" +          ), +          Operation.parameter( +            :following, +            :query, +            %Schema{allOf: [BooleanLike], default: false}, +            "Only include accounts that the user is following" +          ), +          Operation.parameter( +            :offset, +            :query, +            %Schema{type: :integer}, +            "Offset" +          ) +        ] ++ pagination_params() ++ [embed_relationships_param()],        responses: %{          200 => Operation.response("Results", "application/json", results())        } diff --git a/lib/pleroma/web/chat_channel.ex b/lib/pleroma/web/chat_channel.ex index 38ec774f7..bce27897f 100644 --- a/lib/pleroma/web/chat_channel.ex +++ b/lib/pleroma/web/chat_channel.ex @@ -23,6 +23,7 @@ defmodule Pleroma.Web.ChatChannel do      if String.length(text) in 1..Pleroma.Config.get([:instance, :chat_limit]) do        author = User.get_cached_by_nickname(user_name)        author = Pleroma.Web.MastodonAPI.AccountView.render("show.json", user: author) +        message = ChatChannelState.add_message(%{text: text, author: author})        broadcast!(socket, "new_msg", message) diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex index eb97ae975..ae9b265b1 100644 --- a/lib/pleroma/web/controller_helper.ex +++ b/lib/pleroma/web/controller_helper.ex @@ -5,8 +5,6 @@  defmodule Pleroma.Web.ControllerHelper do    use Pleroma.Web, :controller -  alias Pleroma.Config -    # As in Mastodon API, per https://api.rubyonrails.org/classes/ActiveModel/Type/Boolean.html    @falsy_param_values [false, 0, "0", "f", "F", "false", "False", "FALSE", "off", "OFF"] @@ -106,13 +104,8 @@ defmodule Pleroma.Web.ControllerHelper do    def put_if_exist(map, key, value), do: Map.put(map, key, value) -  @doc "Whether to skip rendering `[:account][:pleroma][:relationship]`for statuses/notifications" -  def skip_relationships?(params) do -    if Config.get([:extensions, :output_relationships_in_statuses_by_default]) do -      false -    else -      # BREAKING: older PleromaFE versions do not send this param but _do_ expect relationships. -      not truthy_param?(params["with_relationships"]) -    end +  def embed_relationships?(params) do +    # To do: change to `truthy_param?(params["embed_relationships"])` once PleromaFE supports it +    not explicitly_falsy_param?(params["embed_relationships"])    end  end diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index b9ed2d7b2..ef41f9e96 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -10,8 +10,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do        add_link_headers: 2,        truthy_param?: 1,        assign_account_by_id: 2, -      json_response: 3, -      skip_relationships?: 1 +      embed_relationships?: 1, +      json_response: 3      ]    alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug @@ -247,8 +247,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do        |> render("index.json",          activities: activities,          for: reading_user, -        as: :activity, -        skip_relationships: skip_relationships?(params) +        as: :activity        )      else        _e -> render_error(conn, :not_found, "Can't find user") @@ -271,7 +270,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do      conn      |> add_link_headers(followers) -    |> render("index.json", for: for_user, users: followers, as: :user) +    # https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838#note_59223 +    |> render("index.json", +      for: for_user, +      users: followers, +      as: :user, +      embed_relationships: embed_relationships?(params) +    )    end    @doc "GET /api/v1/accounts/:id/following" @@ -290,7 +295,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do      conn      |> add_link_headers(followers) -    |> render("index.json", for: for_user, users: followers, as: :user) +    # https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838#note_59223 +    |> render("index.json", +      for: for_user, +      users: followers, +      as: :user, +      embed_relationships: embed_relationships?(params) +    )    end    @doc "GET /api/v1/accounts/:id/lists" diff --git a/lib/pleroma/web/mastodon_api/controllers/notification_controller.ex b/lib/pleroma/web/mastodon_api/controllers/notification_controller.ex index 596b85617..bcd12c73f 100644 --- a/lib/pleroma/web/mastodon_api/controllers/notification_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/notification_controller.ex @@ -5,7 +5,7 @@  defmodule Pleroma.Web.MastodonAPI.NotificationController do    use Pleroma.Web, :controller -  import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2, skip_relationships?: 1] +  import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2]    alias Pleroma.Notification    alias Pleroma.Plugs.OAuthScopesPlug @@ -50,8 +50,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationController do      |> add_link_headers(notifications)      |> render("index.json",        notifications: notifications, -      for: user, -      skip_relationships: skip_relationships?(params) +      for: user      )    end diff --git a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex index 0e0d54ba4..632c4590f 100644 --- a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex @@ -5,14 +5,13 @@  defmodule Pleroma.Web.MastodonAPI.SearchController do    use Pleroma.Web, :controller -  import Pleroma.Web.ControllerHelper, only: [skip_relationships?: 1] -    alias Pleroma.Activity    alias Pleroma.Plugs.OAuthScopesPlug    alias Pleroma.Plugs.RateLimiter    alias Pleroma.Repo    alias Pleroma.User    alias Pleroma.Web +  alias Pleroma.Web.ControllerHelper    alias Pleroma.Web.MastodonAPI.AccountView    alias Pleroma.Web.MastodonAPI.StatusView @@ -34,7 +33,13 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do      conn      |> put_view(AccountView) -    |> render("index.json", users: accounts, for: user, as: :user) +    # https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838#note_59223 +    |> render("index.json", +      users: accounts, +      for: user, +      as: :user, +      embed_relationships: ControllerHelper.embed_relationships?(params) +    )    end    def search2(conn, params), do: do_search(:v2, conn, params) @@ -71,13 +76,13 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do    defp search_options(params, user) do      [ -      skip_relationships: skip_relationships?(params),        resolve: params[:resolve],        following: params[:following],        limit: params[:limit],        offset: params[:offset],        type: params[:type],        author: get_author(params), +      embed_relationships: ControllerHelper.embed_relationships?(params),        for_user: user      ]      |> Enum.filter(&elem(&1, 1)) @@ -90,7 +95,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do        users: accounts,        for: options[:for_user],        as: :user, -      skip_relationships: false +      # https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838#note_59223 +      embed_relationships: options[:embed_relationships]      )    end @@ -100,8 +106,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do      StatusView.render("index.json",        activities: statuses,        for: options[:for_user], -      as: :activity, -      skip_relationships: options[:skip_relationships] +      as: :activity      )    end diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index 25e499a77..9dbf4f33c 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -6,7 +6,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do    use Pleroma.Web, :controller    import Pleroma.Web.ControllerHelper, -    only: [try_render: 3, add_link_headers: 2, skip_relationships?: 1] +    only: [try_render: 3, add_link_headers: 2]    require Ecto.Query @@ -105,7 +105,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do    `ids` query param is required    """ -  def index(%{assigns: %{user: user}} = conn, %{ids: ids} = params) do +  def index(%{assigns: %{user: user}} = conn, %{ids: ids} = _params) do      limit = 100      activities = @@ -117,8 +117,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do      render(conn, "index.json",        activities: activities,        for: user, -      as: :activity, -      skip_relationships: skip_relationships?(params) +      as: :activity      )    end @@ -383,8 +382,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do      |> render("index.json",        activities: activities,        for: user, -      as: :activity, -      skip_relationships: skip_relationships?(params) +      as: :activity      )    end @@ -406,8 +404,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do      |> render("index.json",        activities: activities,        for: user, -      as: :activity, -      skip_relationships: skip_relationships?(params) +      as: :activity      )    end  end diff --git a/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex b/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex index bbd576ffd..e2922d830 100644 --- a/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex @@ -6,7 +6,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do    use Pleroma.Web, :controller    import Pleroma.Web.ControllerHelper, -    only: [add_link_headers: 2, add_link_headers: 3, skip_relationships?: 1] +    only: [add_link_headers: 2, add_link_headers: 3, truthy_param?: 1]    alias Pleroma.Pagination    alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug @@ -63,8 +63,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do      |> render("index.json",        activities: activities,        for: user, -      as: :activity, -      skip_relationships: skip_relationships?(params) +      as: :activity      )    end @@ -88,8 +87,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do      |> render("index.json",        activities: activities,        for: user, -      as: :activity, -      skip_relationships: skip_relationships?(params) +      as: :activity      )    end @@ -125,8 +123,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do        |> render("index.json",          activities: activities,          for: user, -        as: :activity, -        skip_relationships: skip_relationships?(params) +        as: :activity        )      end    end @@ -173,8 +170,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do      |> render("index.json",        activities: activities,        for: user, -      as: :activity, -      skip_relationships: skip_relationships?(params) +      as: :activity      )    end @@ -203,8 +199,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do        render(conn, "index.json",          activities: activities,          for: user, -        as: :activity, -        skip_relationships: skip_relationships?(params) +        as: :activity        )      else        _e -> render_error(conn, :forbidden, "Error.") diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 835dfe9f4..45fffaad2 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -15,13 +15,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do    def render("index.json", %{users: users} = opts) do      reading_user = opts[:for] -    # Note: :skip_relationships option is currently intentionally not supported for accounts      relationships_opt =        cond do          Map.has_key?(opts, :relationships) ->            opts[:relationships] -        is_nil(reading_user) -> +        is_nil(reading_user) || !opts[:embed_relationships] ->            UserRelationship.view_relationships_option(nil, [])          true -> @@ -193,14 +192,14 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do        end)      relationship = -      if opts[:skip_relationships] do -        %{} -      else +      if opts[:embed_relationships] do          render("relationship.json", %{            user: opts[:for],            target: user,            relationships: opts[:relationships]          }) +      else +        %{}        end      %{ diff --git a/lib/pleroma/web/mastodon_api/views/notification_view.ex b/lib/pleroma/web/mastodon_api/views/notification_view.ex index 4da1ab67f..c46ddcf55 100644 --- a/lib/pleroma/web/mastodon_api/views/notification_view.ex +++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex @@ -51,9 +51,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do              |> Enum.filter(& &1)              |> Kernel.++(move_activities_targets) -          UserRelationship.view_relationships_option(reading_user, actors, -            source_mutes_only: opts[:skip_relationships] -          ) +          UserRelationship.view_relationships_option(reading_user, actors, subset: :source_mutes)        end      opts = @@ -83,15 +81,13 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do      mastodon_type = Activity.mastodon_notification_type(activity) -    render_opts = %{ -      relationships: opts[:relationships], -      skip_relationships: opts[:skip_relationships] -    } +    # Note: :relationships contain user mutes (needed for :muted flag in :status) +    status_render_opts = %{relationships: opts[:relationships]}      with %{id: _} = account <-             AccountView.render(               "show.json", -             Map.merge(render_opts, %{user: actor, for: reading_user}) +             %{user: actor, for: reading_user}             ) do        response = %{          id: to_string(notification.id), @@ -105,21 +101,20 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do        case mastodon_type do          "mention" -> -          put_status(response, activity, reading_user, render_opts) +          put_status(response, activity, reading_user, status_render_opts)          "favourite" -> -          put_status(response, parent_activity_fn.(), reading_user, render_opts) +          put_status(response, parent_activity_fn.(), reading_user, status_render_opts)          "reblog" -> -          put_status(response, parent_activity_fn.(), reading_user, render_opts) +          put_status(response, parent_activity_fn.(), reading_user, status_render_opts)          "move" -> -          # Note: :skip_relationships option being applied to _account_ rendering (here) -          put_target(response, activity, reading_user, render_opts) +          put_target(response, activity, reading_user, %{})          "pleroma:emoji_reaction" ->            response -          |> put_status(parent_activity_fn.(), reading_user, render_opts) +          |> put_status(parent_activity_fn.(), reading_user, status_render_opts)            |> put_emoji(activity)          type when type in ["follow", "follow_request"] -> diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 24167f66f..05a26017a 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -107,9 +107,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do              |> Enum.map(&get_user(&1.data["actor"], false))              |> Enum.filter(& &1) -          UserRelationship.view_relationships_option(reading_user, actors, -            source_mutes_only: opts[:skip_relationships] -          ) +          UserRelationship.view_relationships_option(reading_user, actors, subset: :source_mutes)        end      opts = @@ -162,9 +160,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do        account:          AccountView.render("show.json", %{            user: user, -          for: opts[:for], -          relationships: opts[:relationships], -          skip_relationships: opts[:skip_relationships] +          for: opts[:for]          }),        in_reply_to_id: nil,        in_reply_to_account_id: nil, @@ -330,9 +326,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do        account:          AccountView.render("show.json", %{            user: user, -          for: opts[:for], -          relationships: opts[:relationships], -          skip_relationships: opts[:skip_relationships] +          for: opts[:for]          }),        in_reply_to_id: reply_to && to_string(reply_to.id),        in_reply_to_account_id: reply_to_user && to_string(reply_to_user.id), diff --git a/lib/pleroma/web/pleroma_api/controllers/account_controller.ex b/lib/pleroma/web/pleroma_api/controllers/account_controller.ex index be7477867..3c6a951b9 100644 --- a/lib/pleroma/web/pleroma_api/controllers/account_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/account_controller.ex @@ -6,7 +6,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do    use Pleroma.Web, :controller    import Pleroma.Web.ControllerHelper, -    only: [json_response: 3, add_link_headers: 2, assign_account_by_id: 2, skip_relationships?: 1] +    only: [json_response: 3, add_link_headers: 2, assign_account_by_id: 2]    alias Ecto.Changeset    alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug @@ -139,8 +139,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do      |> render("index.json",        activities: activities,        for: for_user, -      as: :activity, -      skip_relationships: skip_relationships?(params) +      as: :activity      )    end diff --git a/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex b/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex index 8bc77b75e..e834133b2 100644 --- a/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex @@ -5,7 +5,7 @@  defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do    use Pleroma.Web, :controller -  import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2, skip_relationships?: 1] +  import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2]    alias Pleroma.Activity    alias Pleroma.Conversation.Participation @@ -69,7 +69,12 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do              %{                name: emoji,                count: length(users), -              accounts: AccountView.render("index.json", %{users: users, for: user, as: :user}), +              accounts: +                AccountView.render("index.json", %{ +                  users: users, +                  for: user, +                  as: :user +                }),                me: !!(user && user.ap_id in user_ap_ids)              }            end @@ -145,8 +150,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do        |> render("index.json",          activities: activities,          for: user, -        as: :activity, -        skip_relationships: skip_relationships?(params) +        as: :activity        )      else        _error -> @@ -201,7 +205,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do      end    end -  def mark_notifications_as_read(%{assigns: %{user: user}} = conn, %{"max_id" => max_id} = params) do +  def mark_notifications_as_read(%{assigns: %{user: user}} = conn, %{"max_id" => max_id}) do      with notifications <- Notification.set_read_up_to(user, max_id) do        notifications = Enum.take(notifications, 80) @@ -209,8 +213,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do        |> put_view(NotificationView)        |> render("index.json",          notifications: notifications, -        for: user, -        skip_relationships: skip_relationships?(params) +        for: user        )      end    end | 
