From: csaurus Date: Tue, 22 May 2018 00:19:37 +0000 (-0400) Subject: Merge branch 'develop' into feature/mstdn-direct-api X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=4fd9df100f61dfe4731934eca86500472d866f60;p=akkoma Merge branch 'develop' into feature/mstdn-direct-api --- 4fd9df100f61dfe4731934eca86500472d866f60 diff --cc lib/pleroma/web/activity_pub/activity_pub.ex index 4ce2e6052,24b4f045a..f07e26afd --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@@ -230,30 -260,25 +269,49 @@@ defmodule Pleroma.Web.ActivityPub.Activ |> 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 coalesce(data->'to' \\? ?, false)", ^public) and + fragment("not coalesce(data->'cc' \\? ?, false)", ^public) and + fragment("not coalesce(data->'to' \\? ?, false)", 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 + + 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 from(activity in query, where: activity.id > ^since_id) end