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})
22 _ -> Pleroma.Web.Fallback.RedirectController.redirector(conn, nil)
26 def feed_redirect(%{assigns: %{format: format}} = conn, _params)
27 when format in ["json", "activity+json"] do
28 ActivityPubController.call(conn, :user)
31 def feed_redirect(conn, %{"nickname" => nickname}) do
32 with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
33 redirect(conn, external: "#{Routes.user_feed_url(conn, :feed, user.nickname)}.atom")
37 def feed(conn, %{"nickname" => nickname} = params) do
38 format = get_format(conn)
41 if format in ["atom", "rss"] do
47 with {_, %User{local: true} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)},
48 {_, :visible} <- {:visibility, User.visible_for(user, _reading_user = nil)} do
54 |> Pleroma.Maps.put_if_present(:max_id, params["max_id"])
55 |> ActivityPub.fetch_public_or_unlisted_activities()
58 |> put_resp_content_type("application/#{format}+xml")
60 |> render("user.#{format}",
62 activities: activities,
63 feed_config: Config.get([:feed]),
69 def errors(conn, {:error, :not_found}) do
70 render_error(conn, :not_found, "Not found")
73 def errors(conn, {:fetch_user, %User{local: false}}), do: errors(conn, {:error, :not_found})
74 def errors(conn, {:fetch_user, nil}), do: errors(conn, {:error, :not_found})
76 def errors(conn, {:visibility, _}), do: errors(conn, {:error, :not_found})
78 def errors(conn, _) do
79 render_error(conn, :internal_server_error, "Something went wrong")