diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/feed/feed_view.ex | 16 | ||||
-rw-r--r-- | lib/pleroma/web/feed/tag_controller.ex | 11 | ||||
-rw-r--r-- | lib/pleroma/web/templates/feed/feed/_activity.xml.eex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/templates/feed/feed/_tag_activity.atom.eex | 51 | ||||
-rw-r--r-- | lib/pleroma/web/templates/feed/feed/_tag_author.atom.eex | 18 | ||||
-rw-r--r-- | lib/pleroma/web/templates/feed/feed/tag.atom.eex | 22 | ||||
-rw-r--r-- | lib/pleroma/web/templates/feed/feed/tag.rss.eex (renamed from lib/pleroma/web/templates/feed/feed/tag.xml.eex) | 0 |
7 files changed, 112 insertions, 8 deletions
diff --git a/lib/pleroma/web/feed/feed_view.ex b/lib/pleroma/web/feed/feed_view.ex index 2e7db1ebb..334802e0a 100644 --- a/lib/pleroma/web/feed/feed_view.ex +++ b/lib/pleroma/web/feed/feed_view.ex @@ -22,16 +22,28 @@ defmodule Pleroma.Web.Feed.FeedView do def pub_date(%DateTime{} = date), do: Timex.format!(date, "{RFC822}") - def prepare_activity(activity) do + def prepare_activity(activity, opts \\ []) do object = activity_object(activity) + actor = + if opts[:actor] do + Pleroma.User.get_cached_by_ap_id(activity.actor) + end + %{ activity: activity, data: Map.get(object, :data), - object: object + object: object, + actor: actor } end + def most_recent_update(activities) do + with %{updated_at: updated_at} <- List.first(activities) do + NaiveDateTime.to_iso8601(updated_at) + end + end + def most_recent_update(activities, user) do (List.first(activities) || user).updated_at |> NaiveDateTime.to_iso8601() diff --git a/lib/pleroma/web/feed/tag_controller.ex b/lib/pleroma/web/feed/tag_controller.ex index 97ce147de..9b722336c 100644 --- a/lib/pleroma/web/feed/tag_controller.ex +++ b/lib/pleroma/web/feed/tag_controller.ex @@ -12,7 +12,7 @@ defmodule Pleroma.Web.Feed.TagController do import Pleroma.Web.ControllerHelper, only: [put_in_if_exist: 3] def feed(conn, %{"tag" => raw_tag} = params) do - tag = parse_tag(raw_tag) + {format, tag} = parse_tag(raw_tag) activities = %{"type" => ["Create"], "whole_db" => true, "tag" => tag} @@ -22,19 +22,20 @@ defmodule Pleroma.Web.Feed.TagController do conn |> put_resp_content_type("application/atom+xml") |> put_view(FeedView) - |> render("tag.xml", + |> render("tag.#{format}", activities: activities, tag: tag, feed_config: Config.get([:feed]) ) end + @spec parse_tag(binary() | any()) :: {format :: String.t(), tag :: String.t()} defp parse_tag(raw_tag) when is_binary(raw_tag) do case Enum.reverse(String.split(raw_tag, ".")) do - [format | tag] when format in ["atom", "rss"] -> Enum.join(tag, ".") - _ -> raw_tag + [format | tag] when format in ["atom", "rss"] -> {format, Enum.join(tag, ".")} + _ -> {"rss", raw_tag} end end - defp parse_tag(raw_tag), do: raw_tag + defp parse_tag(raw_tag), do: {"rss", raw_tag} end diff --git a/lib/pleroma/web/templates/feed/feed/_activity.xml.eex b/lib/pleroma/web/templates/feed/feed/_activity.xml.eex index 514eacaed..ac8a75009 100644 --- a/lib/pleroma/web/templates/feed/feed/_activity.xml.eex +++ b/lib/pleroma/web/templates/feed/feed/_activity.xml.eex @@ -9,7 +9,7 @@ <ostatus:conversation ref="<%= activity_context(@activity) %>"> <%= activity_context(@activity) %> </ostatus:conversation> - <link ref="<%= activity_context(@activity) %>" rel="ostatus:conversation"/> + <link href="<%= activity_context(@activity) %>" rel="ostatus:conversation"/> <%= if @data["summary"] do %> <summary><%= @data["summary"] %></summary> diff --git a/lib/pleroma/web/templates/feed/feed/_tag_activity.atom.eex b/lib/pleroma/web/templates/feed/feed/_tag_activity.atom.eex new file mode 100644 index 000000000..da4fa6d6c --- /dev/null +++ b/lib/pleroma/web/templates/feed/feed/_tag_activity.atom.eex @@ -0,0 +1,51 @@ +<entry> + <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type> + <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb> + + <%= render @view_module, "_tag_author.atom", assigns %> + + <id><%= @data["id"] %></id> + <title><%= activity_title(@object, Keyword.get(@feed_config, :post_title, %{})) %></title> + <content type="html"><%= activity_content(@object) %></content> + + <%= if @activity.local do %> + <link type="application/atom+xml" href='<%= @data["id"] %>' rel="self"/> + <link type="text/html" href='<%= @data["id"] %>' rel="alternate"/> + <% else %> + <link type="text/html" href='<%= @data["external_url"] %>' rel="alternate"/> + <% end %> + + <published><%= @data["published"] %></published> + <updated><%= @data["published"] %></updated> + + <ostatus:conversation ref="<%= activity_context(@activity) %>"> + <%= activity_context(@activity) %> + </ostatus:conversation> + <link href="<%= activity_context(@activity) %>" rel="ostatus:conversation"/> + + <%= if @data["summary"] do %> + <summary><%= @data["summary"] %></summary> + <% end %> + + <%= for id <- @activity.recipients do %> + <%= if id == Pleroma.Constants.as_public() do %> + <link rel="mentioned" + ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" + href="http://activityschema.org/collection/public"/> + <% else %> + <%= unless Regex.match?(~r/^#{Pleroma.Web.base_url()}.+followers$/, id) do %> + <link rel="mentioned" + ostatus:object-type="http://activitystrea.ms/schema/1.0/person" + href="<%= id %>" /> + <% end %> + <% end %> + <% end %> + + <%= for tag <- @data["tag"] || [] do %> + <category term="<%= tag %>"></category> + <% end %> + + <%= for {emoji, file} <- @data["emoji"] || %{} do %> + <link name="<%= emoji %>" rel="emoji" href="<%= file %>"/> + <% end %> +</entry> diff --git a/lib/pleroma/web/templates/feed/feed/_tag_author.atom.eex b/lib/pleroma/web/templates/feed/feed/_tag_author.atom.eex new file mode 100644 index 000000000..997c4936e --- /dev/null +++ b/lib/pleroma/web/templates/feed/feed/_tag_author.atom.eex @@ -0,0 +1,18 @@ +<author> + <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type> + <id><%= @actor.ap_id %></id> + <uri><%= @actor.ap_id %></uri> + <name><%= @actor.nickname %></name> + <summary><%= escape(@actor.bio) %></summary> + <link rel="avatar" href="<%= User.avatar_url(@actor) %>"/> + <%= if User.banner_url(@actor) do %> + <link rel="header" href="<%= User.banner_url(@actor) %>"/> + <% end %> + <%= if @actor.local do %> + <ap_enabled>true</ap_enabled> + <% end %> + + <poco:preferredUsername><%= @actor.nickname %></poco:preferredUsername> + <poco:displayName><%= @actor.name %></poco:displayName> + <poco:note><%= escape(@actor.bio) %></poco:note> +</author> diff --git a/lib/pleroma/web/templates/feed/feed/tag.atom.eex b/lib/pleroma/web/templates/feed/feed/tag.atom.eex new file mode 100644 index 000000000..a288539ed --- /dev/null +++ b/lib/pleroma/web/templates/feed/feed/tag.atom.eex @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" + xmlns:thr="http://purl.org/syndication/thread/1.0" + xmlns:georss="http://www.georss.org/georss" + xmlns:activity="http://activitystrea.ms/spec/1.0/" + xmlns:media="http://purl.org/syndication/atommedia" + xmlns:poco="http://portablecontacts.net/spec/1.0" + xmlns:ostatus="http://ostatus.org/schema/1.0" + xmlns:statusnet="http://status.net/schema/api/1/"> + + <id><%= '#{tag_feed_url(@conn, :feed, @tag)}.rss' %></id> + <title>#<%= @tag %></title> + + <subtitle>These are public toots tagged with #<%= @tag %>. You can interact with them if you have an account anywhere in the fediverse.</subtitle> + <logo><%= feed_logo() %></logo> + <updated><%= most_recent_update(@activities) %></updated> + <link rel="self" href="<%= '#{tag_feed_url(@conn, :feed, @tag)}.atom' %>" type="application/atom+xml"/> + <%= for activity <- @activities do %> + <%= render @view_module, "_tag_activity.atom", Map.merge(assigns, prepare_activity(activity, actor: true)) %> + <% end %> +</feed> diff --git a/lib/pleroma/web/templates/feed/feed/tag.xml.eex b/lib/pleroma/web/templates/feed/feed/tag.rss.eex index eeda01a04..eeda01a04 100644 --- a/lib/pleroma/web/templates/feed/feed/tag.xml.eex +++ b/lib/pleroma/web/templates/feed/feed/tag.rss.eex |