adding rss for user feed
This commit is contained in:
parent
26e2076659
commit
91870c8995
@ -40,6 +40,15 @@ defmodule Pleroma.Web.Feed.UserController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def feed(conn, %{"nickname" => nickname} = params) do
|
def feed(conn, %{"nickname" => nickname} = params) do
|
||||||
|
format = get_format(conn)
|
||||||
|
|
||||||
|
format =
|
||||||
|
if format in ["rss", "atom"] do
|
||||||
|
format
|
||||||
|
else
|
||||||
|
"atom"
|
||||||
|
end
|
||||||
|
|
||||||
with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
|
with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
|
||||||
activities =
|
activities =
|
||||||
%{
|
%{
|
||||||
@ -50,9 +59,9 @@ defmodule Pleroma.Web.Feed.UserController do
|
|||||||
|> ActivityPub.fetch_public_activities()
|
|> ActivityPub.fetch_public_activities()
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/atom+xml")
|
|> put_resp_content_type("application/#{format}+xml")
|
||||||
|> put_view(FeedView)
|
|> put_view(FeedView)
|
||||||
|> render("user.xml",
|
|> render("user.#{format}",
|
||||||
user: user,
|
user: user,
|
||||||
activities: activities,
|
activities: activities,
|
||||||
feed_config: Pleroma.Config.get([:feed])
|
feed_config: Pleroma.Config.get([:feed])
|
||||||
|
@ -513,7 +513,7 @@ defmodule Pleroma.Web.Router do
|
|||||||
end
|
end
|
||||||
|
|
||||||
pipeline :ostatus do
|
pipeline :ostatus do
|
||||||
plug(:accepts, ["html", "xml", "atom", "activity+json", "json"])
|
plug(:accepts, ["html", "xml", "rss", "atom", "activity+json", "json"])
|
||||||
plug(Pleroma.Plugs.StaticFEPlug)
|
plug(Pleroma.Plugs.StaticFEPlug)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
49
lib/pleroma/web/templates/feed/feed/_activity.rss.eex
Normal file
49
lib/pleroma/web/templates/feed/feed/_activity.rss.eex
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<item>
|
||||||
|
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
|
||||||
|
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
|
||||||
|
<guid><%= @data["id"] %></guid>
|
||||||
|
<title><%= activity_title(@object, Keyword.get(@feed_config, :post_title, %{})) %></title>
|
||||||
|
<description><%= activity_content(@object) %></description>
|
||||||
|
<pubDate><%= @data["published"] %></pubDate>
|
||||||
|
<updated><%= @data["published"] %></updated>
|
||||||
|
<ostatus:conversation ref="<%= activity_context(@activity) %>">
|
||||||
|
<%= activity_context(@activity) %>
|
||||||
|
</ostatus:conversation>
|
||||||
|
<link rel="ostatus:conversation"><%= activity_context(@activity) %></link>
|
||||||
|
|
||||||
|
<%= if @data["summary"] do %>
|
||||||
|
<description><%= @data["summary"] %></description>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= if @activity.local do %>
|
||||||
|
<link><%= @data["id"] %></link>
|
||||||
|
<% else %>
|
||||||
|
<link><%= @data["external_url"] %></link>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= for tag <- @data["tag"] || [] do %>
|
||||||
|
<category term="<%= tag %>"></category>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= for attachment <- @data["attachment"] || [] do %>
|
||||||
|
<link type="<%= attachment_type(attachment) %>"><%= attachment_href(attachment) %></link>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= if @data["inReplyTo"] do %>
|
||||||
|
<thr:in-reply-to ref='<%= @data["inReplyTo"] %>' href='<%= get_href(@data["inReplyTo"]) %>'/>
|
||||||
|
<% 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">http://activityschema.org/collection/public</link>
|
||||||
|
<% 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"><%= id %></link>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= for {emoji, file} <- @data["emoji"] || %{} do %>
|
||||||
|
<link name="<%= emoji %>" rel="emoji"><%= file %></link>
|
||||||
|
<% end %>
|
||||||
|
</item>
|
17
lib/pleroma/web/templates/feed/feed/_author.rss.eex
Normal file
17
lib/pleroma/web/templates/feed/feed/_author.rss.eex
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<managingEditor>
|
||||||
|
<guid><%= @user.ap_id %></guid>
|
||||||
|
<activity:object>http://activitystrea.ms/schema/1.0/person</activity:object>
|
||||||
|
<uri><%= @user.ap_id %></uri>
|
||||||
|
<poco:preferredUsername><%= @user.nickname %></poco:preferredUsername>
|
||||||
|
<poco:displayName><%= @user.name %></poco:displayName>
|
||||||
|
<poco:note><%= escape(@user.bio) %></poco:note>
|
||||||
|
<description><%= escape(@user.bio) %></description>
|
||||||
|
<name><%= @user.nickname %></name>
|
||||||
|
<link rel="avatar"><%= User.avatar_url(@user) %></link>
|
||||||
|
<%= if User.banner_url(@user) do %>
|
||||||
|
<link rel="header"><%= User.banner_url(@user) %></link>
|
||||||
|
<% end %>
|
||||||
|
<%= if @user.local do %>
|
||||||
|
<ap_enabled>true</ap_enabled>
|
||||||
|
<% end %>
|
||||||
|
</managingEditor>
|
@ -12,13 +12,13 @@
|
|||||||
<logo><%= logo(@user) %></logo>
|
<logo><%= logo(@user) %></logo>
|
||||||
<link rel="self" href="<%= '#{user_feed_url(@conn, :feed, @user.nickname)}.atom' %>" type="application/atom+xml"/>
|
<link rel="self" href="<%= '#{user_feed_url(@conn, :feed, @user.nickname)}.atom' %>" type="application/atom+xml"/>
|
||||||
|
|
||||||
<%= render @view_module, "_author.xml", assigns %>
|
<%= render @view_module, "_author.atom", assigns %>
|
||||||
|
|
||||||
<%= if last_activity(@activities) do %>
|
<%= if last_activity(@activities) do %>
|
||||||
<link rel="next" href="<%= '#{user_feed_url(@conn, :feed, @user.nickname)}.atom?max_id=#{last_activity(@activities).id}' %>" type="application/atom+xml"/>
|
<link rel="next" href="<%= '#{user_feed_url(@conn, :feed, @user.nickname)}.atom?max_id=#{last_activity(@activities).id}' %>" type="application/atom+xml"/>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= for activity <- @activities do %>
|
<%= for activity <- @activities do %>
|
||||||
<%= render @view_module, "_activity.xml", Map.merge(assigns, prepare_activity(activity)) %>
|
<%= render @view_module, "_activity.atom", Map.merge(assigns, prepare_activity(activity)) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</feed>
|
</feed>
|
20
lib/pleroma/web/templates/feed/feed/user.rss.eex
Normal file
20
lib/pleroma/web/templates/feed/feed/user.rss.eex
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<rss version="2.0">
|
||||||
|
<channel>
|
||||||
|
<guid><%= user_feed_url(@conn, :feed, @user.nickname) <> ".rss" %></guid>
|
||||||
|
<title><%= @user.nickname <> "'s timeline" %></title>
|
||||||
|
<updated><%= most_recent_update(@activities, @user) %></updated>
|
||||||
|
<image><%= logo(@user) %></image>
|
||||||
|
<link><%= '#{user_feed_url(@conn, :feed, @user.nickname)}.rss' %></link>
|
||||||
|
|
||||||
|
<%= render @view_module, "_author.rss", assigns %>
|
||||||
|
|
||||||
|
<%= if last_activity(@activities) do %>
|
||||||
|
<link rel="next"><%= '#{user_feed_url(@conn, :feed, @user.nickname)}.rss?max_id=#{last_activity(@activities).id}' %></link>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= for activity <- @activities do %>
|
||||||
|
<%= render @view_module, "_activity.rss", Map.merge(assigns, prepare_activity(activity)) %>
|
||||||
|
<% end %>
|
||||||
|
</channel>
|
||||||
|
</rss>
|
@ -19,7 +19,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||||||
describe "feed" do
|
describe "feed" do
|
||||||
clear_config([:feed])
|
clear_config([:feed])
|
||||||
|
|
||||||
test "gets a feed", %{conn: conn} do
|
test "gets an atom feed", %{conn: conn} do
|
||||||
Config.put(
|
Config.put(
|
||||||
[:feed, :post_title],
|
[:feed, :post_title],
|
||||||
%{max_length: 10, omission: "..."}
|
%{max_length: 10, omission: "..."}
|
||||||
@ -59,7 +59,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||||||
|
|
||||||
resp =
|
resp =
|
||||||
conn
|
conn
|
||||||
|> put_req_header("content-type", "application/atom+xml")
|
|> put_req_header("accept", "application/atom+xml")
|
||||||
|> get(user_feed_path(conn, :feed, user.nickname))
|
|> get(user_feed_path(conn, :feed, user.nickname))
|
||||||
|> response(200)
|
|> response(200)
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||||||
|
|
||||||
resp =
|
resp =
|
||||||
conn
|
conn
|
||||||
|> put_req_header("content-type", "application/atom+xml")
|
|> put_req_header("accept", "application/atom+xml")
|
||||||
|> get("/users/#{user.nickname}/feed", %{"max_id" => note_activity2.id})
|
|> get("/users/#{user.nickname}/feed", %{"max_id" => note_activity2.id})
|
||||||
|> response(200)
|
|> response(200)
|
||||||
|
|
||||||
@ -85,10 +85,76 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||||||
assert activity_titles == ['This is...']
|
assert activity_titles == ['This is...']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "gets a rss feed", %{conn: conn} do
|
||||||
|
Pleroma.Config.put(
|
||||||
|
[:feed, :post_title],
|
||||||
|
%{max_length: 10, omission: "..."}
|
||||||
|
)
|
||||||
|
|
||||||
|
activity = insert(:note_activity)
|
||||||
|
|
||||||
|
note =
|
||||||
|
insert(:note,
|
||||||
|
data: %{
|
||||||
|
"content" => "This is :moominmamma: note ",
|
||||||
|
"attachment" => [
|
||||||
|
%{
|
||||||
|
"url" => [
|
||||||
|
%{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"inReplyTo" => activity.data["id"]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
note_activity = insert(:note_activity, note: note)
|
||||||
|
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||||
|
|
||||||
|
note2 =
|
||||||
|
insert(:note,
|
||||||
|
user: user,
|
||||||
|
data: %{
|
||||||
|
"content" => "42 This is :moominmamma: note ",
|
||||||
|
"inReplyTo" => activity.data["id"]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
note_activity2 = insert(:note_activity, note: note2)
|
||||||
|
object = Object.normalize(note_activity)
|
||||||
|
|
||||||
|
resp =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/rss+xml")
|
||||||
|
|> get("/users/#{user.nickname}/feed.rss")
|
||||||
|
|> response(200)
|
||||||
|
|
||||||
|
activity_titles =
|
||||||
|
resp
|
||||||
|
|> SweetXml.parse()
|
||||||
|
|> SweetXml.xpath(~x"//item/title/text()"l)
|
||||||
|
|
||||||
|
assert activity_titles == ['42 This...', 'This is...']
|
||||||
|
assert resp =~ object.data["content"]
|
||||||
|
|
||||||
|
resp =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/atom+xml")
|
||||||
|
|> get("/users/#{user.nickname}/feed.rss", %{"max_id" => note_activity2.id})
|
||||||
|
|> response(200)
|
||||||
|
|
||||||
|
activity_titles =
|
||||||
|
resp
|
||||||
|
|> SweetXml.parse()
|
||||||
|
|> SweetXml.xpath(~x"//item/title/text()"l)
|
||||||
|
|
||||||
|
assert activity_titles == ['This is...']
|
||||||
|
end
|
||||||
|
|
||||||
test "returns 404 for a missing feed", %{conn: conn} do
|
test "returns 404 for a missing feed", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|> put_req_header("content-type", "application/atom+xml")
|
|> put_req_header("accept", "application/atom+xml")
|
||||||
|> get(user_feed_path(conn, :feed, "nonexisting"))
|
|> get(user_feed_path(conn, :feed, "nonexisting"))
|
||||||
|
|
||||||
assert response(conn, 404)
|
assert response(conn, 404)
|
||||||
|
Loading…
Reference in New Issue
Block a user