Add recipients field to activities.
Also do some very basic checks for AP message insertion.
This commit is contained in:
parent
888ec9e579
commit
4a13b84887
6 changed files with 56 additions and 3 deletions
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Activity do
|
|||
field :data, :map
|
||||
field :local, :boolean, default: true
|
||||
field :actor, :string
|
||||
field :recipients, {:array, :string}
|
||||
has_many :notifications, Notification, on_delete: :delete_all
|
||||
|
||||
timestamps()
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||
alias Pleroma.{Activity, Repo, Object, Upload, User, Notification}
|
||||
alias Pleroma.Web.OStatus
|
||||
import Ecto.Query
|
||||
import Pleroma.Web.ActivityPub.Utils
|
||||
require Logger
|
||||
|
||||
def get_recipients(data) do
|
||||
(data["to"] || []) ++ (data["cc"] || [])
|
||||
end
|
||||
|
||||
def insert(map, local \\ true) when is_map(map) do
|
||||
with nil <- Activity.get_by_ap_id(map["id"]),
|
||||
map <- lazy_put_activity_defaults(map),
|
||||
:ok <- insert_full_object(map) do
|
||||
{:ok, activity} = Repo.insert(%Activity{data: map, local: local, actor: map["actor"]})
|
||||
{:ok, activity} = Repo.insert(%Activity{data: map, local: local, actor: map["actor"], recipients: get_recipients(map)})
|
||||
Notification.create_notifications(activity)
|
||||
stream_out(activity)
|
||||
{:ok, activity}
|
||||
|
|
@ -215,4 +220,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
data = Upload.store(file)
|
||||
Repo.insert(%Object{data: data})
|
||||
end
|
||||
|
||||
def prepare_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
|
||||
with {:ok, user} <- OStatus.find_or_make_user(data["actor"]) do
|
||||
data
|
||||
else
|
||||
_e -> :error
|
||||
end
|
||||
end
|
||||
|
||||
def prepare_incoming(_) do
|
||||
:error
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|
|||
|
||||
# TODO: Move signature failure halt into plug
|
||||
def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
|
||||
{:ok, activity} = ActivityPub.insert(params, false)
|
||||
json(conn, "ok")
|
||||
with {:ok, data} <- ActivityPub.prepare_incoming(params),
|
||||
{:ok, activity} <- ActivityPub.insert(data, false) do
|
||||
json(conn, "ok")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue