2019-12-06 06:32:29 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.Feed.TagController do
|
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
|
|
|
alias Pleroma.Config
|
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
|
|
alias Pleroma.Web.Feed.FeedView
|
|
|
|
|
2019-12-17 19:13:45 +00:00
|
|
|
import Pleroma.Web.ControllerHelper, only: [put_in_if_exist: 3]
|
|
|
|
|
|
|
|
def feed(conn, %{"tag" => raw_tag} = params) do
|
2020-01-24 19:08:10 +00:00
|
|
|
{format, tag} = parse_tag(raw_tag)
|
2019-12-17 19:13:45 +00:00
|
|
|
|
2019-12-06 06:32:29 +00:00
|
|
|
activities =
|
2020-01-28 13:38:49 +00:00
|
|
|
%{"type" => ["Create"], "tag" => tag}
|
2019-12-17 19:13:45 +00:00
|
|
|
|> put_in_if_exist("max_id", params["max_id"])
|
2019-12-06 06:32:29 +00:00
|
|
|
|> ActivityPub.fetch_public_activities()
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_resp_content_type("application/atom+xml")
|
|
|
|
|> put_view(FeedView)
|
2020-01-24 19:08:10 +00:00
|
|
|
|> render("tag.#{format}",
|
2019-12-17 19:13:45 +00:00
|
|
|
activities: activities,
|
|
|
|
tag: tag,
|
|
|
|
feed_config: Config.get([:feed])
|
|
|
|
)
|
2019-12-06 06:32:29 +00:00
|
|
|
end
|
|
|
|
|
2020-01-24 19:08:10 +00:00
|
|
|
@spec parse_tag(binary() | any()) :: {format :: String.t(), tag :: String.t()}
|
2019-12-06 06:32:29 +00:00
|
|
|
defp parse_tag(raw_tag) when is_binary(raw_tag) do
|
|
|
|
case Enum.reverse(String.split(raw_tag, ".")) do
|
2020-01-24 19:08:10 +00:00
|
|
|
[format | tag] when format in ["atom", "rss"] -> {format, Enum.join(tag, ".")}
|
|
|
|
_ -> {"rss", raw_tag}
|
2019-12-06 06:32:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-24 19:08:10 +00:00
|
|
|
defp parse_tag(raw_tag), do: {"rss", raw_tag}
|
2019-12-06 06:32:29 +00:00
|
|
|
end
|