Return private / direct posts on user timelines, too.

This commit is contained in:
lain 2018-05-20 16:15:18 +02:00
parent bdfe0991d2
commit 434601a5c3
4 changed files with 60 additions and 25 deletions

View file

@ -260,6 +260,25 @@ def fetch_public_activities(opts \\ %{}) do
|> Enum.reverse() |> Enum.reverse()
end end
def fetch_user_activities(user, reading_user, params \\ %{}) do
params =
params
|> Map.put("type", ["Create", "Announce"])
|> Map.put("actor_id", user.ap_id)
|> Map.put("whole_db", true)
recipients =
if reading_user do
["https://www.w3.org/ns/activitystreams#Public"] ++
[reading_user.ap_id | reading_user.following]
else
["https://www.w3.org/ns/activitystreams#Public"]
end
fetch_activities(recipients, params)
|> Enum.reverse()
end
defp restrict_since(query, %{"since_id" => since_id}) do defp restrict_since(query, %{"since_id" => since_id}) do
from(activity in query, where: activity.id > ^since_id) from(activity in query, where: activity.id > ^since_id)
end end

View file

@ -204,21 +204,14 @@ def public_timeline(%{assigns: %{user: user}} = conn, params) do
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
end end
def user_statuses(%{assigns: %{user: user}} = conn, params) do def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do
with %User{ap_id: ap_id} <- Repo.get(User, params["id"]) do with %User{} = user <- Repo.get(User, params["id"]) do
params = # Since Pleroma has no "pinned" posts feature, we'll just set an empty list here
params
|> Map.put("type", ["Create", "Announce"])
|> Map.put("actor_id", ap_id)
|> Map.put("whole_db", true)
activities = activities =
if params["pinned"] == "true" do if params["pinned"] == "true" do
# Since Pleroma has no "pinned" posts feature, we'll just set an empty list here
[] []
else else
ActivityPub.fetch_public_activities(params) ActivityPub.fetch_user_activities(user, reading_user, params)
|> Enum.reverse()
end end
conn conn

View file

@ -96,13 +96,7 @@ def show_user(conn, params) do
def user_timeline(%{assigns: %{user: user}} = conn, params) do def user_timeline(%{assigns: %{user: user}} = conn, params) do
case TwitterAPI.get_user(user, params) do case TwitterAPI.get_user(user, params) do
{:ok, target_user} -> {:ok, target_user} ->
params = activities = ActivityPub.fetch_user_activities(target_user, user, params)
params
|> Map.put("type", ["Create", "Announce"])
|> Map.put("actor_id", target_user.ap_id)
|> Map.put("whole_db", true)
activities = ActivityPub.fetch_public_activities(params)
conn conn
|> render(ActivityView, "index.json", %{activities: activities, for: user}) |> render(ActivityView, "index.json", %{activities: activities, for: user})

View file

@ -354,18 +354,47 @@ test "unfavorites a status and returns it", %{conn: conn} do
describe "user timelines" do describe "user timelines" do
test "gets a users statuses", %{conn: conn} do test "gets a users statuses", %{conn: conn} do
_note = insert(:note_activity) user_one = insert(:user)
note_two = insert(:note_activity) user_two = insert(:user)
user_three = insert(:user)
user = User.get_by_ap_id(note_two.data["actor"]) {:ok, user_three} = User.follow(user_three, user_one)
conn = {:ok, activity} = CommonAPI.post(user_one, %{"status" => "HI!!!"})
{:ok, direct_activity} =
CommonAPI.post(user_one, %{
"status" => "Hi, @#{user_two.nickname}.",
"visibility" => "direct"
})
{:ok, private_activity} =
CommonAPI.post(user_one, %{"status" => "private", "visibility" => "private"})
resp =
conn conn
|> get("/api/v1/accounts/#{user.id}/statuses") |> get("/api/v1/accounts/#{user_one.id}/statuses")
assert [%{"id" => id}] = json_response(conn, 200) assert [%{"id" => id}] = json_response(resp, 200)
assert id == to_string(activity.id)
assert id == to_string(note_two.id) resp =
conn
|> assign(:user, user_two)
|> get("/api/v1/accounts/#{user_one.id}/statuses")
assert [%{"id" => id_one}, %{"id" => id_two}] = json_response(resp, 200)
assert id_one == to_string(direct_activity.id)
assert id_two == to_string(activity.id)
resp =
conn
|> assign(:user, user_three)
|> get("/api/v1/accounts/#{user_one.id}/statuses")
assert [%{"id" => id_one}, %{"id" => id_two}] = json_response(resp, 200)
assert id_one == to_string(private_activity.id)
assert id_two == to_string(activity.id)
end end
test "unimplemented pinned statuses feature", %{conn: conn} do test "unimplemented pinned statuses feature", %{conn: conn} do