Merge remote-tracking branch 'origin/develop' into activity-pub-use-atoms-as-keys
[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 def feed(conn, %{"tag" => raw_tag} = params) do
13 {format, tag} = parse_tag(raw_tag)
14
15 activities =
16 %{type: ["Create"], tag: tag}
17 |> Pleroma.Maps.put_if_present(:max_id, params["max_id"])
18 |> ActivityPub.fetch_public_activities()
19
20 conn
21 |> put_resp_content_type("application/#{format}+xml")
22 |> put_view(FeedView)
23 |> render("tag.#{format}",
24 activities: activities,
25 tag: tag,
26 feed_config: Config.get([:feed])
27 )
28 end
29
30 @spec parse_tag(binary() | any()) :: {format :: String.t(), tag :: String.t()}
31 defp parse_tag(raw_tag) when is_binary(raw_tag) do
32 case Enum.reverse(String.split(raw_tag, ".")) do
33 [format | tag] when format in ["atom", "rss"] -> {format, Enum.join(tag, ".")}
34 _ -> {"rss", raw_tag}
35 end
36 end
37
38 defp parse_tag(raw_tag), do: {"rss", raw_tag}
39 end