alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.Push
alias Pleroma.Web.Streamer
+ alias Pleroma.Workers.PollWorker
require Logger
# - Set up notifications
@impl true
def handle(%{data: %{"type" => "Create"}} = activity, meta) do
- with {:ok, object, meta} <- handle_object_creation(meta[:object_data], meta),
+ with {:ok, object, meta} <- handle_object_creation(meta[:object_data], activity, meta),
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
{:ok, notifications} = Notification.create_notifications(activity, do_send: false)
{:ok, _user} = ActivityPub.increase_note_count_if_public(user, object)
{:ok, object, meta}
end
- def handle_object_creation(%{"type" => "ChatMessage"} = object, meta) do
+ def handle_object_creation(%{"type" => "ChatMessage"} = object, _activity, meta) do
with {:ok, object, meta} <- Pipeline.common_pipeline(object, meta) do
actor = User.get_cached_by_ap_id(object.data["actor"])
recipient = User.get_cached_by_ap_id(hd(object.data["to"]))
end
end
- def handle_object_creation(%{"type" => "Answer"} = object_map, meta) do
+ def handle_object_creation(%{"type" => "Question"} = object, activity, meta) do
+ with {:ok, object, meta} <- Pipeline.common_pipeline(object, meta) do
+ PollWorker.schedule_poll_end(activity)
+ {:ok, object, meta}
+ end
+ end
+
+ def handle_object_creation(%{"type" => "Answer"} = object_map, _activity, meta) do
with {:ok, object, meta} <- Pipeline.common_pipeline(object_map, meta) do
Object.increase_vote_count(
object.data["inReplyTo"],
end
end
- def handle_object_creation(%{"type" => objtype} = object, meta)
- when objtype in ~w[Audio Video Question Event Article] do
+ def handle_object_creation(%{"type" => objtype} = object, _activity, meta)
+ when objtype in ~w[Audio Video Event Article] do
with {:ok, object, meta} <- Pipeline.common_pipeline(object, meta) do
{:ok, object, meta}
end
end
# Nothing to do
- def handle_object_creation(object, meta) do
+ def handle_object_creation(object, _activity, meta) do
{:ok, object, meta}
end
end
end
+ describe "Question objects" do
+ setup do
+ user = insert(:user)
+ question = build(:question, user: user)
+ question_activity = build(:question_activity, question: question)
+ activity_data = Map.put(question_activity.data, "object", question.data["id"])
+ meta = [object_data: question.data, local: false]
+
+ {:ok, activity, meta} = ActivityPub.persist(activity_data, meta)
+
+ %{activity: activity, meta: meta}
+ end
+
+ test "enqueues the poll end", %{activity: activity, meta: meta} do
+ {:ok, activity, meta} = SideEffects.handle(activity, meta)
+
+ assert_enqueued(
+ worker: Pleroma.Workers.PollWorker,
+ args: %{op: "poll_end", activity_id: activity.id},
+ scheduled_at: NaiveDateTime.from_iso8601!(meta[:object_data]["closed"])
+ )
+ end
+ end
+
describe "delete users with confirmation pending" do
setup do
user = insert(:user, is_confirmed: false)
"id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
"type" => "Question",
"actor" => user.ap_id,
+ "attributedTo" => user.ap_id,
"attachment" => [],
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"cc" => [user.follower_address],
"context" => Pleroma.Web.ActivityPub.Utils.generate_context_id(),
+ "closed" => DateTime.utc_now() |> DateTime.add(86_400) |> DateTime.to_iso8601(),
"oneOf" => [
%{
"type" => "Note",