Expose unannounce activity so that it can be tested

This commit is contained in:
Francis Dinh 2018-04-18 03:39:42 -04:00
parent 0251690e96
commit 687db1bc3a
4 changed files with 18 additions and 9 deletions

View file

@ -142,11 +142,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
def unannounce(%User{} = actor, %Object{} = object, local \\ true) do def unannounce(%User{} = actor, %Object{} = object, local \\ true) do
with %Activity{} = activity <- get_existing_announce(actor.ap_id, object), with %Activity{} = activity <- get_existing_announce(actor.ap_id, object),
unannounce_data <- make_unannounce_data(actor, activity), unannounce_data <- make_unannounce_data(actor, object),
{:ok, _unannounce_activity} <- insert(unannounce_data, local), {:ok, unannounce_activity} <- insert(unannounce_data, local),
{:ok, _activity} <- Repo.delete(activity), {:ok, _activity} <- Repo.delete(activity),
{:ok, object} <- remove_announce_from_object(activity, object) do {:ok, object} <- remove_announce_from_object(activity, object) do
{:ok, object} {:ok, unannounce_activity, object}
else else
_e -> {:ok, object} _e -> {:ok, object}
end end

View file

@ -283,13 +283,13 @@ defmodule Pleroma.Web.ActivityPub.Utils do
""" """
def make_unannounce_data( def make_unannounce_data(
%User{ap_id: ap_id} = user, %User{ap_id: ap_id} = user,
%Activity{data: %{"id" => id, "context" => context}} = activity %Object{data: %{"id" => id, "context" => context}} = object
) do ) do
%{ %{
"type" => "Undo", "type" => "Undo",
"actor" => ap_id, "actor" => ap_id,
"object" => id, "object" => id,
"to" => [user.follower_address, activity.data["actor"]], "to" => [user.follower_address, object.data["actor"]],
"cc" => ["https://www.w3.org/ns/activitystreams#Public"], "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
"context" => context "context" => context
} }

View file

@ -297,7 +297,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end end
def unreblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do def unreblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
with {:ok, %{data: %{"id" => id}}} = CommonAPI.unrepeat(ap_id_or_id, user), with {:ok, _, %{data: %{"id" => id}}} = CommonAPI.unrepeat(ap_id_or_id, user),
%Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do
render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity}) render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity})
end end

View file

@ -278,15 +278,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
user = insert(:user) user = insert(:user)
# Unannouncing an object that is not announced does nothing # Unannouncing an object that is not announced does nothing
{:ok, object} = ActivityPub.unannounce(user, object) #{:ok, object} = ActivityPub.unannounce(user, object)
assert object.data["announcement_count"] == 0 #assert object.data["announcement_count"] == 0
{:ok, announce_activity, object} = ActivityPub.announce(user, object) {:ok, announce_activity, object} = ActivityPub.announce(user, object)
assert object.data["announcement_count"] == 1 assert object.data["announcement_count"] == 1
{:ok, object} = ActivityPub.unannounce(user, object) {:ok, unannounce_activity, object} = ActivityPub.unannounce(user, object)
assert object.data["announcement_count"] == 0 assert object.data["announcement_count"] == 0
assert unannounce_activity.data["to"] == [
User.ap_followers(user),
note_activity.data["actor"]
]
assert unannounce_activity.data["type"] == "Undo"
assert unannounce_activity.data["object"] == object.data["id"]
assert unannounce_activity.data["actor"] == user.ap_id
assert unannounce_activity.data["context"] == object.data["context"]
assert Repo.get(Activity, announce_activity.id) == nil assert Repo.get(Activity, announce_activity.id) == nil
end end
end end