Commit 9d0b9895 authored by Maksim's avatar Maksim

add subject to atom feed

parent 27867422
...@@ -58,6 +58,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ...@@ -58,6 +58,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Pleroma API: `POST /api/v1/pleroma/conversations/read` to mark all conversations as read - Pleroma API: `POST /api/v1/pleroma/conversations/read` to mark all conversations as read
- Mastodon API: Add `/api/v1/markers` for managing timeline read markers - Mastodon API: Add `/api/v1/markers` for managing timeline read markers
- Mastodon API: Add the `recipients` parameter to `GET /api/v1/conversations` - Mastodon API: Add the `recipients` parameter to `GET /api/v1/conversations`
- Configuration: `feed` option for user atom feed.
</details> </details>
### Fixed ### Fixed
......
...@@ -276,6 +276,12 @@ config :pleroma, :instance, ...@@ -276,6 +276,12 @@ config :pleroma, :instance,
external_user_synchronization: true, external_user_synchronization: true,
extended_nickname_format: false extended_nickname_format: false
config :pleroma, :feed,
post_title: %{
max_length: 100,
omission: "..."
}
config :pleroma, :markup, config :pleroma, :markup,
# XXX - unfortunately, inline images must be enabled by default right now, because # XXX - unfortunately, inline images must be enabled by default right now, because
# of custom emoji. Issue #275 discusses defanging that somehow. # of custom emoji. Issue #275 discusses defanging that somehow.
......
...@@ -568,7 +568,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do ...@@ -568,7 +568,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|> fetch_activities_query(opts) |> fetch_activities_query(opts)
|> restrict_unlisted() |> restrict_unlisted()
|> Pagination.fetch_paginated(opts, pagination) |> Pagination.fetch_paginated(opts, pagination)
|> Enum.reverse()
end end
@valid_visibilities ~w[direct unlisted public private] @valid_visibilities ~w[direct unlisted public private]
......
...@@ -33,21 +33,22 @@ defmodule Pleroma.Web.Feed.FeedController do ...@@ -33,21 +33,22 @@ defmodule Pleroma.Web.Feed.FeedController do
def feed(conn, %{"nickname" => nickname} = params) do def feed(conn, %{"nickname" => nickname} = params) do
with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
query_params =
params
|> Map.take(["max_id"])
|> Map.put("type", ["Create"])
|> Map.put("whole_db", true)
|> Map.put("actor_id", user.ap_id)
activities = activities =
query_params %{
"type" => ["Create"],
"whole_db" => true,
"actor_id" => user.ap_id
}
|> Map.merge(Map.take(params, ["max_id"]))
|> ActivityPub.fetch_public_activities() |> ActivityPub.fetch_public_activities()
|> Enum.reverse()
conn conn
|> put_resp_content_type("application/atom+xml") |> put_resp_content_type("application/atom+xml")
|> render("feed.xml", user: user, activities: activities) |> render("feed.xml",
user: user,
activities: activities,
feed_config: Pleroma.Config.get([:feed])
)
end end
end end
......
...@@ -6,12 +6,23 @@ defmodule Pleroma.Web.Feed.FeedView do ...@@ -6,12 +6,23 @@ defmodule Pleroma.Web.Feed.FeedView do
use Phoenix.HTML use Phoenix.HTML
use Pleroma.Web, :view use Pleroma.Web, :view
alias Pleroma.Formatter
alias Pleroma.Object alias Pleroma.Object
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.MediaProxy alias Pleroma.Web.MediaProxy
require Pleroma.Constants require Pleroma.Constants
def prepare_activity(activity) do
object = activity_object(activity)
%{
activity: activity,
data: Map.get(object, :data),
object: object
}
end
def most_recent_update(activities, user) do def most_recent_update(activities, user) do
(List.first(activities) || user).updated_at (List.first(activities) || user).updated_at
|> NaiveDateTime.to_iso8601() |> NaiveDateTime.to_iso8601()
...@@ -23,31 +34,23 @@ defmodule Pleroma.Web.Feed.FeedView do ...@@ -23,31 +34,23 @@ defmodule Pleroma.Web.Feed.FeedView do
|> MediaProxy.url() |> MediaProxy.url()
end end
def last_activity(activities) do def last_activity(activities), do: List.last(activities)
List.last(activities)
end
def activity_object(activity) do def activity_object(activity), do: Object.normalize(activity)
Object.normalize(activity)
end
def activity_object_data(activity) do def activity_title(%{data: %{"content" => content}}, opts \\ %{}) do
activity content
|> activity_object() |> Formatter.truncate(opts[:max_length], opts[:omission])
|> Map.get(:data) |> escape()
end end
def activity_content(activity) do def activity_content(%{data: %{"content" => content}}) do
content = activity_object_data(activity)["content"]
content content
|> String.replace(~r/[\n\r]/, "") |> String.replace(~r/[\n\r]/, "")
|> escape() |> escape()
end end
def activity_context(activity) do def activity_context(activity), do: activity.data["context"]
activity.data["context"]
end
def attachment_href(attachment) do def attachment_href(attachment) do
attachment["url"] attachment["url"]
......
...@@ -71,7 +71,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do ...@@ -71,7 +71,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|> Map.put("blocking_user", user) |> Map.put("blocking_user", user)
|> Map.put("muting_user", user) |> Map.put("muting_user", user)
|> ActivityPub.fetch_public_activities() |> ActivityPub.fetch_public_activities()
|> Enum.reverse()
conn conn
|> add_link_headers(activities, %{"local" => local_only}) |> add_link_headers(activities, %{"local" => local_only})
...@@ -110,7 +109,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do ...@@ -110,7 +109,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|> Map.put("tag_all", tag_all) |> Map.put("tag_all", tag_all)
|> Map.put("tag_reject", tag_reject) |> Map.put("tag_reject", tag_reject)
|> ActivityPub.fetch_public_activities() |> ActivityPub.fetch_public_activities()
|> Enum.reverse()
conn conn
|> add_link_headers(activities, %{"local" => local_only}) |> add_link_headers(activities, %{"local" => local_only})
......
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type> <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb> <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<id><%= @data["id"] %></id> <id><%= @data["id"] %></id>
<title><%= "New note by #{@user.nickname}" %></title> <title><%= activity_title(@object, Keyword.get(@feed_config, :post_title, %{})) %></title>
<content type="html"><%= activity_content(@activity) %></content> <content type="html"><%= activity_content(@object) %></content>
<published><%= @data["published"] %></published> <published><%= @data["published"] %></published>
<updated><%= @data["published"] %></updated> <updated><%= @data["published"] %></updated>
<ostatus:conversation ref="<%= activity_context(@activity) %>"><%= activity_context(@activity) %></ostatus:conversation> <ostatus:conversation ref="<%= activity_context(@activity) %>">
<%= activity_context(@activity) %>
</ostatus:conversation>
<link ref="<%= activity_context(@activity) %>" rel="ostatus:conversation"/> <link ref="<%= activity_context(@activity) %>" rel="ostatus:conversation"/>
<%= if @data["summary"] do %> <%= if @data["summary"] do %>
......
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
<% end %> <% end %>
<%= for activity <- @activities do %> <%= for activity <- @activities do %>
<%= render @view_module, "_activity.xml", Map.merge(assigns, %{activity: activity, data: activity_object_data(activity)}) %> <%= render @view_module, "_activity.xml", Map.merge(assigns, prepare_activity(activity)) %>
<% end %> <% end %>
</feed> </feed>
...@@ -734,56 +734,54 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do ...@@ -734,56 +734,54 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end end
test "retrieves a maximum of 20 activities" do test "retrieves a maximum of 20 activities" do
activities = ActivityBuilder.insert_list(30) ActivityBuilder.insert_list(10)
last_expected = List.last(activities) expected_activities = ActivityBuilder.insert_list(20)
activities = ActivityPub.fetch_public_activities() activities = ActivityPub.fetch_public_activities()
last = List.last(activities)
assert collect_ids(activities) == collect_ids(expected_activities)
assert length(activities) == 20 assert length(activities) == 20
assert last == last_expected
end end
test "retrieves ids starting from a since_id" do test "retrieves ids starting from a since_id" do
activities = ActivityBuilder.insert_list(30) activities = ActivityBuilder.insert_list(30)
later_activities = ActivityBuilder.insert_list(10) expected_activities = ActivityBuilder.insert_list(10)
since_id = List.last(activities).id since_id = List.last(activities).id
last_expected = List.last(later_activities)
activities = ActivityPub.fetch_public_activities(%{"since_id" => since_id}) activities = ActivityPub.fetch_public_activities(%{"since_id" => since_id})
last = List.last(activities)
assert collect_ids(activities) == collect_ids(expected_activities)
assert length(activities) == 10 assert length(activities) == 10
assert last == last_expected
end end
test "retrieves ids up to max_id" do test "retrieves ids up to max_id" do
_first_activities = ActivityBuilder.insert_list(10) ActivityBuilder.insert_list(10)
activities = ActivityBuilder.insert_list(20) expected_activities = ActivityBuilder.insert_list(20)
later_activities = ActivityBuilder.insert_list(10)
max_id = List.first(later_activities).id %{id: max_id} =
last_expected = List.last(activities) 10
|> ActivityBuilder.insert_list()
|> List.first()
activities = ActivityPub.fetch_public_activities(%{"max_id" => max_id}) activities = ActivityPub.fetch_public_activities(%{"max_id" => max_id})
last = List.last(activities)
assert length(activities) == 20 assert length(activities) == 20
assert last == last_expected assert collect_ids(activities) == collect_ids(expected_activities)
end end
test "paginates via offset/limit" do test "paginates via offset/limit" do
_first_activities = ActivityBuilder.insert_list(10) _first_part_activities = ActivityBuilder.insert_list(10)
activities = ActivityBuilder.insert_list(10) second_part_activities = ActivityBuilder.insert_list(10)
_later_activities = ActivityBuilder.insert_list(10)
first_expected = List.first(activities) later_activities = ActivityBuilder.insert_list(10)
activities = activities =
ActivityPub.fetch_public_activities(%{"page" => "2", "page_size" => "20"}, :offset) ActivityPub.fetch_public_activities(%{"page" => "2", "page_size" => "20"}, :offset)
first = List.first(activities)
assert length(activities) == 20 assert length(activities) == 20
assert first == first_expected
assert collect_ids(activities) ==
collect_ids(second_part_activities) ++ collect_ids(later_activities)
end end
test "doesn't return reblogs for users for whom reblogs have been muted" do test "doesn't return reblogs for users for whom reblogs have been muted" do
......
...@@ -6,16 +6,25 @@ defmodule Pleroma.Web.Feed.FeedControllerTest do ...@@ -6,16 +6,25 @@ defmodule Pleroma.Web.Feed.FeedControllerTest do
use Pleroma.Web.ConnCase use Pleroma.Web.ConnCase
import Pleroma.Factory import Pleroma.Factory
import SweetXml
alias Pleroma.Object alias Pleroma.Object
alias Pleroma.User alias Pleroma.User
clear_config([:feed])
test "gets a feed", %{conn: conn} do test "gets a feed", %{conn: conn} do
Pleroma.Config.put(
[:feed, :post_title],
%{max_length: 10, omission: "..."}
)
activity = insert(:note_activity) activity = insert(:note_activity)
note = note =
insert(:note, insert(:note,
data: %{ data: %{
"content" => "This is :moominmamma: note ",
"attachment" => [ "attachment" => [
%{ %{
"url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}] "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}]
...@@ -26,15 +35,30 @@ defmodule Pleroma.Web.Feed.FeedControllerTest do ...@@ -26,15 +35,30 @@ defmodule Pleroma.Web.Feed.FeedControllerTest do
) )
note_activity = insert(:note_activity, note: note) note_activity = insert(:note_activity, note: note)
object = Object.normalize(note_activity)
user = User.get_cached_by_ap_id(note_activity.data["actor"]) user = User.get_cached_by_ap_id(note_activity.data["actor"])
conn = 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 conn
|> put_req_header("content-type", "application/atom+xml") |> put_req_header("content-type", "application/atom+xml")
|> get("/users/#{user.nickname}/feed.atom") |> get("/users/#{user.nickname}/feed.atom")
|> response(200)
activity_titles =
resp
|> SweetXml.parse()
|> SweetXml.xpath(~x"//entry/title/text()"l)
assert response(conn, 200) =~ object.data["content"] assert activity_titles == ['42 This...', 'This is...']
assert resp =~ object.data["content"]
end end
test "returns 404 for a missing feed", %{conn: conn} do test "returns 404 for a missing feed", %{conn: conn} do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment