+ q = fetch_activities_query(["https://www.w3.org/ns/activitystreams#Public"], opts)
+
+ q
+ |> restrict_unlisted()
+ |> Repo.all()
+ |> 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,
+ # Are non-direct statuses with no to/cc possible?
+ where:
+ fragment(
+ "not (? && ?)",
+ [^public, sender.follower_address],
+ activity.recipients
+ )
+ )
+ 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
+
+ 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()