defmodule Pleroma.Web.ActivityPub.ActivityPub do
- alias Pleroma.{Activity, Repo, Object, Upload, User, Web, Notification}
- alias Ecto.{Changeset, UUID}
+ alias Pleroma.{Activity, Repo, Object, Upload, User, Notification}
import Ecto.Query
import Pleroma.Web.ActivityPub.Utils
require Logger
:ok <- insert_full_object(map) do
{:ok, activity} = Repo.insert(%Activity{data: map, local: local, actor: map["actor"]})
Notification.create_notifications(activity)
+ stream_out(activity)
{:ok, activity}
else
%Activity{} = activity -> {:ok, activity}
end
end
- def create(to, actor, context, object, additional \\ %{}, published \\ nil, local \\ true) do
- 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
- if activity.data["type"] == "Create" and Enum.member?(activity.data["to"], "https://www.w3.org/ns/activitystreams#Public") do
+ def stream_out(activity) do
+ if activity.data["type"] in ["Create", "Announce"] do
+ Pleroma.Web.Streamer.stream("user", activity)
+ if Enum.member?(activity.data["to"], "https://www.w3.org/ns/activitystreams#Public") do
Pleroma.Web.Streamer.stream("public", activity)
- if local do
+ if activity.local do
Pleroma.Web.Streamer.stream("public:local", activity)
end
end
+ end
+ end
+
+ def create(to, actor, context, object, additional \\ %{}, published \\ nil, local \\ true) do
+ 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
{:ok, activity}
end
end
# TODO: This is weird, maybe we shouldn't check here if we can make the activity.
- def like(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, activity_id \\ nil, local \\ true) do
+ def like(%User{ap_id: ap_id} = user, %Object{data: %{"id" => _}} = object, activity_id \\ nil, local \\ true) do
with nil <- get_existing_like(ap_id, object),
like_data <- make_like_data(user, object, activity_id),
{:ok, activity} <- insert(like_data, local),
end
end
- def announce(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, activity_id \\ nil, local \\ true) do
+ def announce(%User{ap_id: _} = user, %Object{data: %{"id" => _}} = object, activity_id \\ nil, local \\ true) do
with announce_data <- make_announce_data(user, object, activity_id),
{:ok, activity} <- insert(announce_data, local),
{:ok, object} <- add_announce_to_object(activity, object),