X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Factivity_pub%2Factivity_pub.ex;h=8e15fde4a810cf1373b92e255ceb271c1ee3103e;hb=e7b73359e352ed585613feeb61a48df3dd6d2cb3;hp=6e29768d14d8090286d9cccc24cdadab2de337e5;hpb=b331cb449a46bbead19fea4fba59762c1a2e3a10;p=akkoma diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 6e29768d1..8e15fde4a 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -1,6 +1,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do alias Pleroma.{Activity, Repo, Object, Upload, User, Notification} - alias Pleroma.Web.OStatus + alias Pleroma.Web.ActivityPub.Transmogrifier import Ecto.Query import Pleroma.Web.ActivityPub.Utils require Logger @@ -37,7 +37,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end - def create(to, actor, context, object, additional \\ %{}, published \\ nil, local \\ true) do + def create(%{to: to, actor: actor, context: context, object: object} = params) do + additional = params[:additional] || %{} + local = !(params[:local] == false) # only accept false as false value + published = params[:published] + with create_data <- make_create_data(%{to: to, actor: actor, published: published, context: context, object: object}, additional), {:ok, activity} <- insert(create_data, local), :ok <- maybe_federate(activity) do @@ -136,12 +140,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end defp restrict_tag(query, _), do: query + defp restrict_recipients(query, []), do: query defp restrict_recipients(query, recipients) do - Enum.reduce(recipients, query, fn (recipient, q) -> - map = %{ to: [recipient] } - from activity in q, - or_where: fragment(~s(? @> ?), activity.data, ^map) - end) + from activity in query, + where: fragment("? && ?", ^recipients, activity.recipients) end defp restrict_local(query, %{"local_only" => true}) do @@ -241,27 +243,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end - # TODO: Extract to own module, align as close to Mastodon format as possible. - def sanitize_outgoing_activity_data(data) do - data - |> Map.put("@context", "https://www.w3.org/ns/activitystreams") - end - - def prepare_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do - with {:ok, user} <- OStatus.find_or_make_user(data["actor"]) do - {:ok, data} - else - _e -> :error - end - end - - def prepare_incoming(_) do - :error - end - def publish(actor, activity) do remote_users = Pleroma.Web.Salmon.remote_users(activity) - data = sanitize_outgoing_activity_data(activity.data) + {:ok, data} = Transmogrifier.prepare_outgoing(activity.data) Enum.each remote_users, fn(user) -> if user.info["ap_enabled"] do inbox = user.info["source_data"]["inbox"]