1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Feed.FeedController do
6 use Pleroma.Web, :controller
8 alias Fallback.RedirectController
10 alias Pleroma.Web.ActivityPub.ActivityPub
11 alias Pleroma.Web.ActivityPub.ActivityPubController
13 plug(Pleroma.Plugs.SetFormatPlug when action in [:feed_redirect])
15 action_fallback(:errors)
17 def feed_redirect(%{assigns: %{format: "html"}} = conn, %{"nickname" => nickname}) do
18 with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname_or_id(nickname)} do
19 RedirectController.redirector_with_meta(conn, %{user: user})
23 def feed_redirect(%{assigns: %{format: format}} = conn, _params)
24 when format in ["json", "activity+json"] do
25 ActivityPubController.call(conn, :user)
28 def feed_redirect(conn, %{"nickname" => nickname}) do
29 with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
30 redirect(conn, external: "#{feed_url(conn, :feed, user.nickname)}.atom")
34 def feed(conn, %{"nickname" => nickname} = params) do
35 with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
40 "actor_id" => user.ap_id
42 |> Map.merge(Map.take(params, ["max_id"]))
43 |> ActivityPub.fetch_public_activities()
46 |> put_resp_content_type("application/atom+xml")
49 activities: activities,
50 feed_config: Pleroma.Config.get([:feed])
55 def errors(conn, {:error, :not_found}) do
56 render_error(conn, :not_found, "Not found")
59 def errors(conn, {:fetch_user, nil}), do: errors(conn, {:error, :not_found})
61 def errors(conn, _) do
62 render_error(conn, :internal_server_error, "Something went wrong")