api/v1/timelines/direct implementation
This commit is contained in:
parent
392bd9ef56
commit
c8d418acdd
@ -224,6 +224,28 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
|> Enum.reverse()
|
|> Enum.reverse()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@valid_visibilities ~w[direct unlisted public private]
|
||||||
|
|
||||||
|
defp restrict_visibility(query, %{visibility: "direct"}) do
|
||||||
|
public = "https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
|
||||||
|
from(
|
||||||
|
activity in query,
|
||||||
|
join: sender in User,
|
||||||
|
on: sender.ap_id == activity.actor,
|
||||||
|
where:
|
||||||
|
fragment("not data->'to' \\? ?", ^public) and fragment("not data->'cc' \\? ?", ^public) and
|
||||||
|
fragment("not data->'to' \\? ?", sender.follower_address)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict_visibility(_query, %{visibility: visibility})
|
||||||
|
when visibility not in @valid_visibilities do
|
||||||
|
Logger.error("Could not restrict visibility to #{visibility}")
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict_visibility(query, _visibility), do: query
|
||||||
|
|
||||||
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
|
||||||
@ -347,6 +369,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
|> restrict_recent(opts)
|
|> restrict_recent(opts)
|
||||||
|> restrict_blocked(opts)
|
|> restrict_blocked(opts)
|
||||||
|> restrict_media(opts)
|
|> restrict_media(opts)
|
||||||
|
|> restrict_visibility(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_activities(recipients, opts \\ %{}) do
|
def fetch_activities(recipients, opts \\ %{}) do
|
||||||
|
@ -227,6 +227,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dm_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
query = ActivityPub.fetch_activities_query([user.ap_id], %{visibility: "direct"})
|
||||||
|
activities = Repo.all(query)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> add_link_headers(:user_statuses, activities, user.ap_id)
|
||||||
|
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
|
||||||
|
end
|
||||||
|
|
||||||
def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
with %Activity{} = activity <- Repo.get(Activity, id),
|
with %Activity{} = activity <- Repo.get(Activity, id),
|
||||||
true <- ActivityPub.visible_for_user?(activity, user) do
|
true <- ActivityPub.visible_for_user?(activity, user) do
|
||||||
|
@ -106,6 +106,8 @@ defmodule Pleroma.Web.Router do
|
|||||||
|
|
||||||
get("/timelines/home", MastodonAPIController, :home_timeline)
|
get("/timelines/home", MastodonAPIController, :home_timeline)
|
||||||
|
|
||||||
|
get("/timelines/direct", MastodonAPIController, :dm_timeline)
|
||||||
|
|
||||||
get("/favourites", MastodonAPIController, :favourites)
|
get("/favourites", MastodonAPIController, :favourites)
|
||||||
|
|
||||||
post("/statuses", MastodonAPIController, :post_status)
|
post("/statuses", MastodonAPIController, :post_status)
|
||||||
|
Loading…
Reference in New Issue
Block a user