66abc186b82a3a26922fe8e56ab46e9e31822077
[akkoma] / lib / pleroma / web / feed / tag_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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" => tag} = params) do
13 activities =
14 %{
15 "type" => ["Create"],
16 "whole_db" => true,
17 "tag" => parse_tag(tag)
18 }
19 |> Map.merge(Map.take(params, ["max_id"]))
20 |> ActivityPub.fetch_public_activities()
21
22 conn
23 |> put_resp_content_type("application/atom+xml")
24 |> put_view(FeedView)
25 |> render("tag.xml", activities: activities, feed_config: Config.get([:feed]))
26 end
27
28 defp parse_tag(raw_tag) when is_binary(raw_tag) do
29 case Enum.reverse(String.split(raw_tag, ".")) do
30 [format | tag] when format in ["atom", "rss"] -> Enum.join(tag, ".")
31 _ -> raw_tag
32 end
33 end
34
35 defp parse_tag(raw_tag), do: raw_tag
36 end