diff --git a/CHANGELOG.md b/CHANGELOG.md
index c133cd9ec..feb3f9b3c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -86,6 +86,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Mastodon API: `/api/v1/update_credentials` accepts `actor_type` field.
- Captcha: Support native provider
- Captcha: Enable by default
+- Configuration: `feed.logo` option for tag feed.
+- Tag feed: `/tags/:tag.rss` - list public statuses by hashtag.
### Fixed
diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex
index 9a4e322c9..e3d7a465b 100644
--- a/lib/pleroma/web/controller_helper.ex
+++ b/lib/pleroma/web/controller_helper.ex
@@ -76,8 +76,7 @@ def assign_account_by_id(%{params: %{"id" => id}} = conn, _) do
end
end
- def try_render(conn, target, params)
- when is_binary(target) do
+ def try_render(conn, target, params) when is_binary(target) do
case render(conn, target, params) do
nil -> render_error(conn, :not_implemented, "Can't display this activity")
res -> res
@@ -87,4 +86,8 @@ def try_render(conn, target, params)
def try_render(conn, _, _) do
render_error(conn, :not_implemented, "Can't display this activity")
end
+
+ @spec put_in_if_exist(map(), atom() | String.t(), any) :: map()
+ def put_in_if_exist(map, _key, nil), do: map
+ def put_in_if_exist(map, key, value), do: put_in(map, key, value)
end
diff --git a/lib/pleroma/web/feed/feed_view.ex b/lib/pleroma/web/feed/feed_view.ex
index bb1332fd3..2e7db1ebb 100644
--- a/lib/pleroma/web/feed/feed_view.ex
+++ b/lib/pleroma/web/feed/feed_view.ex
@@ -13,6 +13,15 @@ defmodule Pleroma.Web.Feed.FeedView do
require Pleroma.Constants
+ @spec pub_date(String.t() | DateTime.t()) :: String.t()
+ def pub_date(date) when is_binary(date) do
+ date
+ |> Timex.parse!("{ISO:Extended}")
+ |> pub_date
+ end
+
+ def pub_date(%DateTime{} = date), do: Timex.format!(date, "{RFC822}")
+
def prepare_activity(activity) do
object = activity_object(activity)
@@ -28,6 +37,17 @@ def most_recent_update(activities, user) do
|> NaiveDateTime.to_iso8601()
end
+ def feed_logo do
+ case Pleroma.Config.get([:feed, :logo]) do
+ nil ->
+ "#{Pleroma.Web.base_url()}/static/logo.png"
+
+ logo ->
+ "#{Pleroma.Web.base_url()}#{logo}"
+ end
+ |> MediaProxy.url()
+ end
+
def logo(user) do
user
|> User.avatar_url()
@@ -40,6 +60,8 @@ def activity_object(activity), do: Object.normalize(activity)
def activity_title(%{data: %{"content" => content}}, opts \\ %{}) do
content
+ |> Pleroma.Web.Metadata.Utils.scrub_html()
+ |> Pleroma.Emoji.Formatter.demojify()
|> Formatter.truncate(opts[:max_length], opts[:omission])
|> escape()
end
@@ -50,6 +72,8 @@ def activity_content(%{data: %{"content" => content}}) do
|> escape()
end
+ def activity_content(_), do: ""
+
def activity_context(activity), do: activity.data["context"]
def attachment_href(attachment) do
diff --git a/lib/pleroma/web/feed/tag_controller.ex b/lib/pleroma/web/feed/tag_controller.ex
index 66abc186b..97ce147de 100644
--- a/lib/pleroma/web/feed/tag_controller.ex
+++ b/lib/pleroma/web/feed/tag_controller.ex
@@ -9,20 +9,24 @@ defmodule Pleroma.Web.Feed.TagController do
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.Feed.FeedView
- def feed(conn, %{"tag" => tag} = params) do
+ import Pleroma.Web.ControllerHelper, only: [put_in_if_exist: 3]
+
+ def feed(conn, %{"tag" => raw_tag} = params) do
+ tag = parse_tag(raw_tag)
+
activities =
- %{
- "type" => ["Create"],
- "whole_db" => true,
- "tag" => parse_tag(tag)
- }
- |> Map.merge(Map.take(params, ["max_id"]))
+ %{"type" => ["Create"], "whole_db" => true, "tag" => tag}
+ |> put_in_if_exist("max_id", params["max_id"])
|> ActivityPub.fetch_public_activities()
conn
|> put_resp_content_type("application/atom+xml")
|> put_view(FeedView)
- |> render("tag.xml", activities: activities, feed_config: Config.get([:feed]))
+ |> render("tag.xml",
+ activities: activities,
+ tag: tag,
+ feed_config: Config.get([:feed])
+ )
end
defp parse_tag(raw_tag) when is_binary(raw_tag) do
diff --git a/lib/pleroma/web/feed/user_controller.ex b/lib/pleroma/web/feed/user_controller.ex
index e5d8427ce..cf04fd497 100644
--- a/lib/pleroma/web/feed/user_controller.ex
+++ b/lib/pleroma/web/feed/user_controller.ex
@@ -11,6 +11,8 @@ defmodule Pleroma.Web.Feed.UserController do
alias Pleroma.Web.ActivityPub.ActivityPubController
alias Pleroma.Web.Feed.FeedView
+ import Pleroma.Web.ControllerHelper, only: [put_in_if_exist: 3]
+
plug(Pleroma.Plugs.SetFormatPlug when action in [:feed_redirect])
action_fallback(:errors)
@@ -35,12 +37,8 @@ def feed_redirect(conn, %{"nickname" => nickname}) do
def feed(conn, %{"nickname" => nickname} = params) do
with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
activities =
- %{
- "type" => ["Create"],
- "whole_db" => true,
- "actor_id" => user.ap_id
- }
- |> Map.merge(Map.take(params, ["max_id"]))
+ %{"type" => ["Create"], "whole_db" => true, "actor_id" => user.ap_id}
+ |> put_in_if_exist("max_id", params["max_id"])
|> ActivityPub.fetch_public_activities()
conn
diff --git a/lib/pleroma/web/metadata/utils.ex b/lib/pleroma/web/metadata/utils.ex
index 382ecf426..c0dae1b7e 100644
--- a/lib/pleroma/web/metadata/utils.ex
+++ b/lib/pleroma/web/metadata/utils.ex
@@ -19,15 +19,22 @@ def scrub_html_and_truncate(%{data: %{"content" => content}} = object) do
end
def scrub_html_and_truncate(content, max_length \\ 200) when is_binary(content) do
+ content
+ |> scrub_html
+ |> Emoji.Formatter.demojify()
+ |> Formatter.truncate(max_length)
+ end
+
+ def scrub_html(content) when is_binary(content) do
content
# html content comes from DB already encoded, decode first and scrub after
|> HtmlEntities.decode()
|> String.replace(~r/
/, " ")
|> HTML.strip_tags()
- |> Emoji.Formatter.demojify()
- |> Formatter.truncate(max_length)
end
+ def scrub_html(content), do: content
+
def attachment_url(url) do
MediaProxy.url(url)
end
diff --git a/lib/pleroma/web/templates/feed/feed/_tag_activity.xml.eex b/lib/pleroma/web/templates/feed/feed/_tag_activity.xml.eex
new file mode 100644
index 000000000..295574df1
--- /dev/null
+++ b/lib/pleroma/web/templates/feed/feed/_tag_activity.xml.eex
@@ -0,0 +1,15 @@
+