|> Enum.reverse()
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
from(activity in query, where: activity.id > ^since_id)
end
|> restrict_recent(opts)
|> restrict_blocked(opts)
|> restrict_media(opts)
+ |> restrict_visibility(opts)
end
def fetch_activities(recipients, opts \\ %{}) do
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
with %Activity{} = activity <- Repo.get(Activity, id),
true <- ActivityPub.visible_for_user?(activity, user) do
get("/timelines/home", MastodonAPIController, :home_timeline)
+ get("/timelines/direct", MastodonAPIController, :dm_timeline)
+
get("/favourites", MastodonAPIController, :favourites)
post("/statuses", MastodonAPIController, :post_status)