Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
authorlain <lain@soykaf.club>
Tue, 2 Jun 2020 12:28:01 +0000 (14:28 +0200)
committerlain <lain@soykaf.club>
Tue, 2 Jun 2020 12:28:01 +0000 (14:28 +0200)
1  2 
lib/pleroma/web/activity_pub/activity_pub.ex

index 5858eb47377b929c017c7992c616138d863a634e,a38f9a3c8a101baa4c5d6cc5f3e165a852386dd4..568db23483d585cda7bccc02701055e96895ffbb
@@@ -1037,18 -1030,17 +1037,29 @@@ defmodule Pleroma.Web.ActivityPub.Activ
      end
    end
  
 +  defp exclude_chat_messages(query, %{"include_chat_messages" => true}), do: query
 +
 +  defp exclude_chat_messages(query, _) do
 +    if has_named_binding?(query, :object) do
 +      from([activity, object: o] in query,
 +        where: fragment("not(?->>'type' = ?)", o.data, "ChatMessage")
 +      )
 +    else
 +      query
 +    end
 +  end
 +
+   defp exclude_invisible_actors(query, %{"invisible_actors" => true}), do: query
+   defp exclude_invisible_actors(query, _opts) do
+     invisible_ap_ids =
+       User.Query.build(%{invisible: true, select: [:ap_id]})
+       |> Repo.all()
+       |> Enum.map(fn %{ap_id: ap_id} -> ap_id end)
+     from([activity] in query, where: activity.actor not in ^invisible_ap_ids)
+   end
    defp exclude_id(query, %{"exclude_id" => id}) when is_binary(id) do
      from(activity in query, where: activity.id != ^id)
    end
      |> restrict_instance(opts)
      |> Activity.restrict_deactivated_users()
      |> exclude_poll_votes(opts)
 +    |> exclude_chat_messages(opts)
+     |> exclude_invisible_actors(opts)
      |> exclude_visibility(opts)
    end