Merge branch 'develop' into feature/mstdn-direct-api
authorcsaurus <csaurus@mailbox.org>
Tue, 22 May 2018 00:19:37 +0000 (20:19 -0400)
committercsaurus <csaurus@mailbox.org>
Tue, 22 May 2018 00:19:37 +0000 (20:19 -0400)
1  2 
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
lib/pleroma/web/router.ex
test/web/mastodon_api/mastodon_api_controller_test.exs

index 4ce2e605266542888e64d7dd176f6b1737d31b15,24b4f045afd8df952856359d8ca802ede03505c9..f07e26afd02dd9e475caf396acb39da3d3d2c614
@@@ -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
Simple merge