Merge branch 'features/openrc-console' into 'develop'
[akkoma] / lib / pleroma / web / feed / tag_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Feed.TagController do
6 use Pleroma.Web, :controller
7
8 alias Pleroma.Config
9 alias Pleroma.Web.ActivityPub.ActivityPub
10 alias Pleroma.Web.Feed.FeedView
11
12 import Pleroma.Web.ControllerHelper, only: [put_if_exist: 3]
13
14 def feed(conn, %{"tag" => raw_tag} = params) do
15 {format, tag} = parse_tag(raw_tag)
16
17 activities =
18 %{"type" => ["Create"], "tag" => tag}
19 |> put_if_exist("max_id", params["max_id"])
20 |> ActivityPub.fetch_public_activities()
21
22 conn
23 |> put_resp_content_type("application/#{format}+xml")
24 |> put_view(FeedView)
25 |> render("tag.#{format}",
26 activities: activities,
27 tag: tag,
28 feed_config: Config.get([:feed])
29 )
30 end
31
32 @spec parse_tag(binary() | any()) :: {format :: String.t(), tag :: String.t()}
33 defp parse_tag(raw_tag) when is_binary(raw_tag) do
34 case Enum.reverse(String.split(raw_tag, ".")) do
35 [format | tag] when format in ["atom", "rss"] -> {format, Enum.join(tag, ".")}
36 _ -> {"rss", raw_tag}
37 end
38 end
39
40 defp parse_tag(raw_tag), do: {"rss", raw_tag}
41 end