1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Feed.UserController do
6 use Pleroma.Web, :controller
10 alias Pleroma.Web.ActivityPub.ActivityPub
11 alias Pleroma.Web.ActivityPub.ActivityPubController
12 alias Pleroma.Web.Feed.FeedView
14 plug(Pleroma.Web.Plugs.SetFormatPlug when action in [:feed_redirect])
16 action_fallback(:errors)
18 def feed_redirect(%{assigns: %{format: "html"}} = conn, %{"nickname" => nickname}) do
19 with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname_or_id(nickname)} do
20 Pleroma.Web.Fallback.RedirectController.redirector_with_meta(conn, %{user: user})
24 def feed_redirect(%{assigns: %{format: format}} = conn, _params)
25 when format in ["json", "activity+json"] do
26 ActivityPubController.call(conn, :user)
29 def feed_redirect(conn, %{"nickname" => nickname}) do
30 with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
31 redirect(conn, external: "#{user_feed_url(conn, :feed, user.nickname)}.atom")
35 def feed(conn, %{"nickname" => nickname} = params) do
36 format = get_format(conn)
39 if format in ["atom", "rss"] do
45 with {_, %User{local: true} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)},
46 {_, :visible} <- {:visibility, User.visible_for(user, _reading_user = nil)} do
52 |> Pleroma.Maps.put_if_present(:max_id, params["max_id"])
53 |> ActivityPub.fetch_public_or_unlisted_activities()
56 |> put_resp_content_type("application/#{format}+xml")
58 |> render("user.#{format}",
60 activities: activities,
61 feed_config: Config.get([:feed])
66 def errors(conn, {:error, :not_found}) do
67 render_error(conn, :not_found, "Not found")
70 def errors(conn, {:fetch_user, %User{local: false}}), do: errors(conn, {:error, :not_found})
71 def errors(conn, {:fetch_user, nil}), do: errors(conn, {:error, :not_found})
73 def errors(conn, {:visibility, _}), do: errors(conn, {:error, :not_found})
75 def errors(conn, _) do
76 render_error(conn, :internal_server_error, "Something went wrong")