[#1501] Made user feed contain public and unlisted activities.
This commit is contained in:
parent
09d8b9cb55
commit
d7a57004ef
|
@ -538,14 +538,27 @@ def fetch_latest_activity_id_for_context(context, opts \\ %{}) do
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec fetch_public_activities(map(), Pagination.type()) :: [Activity.t()]
|
@spec fetch_public_or_unlisted_activities(map(), Pagination.type()) :: [Activity.t()]
|
||||||
def fetch_public_activities(opts \\ %{}, pagination \\ :keyset) do
|
def fetch_public_or_unlisted_activities(opts \\ %{}, pagination \\ :keyset) do
|
||||||
opts = Map.drop(opts, ["user"])
|
opts = Map.drop(opts, ["user"])
|
||||||
|
|
||||||
[Constants.as_public()]
|
query = fetch_activities_query([Constants.as_public()], opts)
|
||||||
|> fetch_activities_query(opts)
|
|
||||||
|> restrict_unlisted()
|
query =
|
||||||
|> Pagination.fetch_paginated(opts, pagination)
|
if opts["restrict_unlisted"] do
|
||||||
|
restrict_unlisted(query)
|
||||||
|
else
|
||||||
|
query
|
||||||
|
end
|
||||||
|
|
||||||
|
Pagination.fetch_paginated(query, opts, pagination)
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec fetch_public_activities(map(), Pagination.type()) :: [Activity.t()]
|
||||||
|
def fetch_public_activities(opts \\ %{}, pagination \\ :keyset) do
|
||||||
|
opts
|
||||||
|
|> Map.put("restrict_unlisted", true)
|
||||||
|
|> fetch_public_or_unlisted_activities(pagination)
|
||||||
end
|
end
|
||||||
|
|
||||||
@valid_visibilities ~w[direct unlisted public private]
|
@valid_visibilities ~w[direct unlisted public private]
|
||||||
|
|
|
@ -56,7 +56,7 @@ def feed(conn, %{"nickname" => nickname} = params) do
|
||||||
"actor_id" => user.ap_id
|
"actor_id" => user.ap_id
|
||||||
}
|
}
|
||||||
|> put_if_exist("max_id", params["max_id"])
|
|> put_if_exist("max_id", params["max_id"])
|
||||||
|> ActivityPub.fetch_public_activities()
|
|> ActivityPub.fetch_public_or_unlisted_activities()
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/#{format}+xml")
|
|> put_resp_content_type("application/#{format}+xml")
|
||||||
|
|
|
@ -11,13 +11,14 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
setup do: clear_config([:instance, :federating], true)
|
setup do: clear_config([:instance, :federating], true)
|
||||||
|
|
||||||
describe "feed" do
|
describe "feed" do
|
||||||
setup do: clear_config([:feed])
|
setup do: 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: "..."}
|
||||||
|
@ -157,6 +158,29 @@ test "returns 404 for a missing feed", %{conn: conn} do
|
||||||
|
|
||||||
assert response(conn, 404)
|
assert response(conn, 404)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "returns feed with public and unlisted activities", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, _} = CommonAPI.post(user, %{status: "public", visibility: "public"})
|
||||||
|
{:ok, _} = CommonAPI.post(user, %{status: "direct", visibility: "direct"})
|
||||||
|
{:ok, _} = CommonAPI.post(user, %{status: "unlisted", visibility: "unlisted"})
|
||||||
|
{:ok, _} = CommonAPI.post(user, %{status: "private", visibility: "private"})
|
||||||
|
|
||||||
|
resp =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/atom+xml")
|
||||||
|
|> get(user_feed_path(conn, :feed, user.nickname))
|
||||||
|
|> response(200)
|
||||||
|
|
||||||
|
activity_titles =
|
||||||
|
resp
|
||||||
|
|> SweetXml.parse()
|
||||||
|
|> SweetXml.xpath(~x"//entry/title/text()"l)
|
||||||
|
|> Enum.sort()
|
||||||
|
|
||||||
|
assert activity_titles == ['public', 'unlisted']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Note: see ActivityPubControllerTest for JSON format tests
|
# Note: see ActivityPubControllerTest for JSON format tests
|
||||||
|
|
Loading…
Reference in New Issue