Added support for :skip_notifications for accounts listing (index.json).
Adjusted tests.
favourites = ActivityPub.fetch_favourites(user)
- output_relationships =
- !!Pleroma.Config.get([:extensions, :output_relationships_in_statuses_by_default])
-
Benchee.run(
%{
"Rendering home timeline" => fn ->
StatusView.render("index.json", %{
activities: home_activities,
for: user,
- as: :activity,
- skip_relationships: !output_relationships
+ as: :activity
})
end,
"Rendering direct timeline" => fn ->
StatusView.render("index.json", %{
activities: direct_activities,
for: user,
- as: :activity,
- skip_relationships: !output_relationships
+ as: :activity
})
end,
"Rendering public timeline" => fn ->
StatusView.render("index.json", %{
activities: public_activities,
for: user,
- as: :activity,
- skip_relationships: !output_relationships
+ as: :activity
})
end,
"Rendering tag timeline" => fn ->
StatusView.render("index.json", %{
activities: tag_activities,
for: user,
- as: :activity,
- skip_relationships: !output_relationships
+ as: :activity
})
end,
"Rendering notifications" => fn ->
Pleroma.Web.MastodonAPI.NotificationView.render("index.json", %{
notifications: notifications,
- for: user,
- skip_relationships: !output_relationships
+ for: user
})
end,
"Rendering favourites timeline" => fn ->
StatusView.render("index.json", %{
activities: favourites,
for: user,
- as: :activity,
- skip_relationships: !output_relationships
+ as: :activity
})
end
},
extended_nickname_format: true,
cleanup_attachments: false
-config :pleroma, :extensions, output_relationships_in_statuses_by_default: true
-
config :pleroma, :feed,
post_title: %{
max_length: 100,
Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
activities: activities,
for: user,
- as: :activity,
- skip_relationships: true
+ as: :activity
})
end
},
conn
|> put_view(Pleroma.Web.AdminAPI.StatusView)
- |> render("index.json", %{activities: activities, as: :activity, skip_relationships: false})
+ |> render("index.json", %{activities: activities, as: :activity})
end
def list_user_statuses(conn, %{"nickname" => nickname} = params) do
conn
|> put_view(StatusView)
- |> render("index.json", %{activities: activities, as: :activity, skip_relationships: false})
+ |> render("index.json", %{activities: activities, as: :activity})
else
_ -> {:error, :not_found}
end
conn
|> put_view(Pleroma.Web.AdminAPI.StatusView)
- |> render("index.json", %{activities: activities, as: :activity, skip_relationships: false})
+ |> render("index.json", %{activities: activities, as: :activity})
end
def status_update(%{assigns: %{user: admin}} = conn, %{"id" => id} = params) 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
alias Pleroma.Web.MastodonAPI.StatusView
def render("index.json", %{reports: reports}) 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})
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}))
+ MastodonAPI.AccountView.render("show.json", %{user: user, skip_relationships: true})
+ |> Map.merge(AdminAPI.AccountView.render("show.json", %{user: user}))
end
defp merge_account_views(_), do: %{}
require Pleroma.Constants
alias Pleroma.User
+ alias Pleroma.Web.AdminAPI
+ alias Pleroma.Web.MastodonAPI
alias Pleroma.Web.MastodonAPI.StatusView
def render("index.json", opts) do
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}))
+ MastodonAPI.AccountView.render("show.json", %{user: user, skip_relationships: true})
+ |> Map.merge(AdminAPI.AccountView.render("show.json", %{user: user}))
end
defp merge_account_views(_), 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)
+
+ author =
+ Pleroma.Web.MastodonAPI.AccountView.render("show.json",
+ user: author,
+ skip_relationships: true
+ )
+
message = ChatChannelState.add_message(%{text: text, author: author})
broadcast!(socket, "new_msg", message)
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"]
def put_if_exist(map, key, value), do: Map.put(map, key, value)
- @doc "Whether to skip rendering `[:account][:pleroma][:relationship]`for statuses/notifications"
+ @doc "Whether to skip `account.pleroma.relationship` rendering 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
+ not truthy_param?(params["with_relationships"])
end
end
users: accounts,
for: options[:for_user],
as: :user,
- skip_relationships: false
+ skip_relationships: true
)
end
alias Pleroma.Web.MediaProxy
def render("index.json", %{users: users} = opts) do
+ opts = Map.merge(%{skip_relationships: false}, opts)
+
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[:skip_relationships] ->
UserRelationship.view_relationships_option(nil, [])
true ->
end
defp do_render("show.json", %{user: user} = opts) do
+ opts = Map.merge(%{skip_relationships: false}, opts)
+
user = User.sanitize_html(user, User.html_filter_policy(opts[:for]))
display_name = user.name || user.nickname
alias Pleroma.Web.MastodonAPI.StatusView
def render("index.json", %{notifications: notifications, for: reading_user} = opts) do
+ opts = Map.merge(%{skip_relationships: true}, opts)
+
activities = Enum.map(notifications, & &1.activity)
parent_activities =
for: reading_user
} = opts
) do
+ opts = Map.merge(%{skip_relationships: true}, opts)
+
actor = User.get_cached_by_ap_id(activity.data["actor"])
parent_activity_fn = fn ->
end
def render("index.json", opts) do
+ opts = Map.merge(%{skip_relationships: true}, opts)
+
reading_user = opts[:for]
# To do: check AdminAPIControllerTest on the reasons behind nil activities in the list
"show.json",
%{activity: %{data: %{"type" => "Announce", "object" => _object}} = activity} = opts
) do
+ opts = Map.merge(%{skip_relationships: true}, opts)
+
user = get_user(activity.data["actor"])
created_at = Utils.to_masto_date(activity.data["published"])
activity_object = Object.normalize(activity)
end
def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
+ opts = Map.merge(%{skip_relationships: true}, opts)
+
object = Object.normalize(activity)
user = get_user(activity.data["actor"])
%{
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,
+ skip_relationships: true
+ }),
me: !!(user && user.ap_id in user_ap_ids)
}
end
import Pleroma.Factory
- test "does NOT render account/pleroma/relationship if this is disabled by default" do
- clear_config([:extensions, :output_relationships_in_statuses_by_default], false)
-
+ test "does NOT render account/pleroma/relationship by default" do
%{user: user, conn: conn} = oauth_access(["read:notifications"])
other_user = insert(:user)
end
test "bookmarks" do
- bookmarks_uri = "/api/v1/bookmarks?with_relationships=true"
+ bookmarks_uri = "/api/v1/bookmarks"
%{conn: conn} = oauth_access(["write:bookmarks", "read:bookmarks"])
author = insert(:user)
describe "home" do
setup do: oauth_access(["read:statuses"])
- test "does NOT render account/pleroma/relationship if this is disabled by default", %{
+ test "does NOT render account/pleroma/relationship by default", %{
user: user,
conn: conn
} do
- clear_config([:extensions, :output_relationships_in_statuses_by_default], false)
-
other_user = insert(:user)
{:ok, _} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
end)
end
- test "the home timeline", %{user: user, conn: conn} do
+ test "embeds account relationships with `with_relationships=true`", %{user: user, conn: conn} do
uri = "/api/v1/timelines/home?with_relationships=true"
following = insert(:user, nickname: "followed")
}
}
},
- "account" => %{"pleroma" => %{"relationship" => %{"following" => true}}}
+ "account" => %{
+ "pleroma" => %{
+ "relationship" => %{"following" => true}
+ }
+ }
},
%{
"content" => "post",
"account" => %{
"acct" => "followed",
- "pleroma" => %{"relationship" => %{"following" => true}}
+ "pleroma" => %{
+ "relationship" => %{"following" => true}
+ }
}
}
] = json_response(ret_conn, :ok)
}
}
},
- "account" => %{"pleroma" => %{"relationship" => %{"following" => true}}}
+ "account" => %{
+ "pleroma" => %{
+ "relationship" => %{"following" => true}
+ }
+ }
},
%{
"content" => "post",
"account" => %{
"acct" => "followed",
- "pleroma" => %{"relationship" => %{"following" => true}}
+ "pleroma" => %{
+ "relationship" => %{"following" => true}
+ }
}
}
] = json_response(ret_conn, :ok)
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "mention",
- account: AccountView.render("show.json", %{user: user, for: mentioned_user}),
+ account:
+ AccountView.render("show.json", %{
+ user: user,
+ for: mentioned_user,
+ skip_relationships: true
+ }),
status: StatusView.render("show.json", %{activity: activity, for: mentioned_user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "favourite",
- account: AccountView.render("show.json", %{user: another_user, for: user}),
+ account:
+ AccountView.render("show.json", %{user: another_user, for: user, skip_relationships: true}),
status: StatusView.render("show.json", %{activity: create_activity, for: user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "reblog",
- account: AccountView.render("show.json", %{user: another_user, for: user}),
+ account:
+ AccountView.render("show.json", %{user: another_user, for: user, skip_relationships: true}),
status: StatusView.render("show.json", %{activity: reblog_activity, for: user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "follow",
- account: AccountView.render("show.json", %{user: follower, for: followed}),
+ account:
+ AccountView.render("show.json", %{user: follower, for: followed, skip_relationships: true}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "move",
- account: AccountView.render("show.json", %{user: old_user, for: follower}),
- target: AccountView.render("show.json", %{user: new_user, for: follower}),
+ account:
+ AccountView.render("show.json", %{user: old_user, for: follower, skip_relationships: true}),
+ target:
+ AccountView.render("show.json", %{user: new_user, for: follower, skip_relationships: true}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
pleroma: %{is_seen: false},
type: "pleroma:emoji_reaction",
emoji: "☕",
- account: AccountView.render("show.json", %{user: other_user, for: user}),
+ account:
+ AccountView.render("show.json", %{user: other_user, for: user, skip_relationships: true}),
status: StatusView.render("show.json", %{activity: activity, for: user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
end
end
- test "embeds a relationship in the account" do
+ test "does not embed a relationship in the account" do
user = insert(:user)
other_user = insert(:user)
result = StatusView.render("show.json", %{activity: activity, for: other_user})
- assert result[:account][:pleroma][:relationship] ==
- AccountView.render("relationship.json", %{user: other_user, target: user})
+ assert result[:account][:pleroma][:relationship] == %{}
end
- test "embeds a relationship in the account in reposts" do
+ test "does not embed a relationship in the account in reposts" do
user = insert(:user)
other_user = insert(:user)
result = StatusView.render("show.json", %{activity: activity, for: user})
- assert result[:account][:pleroma][:relationship] ==
- AccountView.render("relationship.json", %{user: user, target: other_user})
-
- assert result[:reblog][:account][:pleroma][:relationship] ==
- AccountView.render("relationship.json", %{user: user, target: user})
+ assert result[:account][:pleroma][:relationship] == %{}
+ assert result[:reblog][:account][:pleroma][:relationship] == %{}
end
test "visibility/list" do