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.UserController do
6 use Pleroma.Web, :controller
8 alias Fallback.RedirectController
10 alias Pleroma.Web.ActivityPub.ActivityPub
11 alias Pleroma.Web.ActivityPub.ActivityPubController
12 alias Pleroma.Web.Feed.FeedView
14 import Pleroma.Web.ControllerHelper, only: [put_in_if_exist: 3]
16 plug(Pleroma.Plugs.SetFormatPlug when action in [:feed_redirect])
18 action_fallback(:errors)
20 def feed_redirect(%{assigns: %{format: "html"}} = conn, %{"nickname" => nickname}) do
21 with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname_or_id(nickname)} do
22 RedirectController.redirector_with_meta(conn, %{user: user})
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: "#{user_feed_url(conn, :feed, user.nickname)}.atom")
37 def feed(conn, %{"nickname" => nickname} = params) do
38 with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
40 %{"type" => ["Create"], "whole_db" => true, "actor_id" => user.ap_id}
41 |> put_in_if_exist("max_id", params["max_id"])
42 |> ActivityPub.fetch_public_activities()
45 |> 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")