Remove Twemoji stuff from MastoFE
[akkoma] / lib / pleroma / web / feed / user_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Feed.UserController do
6 use Pleroma.Web, :controller
7
8 alias Pleroma.Config
9 alias Pleroma.User
10 alias Pleroma.Web.ActivityPub.ActivityPub
11 alias Pleroma.Web.ActivityPub.ActivityPubController
12 alias Pleroma.Web.Feed.FeedView
13
14 plug(Pleroma.Web.Plugs.SetFormatPlug when action in [:feed_redirect])
15
16 action_fallback(:errors)
17
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})
21 end
22 end
23
24 def feed_redirect(%{assigns: %{format: format}} = conn, _params)
25 when format in ["json", "activity+json"] do
26 ActivityPubController.call(conn, :user)
27 end
28
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")
32 end
33 end
34
35 def feed(conn, %{"nickname" => nickname} = params) do
36 format = get_format(conn)
37
38 format =
39 if format in ["atom", "rss"] do
40 format
41 else
42 "atom"
43 end
44
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
47 activities =
48 %{
49 type: ["Create"],
50 actor_id: user.ap_id
51 }
52 |> Pleroma.Maps.put_if_present(:max_id, params["max_id"])
53 |> ActivityPub.fetch_public_or_unlisted_activities()
54
55 conn
56 |> put_resp_content_type("application/#{format}+xml")
57 |> put_view(FeedView)
58 |> render("user.#{format}",
59 user: user,
60 activities: activities,
61 feed_config: Config.get([:feed])
62 )
63 end
64 end
65
66 def errors(conn, {:error, :not_found}) do
67 render_error(conn, :not_found, "Not found")
68 end
69
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})
72
73 def errors(conn, {:visibility, _}), do: errors(conn, {:error, :not_found})
74
75 def errors(conn, _) do
76 render_error(conn, :internal_server_error, "Something went wrong")
77 end
78 end