From: William Pitcock Date: Wed, 29 Aug 2018 08:51:23 +0000 (+0000) Subject: activitypub: allow querying the activity/object graph bounded to a specific to/cc set X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=643fae6e36881b8883e247df28568e9b54e1b086;p=akkoma activitypub: allow querying the activity/object graph bounded to a specific to/cc set --- diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index fdbd7fed0..dad9c4865 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -410,6 +410,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_tag(query, _), do: query + defp restrict_to_cc(query, recipients_to, recipients_cc) do + from( + activity in query, + where: + fragment( + "(? && ?) or (? && ?)", + ^recipients_to, + activity.recipients_to, + ^recipients_cc, + activity.recipients_cc + ) + ) + end + defp restrict_recipients(query, [], _user), do: query defp restrict_recipients(query, recipients, nil) do @@ -551,6 +565,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do |> Enum.reverse() end + def fetch_activities_bounded(recipients_to, recipients_cc, opts \\ %{}) do + fetch_activities_query([], opts) + |> restrict_to_cc(recipients_to, recipients_cc) + |> Repo.all() + |> Enum.reverse() + end + def upload(file) do data = Upload.store(file, Application.get_env(:pleroma, :instance)[:dedupe_media]) Repo.insert(%Object{data: data})