From b949577472d5e4db1aeacb9ff2162eb89440130c Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sat, 14 Apr 2018 03:39:16 -0400 Subject: [PATCH 01/32] Add unrepeat functionality --- lib/pleroma/web/activity_pub/activity_pub.ex | 10 ++++++++ lib/pleroma/web/activity_pub/utils.ex | 25 +++++++++++++++++++ lib/pleroma/web/common_api/common_api.ex | 10 ++++++++ .../mastodon_api/mastodon_api_controller.ex | 6 +++++ lib/pleroma/web/router.ex | 1 + lib/pleroma/web/twitter_api/twitter_api.ex | 7 ++++++ .../web/twitter_api/twitter_api_controller.ex | 6 +++++ 7 files changed, 65 insertions(+) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 04b50c1cc..b3154ea99 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -140,6 +140,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end + def unannounce(%User{} = actor, %Object{} = object) do + with %Activity{} = activity <- get_existing_announce(actor.ap_id, object), + {:ok, _activity} <- Repo.delete(activity), + {:ok, object} <- remove_announce_from_object(activity, object) do + {:ok, object} + else + _e -> {:ok, object} + end + end + def follow(follower, followed, activity_id \\ nil, local \\ true) do with data <- make_follow_data(follower, followed, activity_id), {:ok, activity} <- insert(data, local), diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 7a0762e9f..c7c876670 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -239,6 +239,25 @@ defmodule Pleroma.Web.ActivityPub.Utils do @doc """ Make announce activity data for the given actor and object """ + def get_existing_announce(actor, %{data: %{"id" => id}}) do + query = + from( + activity in Activity, + where: fragment("(?)->>'actor' = ?", activity.data, ^actor), + # this is to use the index + where: + fragment( + "coalesce((?)->'object'->>'id', (?)->>'object') = ?", + activity.data, + activity.data, + ^id + ), + where: fragment("(?)->>'type' = 'Announce'", activity.data) + ) + + Repo.one(query) + end + def make_announce_data( %User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, @@ -262,6 +281,12 @@ defmodule Pleroma.Web.ActivityPub.Utils do end end + def remove_announce_from_object(%Activity{data: %{"actor" => actor}}, object) do + with announcements <- (object.data["announcements"] || []) |> List.delete(actor) do + update_element_in_object("announcement", announcements, object) + end + end + #### Unfollow-related helpers def make_unfollow_data(follower, followed, follow_activity) do diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 21225c3b7..8889b9b42 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -24,6 +24,16 @@ defmodule Pleroma.Web.CommonAPI do end end + def unrepeat(id_or_ap_id, user) do + with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id), + object <- Object.get_by_ap_id(activity.data["object"]["id"]) do + ActivityPub.unannounce(user, object) + else + _ -> + {:error, "Could not unrepeat"} + end + end + def favorite(id_or_ap_id, user) do with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id), false <- activity.data["actor"] == user.ap_id, diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 21a3660c8..1825e156f 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -296,6 +296,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end + def unreblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do + with {:ok, announce, _activity} = CommonAPI.unrepeat(ap_id_or_id, user) do + render(conn, StatusView, "status.json", %{activity: announce, for: user, as: :activity}) + end + end + def fav_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do with {:ok, _fav, %{data: %{"id" => id}}} = CommonAPI.favorite(ap_id_or_id, user), %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 8ee27e63c..5a32cf7b4 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -110,6 +110,7 @@ defmodule Pleroma.Web.Router do delete("/statuses/:id", MastodonAPIController, :delete_status) post("/statuses/:id/reblog", MastodonAPIController, :reblog_status) + post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status) post("/statuses/:id/favourite", MastodonAPIController, :fav_status) post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status) diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index c12cd7f8a..1791feb3a 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -64,6 +64,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do end end + def unrepeat(%User{} = user, ap_id_or_id) do + with {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.unrepeat(ap_id_or_id, user), + %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + {:ok, activity} + end + end + def fav(%User{} = user, ap_id_or_id) do with {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.favorite(ap_id_or_id, user), %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 5f44e46c0..986436326 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -229,6 +229,12 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def unretweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do + with {:ok, activity} <- TwitterAPI.unrepeat(user, id) do + render(conn, ActivityView, "activity.json", %{activity: activity, for: user}) + end + end + def register(conn, params) do with {:ok, user} <- TwitterAPI.register_user(params) do render(conn, UserView, "show.json", %{user: user}) From 5b0d0b9ab2e9efba3d170a06ea3cc5c4ca33c2c9 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sat, 14 Apr 2018 22:34:06 -0400 Subject: [PATCH 02/32] Add unreblogging tests --- test/web/activity_pub/activity_pub_test.exs | 20 +++++++++++++++++++ .../mastodon_api_controller_test.exs | 19 ++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 657d75a55..84f844322 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -271,6 +271,26 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do end end + describe "unannouncing an object" do + test "unannouncing a previously announced object" do + note_activity = insert(:note_activity) + object = Object.get_by_ap_id(note_activity.data["object"]["id"]) + user = insert(:user) + + # Unannouncing an object that is not announced does nothing + {:ok, object} = ActivityPub.unannounce(user, object) + assert object.data["announcement_count"] == 0 + + {:ok, announce_activity, object} = ActivityPub.announce(user, object) + assert object.data["announcement_count"] == 1 + + {:ok, object} = ActivityPub.unannounce(user, object) + assert object.data["announcement_count"] == 0 + + assert Repo.get(Activity, announce_activity.id) == nil + end + end + describe "uploading files" do test "copies the file to the configured folder" do file = %Plug.Upload{ diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 5293b9364..f3a9c1def 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -264,6 +264,25 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do end end + describe "unreblogging" do + test "unreblogs and returns the unreblogged status", %{conn: conn} do + activity = insert(:note_activity) + user = insert(:user) + + {:ok, _, _} = CommonAPI.repeat(activity.id, user) + + conn = + conn + |> assign(:user, user) + |> post("/api/v1/statuses/#{activity.id}/unreblog") + + assert %{"reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 0}} = + json_response(conn, 200) + + assert to_string(activity.id) == id + end + end + describe "favoriting" do test "favs a status and returns it", %{conn: conn} do activity = insert(:note_activity) From d16877251a42545bfbef383b1a023aa029730c44 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Mon, 16 Apr 2018 10:59:32 -0400 Subject: [PATCH 03/32] doc fixes --- lib/pleroma/web/activity_pub/utils.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index c7c876670..6a36a6c10 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -237,7 +237,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do #### Announce-related helpers @doc """ - Make announce activity data for the given actor and object + Retruns an existing announce activity if the notice has already been announced """ def get_existing_announce(actor, %{data: %{"id" => id}}) do query = @@ -258,6 +258,9 @@ defmodule Pleroma.Web.ActivityPub.Utils do Repo.one(query) end + @doc """ + Make announce activity data for the given actor and object + """ def make_announce_data( %User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, From 42279f54cfa6b1728f71de0a14cfde8e615141e7 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Mon, 16 Apr 2018 23:30:52 -0400 Subject: [PATCH 04/32] Return target status in MastoAPI endpoint instead of reblog activity --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 5 +++-- test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 1825e156f..6ddfc8b75 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -297,8 +297,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def unreblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do - with {:ok, announce, _activity} = CommonAPI.unrepeat(ap_id_or_id, user) do - render(conn, StatusView, "status.json", %{activity: announce, for: user, as: :activity}) + with {:ok, %{data: %{"id" => id}}} = CommonAPI.unrepeat(ap_id_or_id, user), + %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity}) end end diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index f3a9c1def..2a24037d7 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -276,7 +276,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> assign(:user, user) |> post("/api/v1/statuses/#{activity.id}/unreblog") - assert %{"reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 0}} = + assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} = json_response(conn, 200) assert to_string(activity.id) == id From 85bd191291fdf0fb5f1807b3aa95913a607ddc6a Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 17 Apr 2018 04:12:16 -0400 Subject: [PATCH 05/32] Remove unretweet function for now --- lib/pleroma/web/twitter_api/twitter_api.ex | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 1791feb3a..c12cd7f8a 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -64,13 +64,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do end end - def unrepeat(%User{} = user, ap_id_or_id) do - with {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.unrepeat(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do - {:ok, activity} - end - end - def fav(%User{} = user, ap_id_or_id) do with {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.favorite(ap_id_or_id, user), %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do From c9e7b984d5d09f6b1ecdeb04e888b9000de6e11c Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 17 Apr 2018 04:13:08 -0400 Subject: [PATCH 06/32] Add make_unannounce_data helper function --- lib/pleroma/web/activity_pub/utils.ex | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 6a36a6c10..a124bb8b6 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -237,7 +237,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do #### Announce-related helpers @doc """ - Retruns an existing announce activity if the notice has already been announced + Retruns an existing announce activity if the notice has already been announced """ def get_existing_announce(actor, %{data: %{"id" => id}}) do query = @@ -278,6 +278,23 @@ defmodule Pleroma.Web.ActivityPub.Utils do if activity_id, do: Map.put(data, "id", activity_id), else: data end + @doc """ + Make unannounce activity data for the given actor and object + """ + def make_unannounce_data( + %User{ap_id: ap_id} = user, + %Object{data: %{"id" => id}} = object + ) do + %{ + "type" => "Undo", + "actor" => ap_id, + "object" => id, + "to" => [user.follower_address, object.data["actor"]], + "cc" => ["https://www.w3.org/ns/activitystreams#Public"], + "context" => object.data["context"] + } + end + def add_announce_to_object(%Activity{data: %{"actor" => actor}}, object) do with announcements <- [actor | object.data["announcements"] || []] |> Enum.uniq() do update_element_in_object("announcement", announcements, object) From 0251690e96d683fb5f5eee11e2dfff4c008676cf Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 17 Apr 2018 20:35:07 -0400 Subject: [PATCH 07/32] Add federation for unrepeats --- lib/pleroma/web/activity_pub/activity_pub.ex | 4 +++- lib/pleroma/web/activity_pub/utils.ex | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index b3154ea99..2239da472 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -140,8 +140,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end - def unannounce(%User{} = actor, %Object{} = object) do + def unannounce(%User{} = actor, %Object{} = object, local \\ true) do with %Activity{} = activity <- get_existing_announce(actor.ap_id, object), + unannounce_data <- make_unannounce_data(actor, activity), + {:ok, _unannounce_activity} <- insert(unannounce_data, local), {:ok, _activity} <- Repo.delete(activity), {:ok, object} <- remove_announce_from_object(activity, object) do {:ok, object} diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index a124bb8b6..9e2fa1fb2 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -283,15 +283,15 @@ defmodule Pleroma.Web.ActivityPub.Utils do """ def make_unannounce_data( %User{ap_id: ap_id} = user, - %Object{data: %{"id" => id}} = object + %Activity{data: %{"id" => id, "context" => context}} = activity ) do %{ "type" => "Undo", "actor" => ap_id, "object" => id, - "to" => [user.follower_address, object.data["actor"]], + "to" => [user.follower_address, activity.data["actor"]], "cc" => ["https://www.w3.org/ns/activitystreams#Public"], - "context" => object.data["context"] + "context" => context } end From 687db1bc3a13d3303865a104f0475a6fc4671037 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 18 Apr 2018 03:39:42 -0400 Subject: [PATCH 08/32] Expose unannounce activity so that it can be tested --- lib/pleroma/web/activity_pub/activity_pub.ex | 6 +++--- lib/pleroma/web/activity_pub/utils.ex | 4 ++-- .../web/mastodon_api/mastodon_api_controller.ex | 2 +- test/web/activity_pub/activity_pub_test.exs | 15 ++++++++++++--- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 2239da472..3b918e28f 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -142,11 +142,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def unannounce(%User{} = actor, %Object{} = object, local \\ true) do with %Activity{} = activity <- get_existing_announce(actor.ap_id, object), - unannounce_data <- make_unannounce_data(actor, activity), - {:ok, _unannounce_activity} <- insert(unannounce_data, local), + unannounce_data <- make_unannounce_data(actor, object), + {:ok, unannounce_activity} <- insert(unannounce_data, local), {:ok, _activity} <- Repo.delete(activity), {:ok, object} <- remove_announce_from_object(activity, object) do - {:ok, object} + {:ok, unannounce_activity, object} else _e -> {:ok, object} end diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 9e2fa1fb2..1f740eda5 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -283,13 +283,13 @@ defmodule Pleroma.Web.ActivityPub.Utils do """ def make_unannounce_data( %User{ap_id: ap_id} = user, - %Activity{data: %{"id" => id, "context" => context}} = activity + %Object{data: %{"id" => id, "context" => context}} = object ) do %{ "type" => "Undo", "actor" => ap_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"], "context" => context } diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 6ddfc8b75..c01552410 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -297,7 +297,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end 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 render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity}) end diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 84f844322..85a6aecf0 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -278,15 +278,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do user = insert(:user) # Unannouncing an object that is not announced does nothing - {:ok, object} = ActivityPub.unannounce(user, object) - assert object.data["announcement_count"] == 0 + #{:ok, object} = ActivityPub.unannounce(user, object) + #assert object.data["announcement_count"] == 0 {:ok, announce_activity, object} = ActivityPub.announce(user, object) 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 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 end end From 7b4f55238eeb8561c6a8e43321cd965667cefabe Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 18 Apr 2018 06:00:40 -0400 Subject: [PATCH 09/32] Handle unrepeats via the TwitterAPI --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- .../mastodon_api/mastodon_api_controller.ex | 2 +- lib/pleroma/web/twitter_api/twitter_api.ex | 18 ++++++++++++++++++ .../web/twitter_api/twitter_api_controller.ex | 10 ++-------- test/web/activity_pub/activity_pub_test.exs | 4 +++- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 3b918e28f..dccd2e757 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -146,7 +146,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do {:ok, unannounce_activity} <- insert(unannounce_data, local), {:ok, _activity} <- Repo.delete(activity), {:ok, object} <- remove_announce_from_object(activity, object) do - {:ok, unannounce_activity, object} + {:ok, unannounce_activity, activity, object} else _e -> {:ok, object} end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index c01552410..ebd587d26 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -297,7 +297,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end 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 render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity}) end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index c12cd7f8a..b6ae7c7f7 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -12,6 +12,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do CommonAPI.post(user, data) end + def delete(%User{} = user, id) do + # TwitterAPI does not have an "unretweet" endpoint; instead this is done + # via the "destroy" endpoint. Therefore, there is a need to handle + # when the status to "delete" is actually an Announce (repeat) object. + with %Activity{data: %{"type" => type}} <- Repo.get(Activity, id) do + case type do + "Announce" -> unrepeat(user, id) + _ -> CommonAPI.delete(id, user) + end + end + end + def follow(%User{} = follower, params) do with {:ok, %User{} = followed} <- get_user(params), {:ok, follower} <- User.follow(follower, followed), @@ -64,6 +76,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do end end + defp unrepeat(%User{} = user, ap_id_or_id) do + with {:ok, _unannounce, activity, _object} <- CommonAPI.unrepeat(ap_id_or_id, user) do + {:ok, activity} + end + end + def fav(%User{} = user, ap_id_or_id) do with {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.favorite(ap_id_or_id, user), %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 986436326..e1c1cb5d4 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -150,8 +150,8 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def delete_post(%{assigns: %{user: user}} = conn, %{"id" => id}) do - with {:ok, delete} <- CommonAPI.delete(id, user) do - render(conn, ActivityView, "activity.json", %{activity: delete, for: user}) + with {:ok, activity} <- TwitterAPI.delete(id, user) do + render(conn, ActivityView, "activity.json", %{activity: activity, for: user}) end end @@ -229,12 +229,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end - def unretweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do - with {:ok, activity} <- TwitterAPI.unrepeat(user, id) do - render(conn, ActivityView, "activity.json", %{activity: activity, for: user}) - end - end - def register(conn, params) do with {:ok, user} <- TwitterAPI.register_user(params) do render(conn, UserView, "show.json", %{user: user}) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 85a6aecf0..6a07da775 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -284,9 +284,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do {:ok, announce_activity, object} = ActivityPub.announce(user, object) assert object.data["announcement_count"] == 1 - {:ok, unannounce_activity, object} = ActivityPub.unannounce(user, object) + {:ok, unannounce_activity, activity, object} = ActivityPub.unannounce(user, object) assert object.data["announcement_count"] == 0 + assert activity == announce_activity + assert unannounce_activity.data["to"] == [ User.ap_followers(user), note_activity.data["actor"] From 32a26eb91048bb92abfd3c7770dc0d72855101c3 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 18 Apr 2018 20:41:12 -0400 Subject: [PATCH 10/32] Fix TwitterAPI.delete call --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index e1c1cb5d4..02b4e9eb0 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -150,7 +150,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def delete_post(%{assigns: %{user: user}} = conn, %{"id" => id}) do - with {:ok, activity} <- TwitterAPI.delete(id, user) do + with {:ok, activity} <- TwitterAPI.delete(user, id) do render(conn, ActivityView, "activity.json", %{activity: activity, for: user}) end end From 4b9f2ab526104d27441dad31820ca746bbb94f0e Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 20 Apr 2018 23:09:19 -0400 Subject: [PATCH 11/32] Fix federation of unreblog activity --- lib/pleroma/web/activity_pub/activity_pub.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index dccd2e757..215ddc57a 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -144,6 +144,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do with %Activity{} = activity <- get_existing_announce(actor.ap_id, object), unannounce_data <- make_unannounce_data(actor, object), {:ok, unannounce_activity} <- insert(unannounce_data, local), + :ok <- maybe_federate(activity), {:ok, _activity} <- Repo.delete(activity), {:ok, object} <- remove_announce_from_object(activity, object) do {:ok, unannounce_activity, activity, object} From f0798440de96139f5717e90582e41ddb6ce5a0ce Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 20 Apr 2018 23:22:16 -0400 Subject: [PATCH 12/32] Use correct activity for undo --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/activity_pub/utils.ex | 4 ++-- test/web/activity_pub/activity_pub_test.exs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 215ddc57a..ace230804 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -142,7 +142,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def unannounce(%User{} = actor, %Object{} = object, local \\ true) do with %Activity{} = activity <- get_existing_announce(actor.ap_id, object), - unannounce_data <- make_unannounce_data(actor, object), + unannounce_data <- make_unannounce_data(actor, activity), {:ok, unannounce_activity} <- insert(unannounce_data, local), :ok <- maybe_federate(activity), {:ok, _activity} <- Repo.delete(activity), diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 1f740eda5..9e2fa1fb2 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -283,13 +283,13 @@ defmodule Pleroma.Web.ActivityPub.Utils do """ def make_unannounce_data( %User{ap_id: ap_id} = user, - %Object{data: %{"id" => id, "context" => context}} = object + %Activity{data: %{"id" => id, "context" => context}} = activity ) do %{ "type" => "Undo", "actor" => ap_id, "object" => id, - "to" => [user.follower_address, object.data["actor"]], + "to" => [user.follower_address, activity.data["actor"]], "cc" => ["https://www.w3.org/ns/activitystreams#Public"], "context" => context } diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 6a07da775..e3258ed4e 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -291,12 +291,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert unannounce_activity.data["to"] == [ User.ap_followers(user), - note_activity.data["actor"] + announce_activity.data["actor"] ] assert unannounce_activity.data["type"] == "Undo" - assert unannounce_activity.data["object"] == object.data["id"] + assert unannounce_activity.data["object"] == announce_activity.data["id"] assert unannounce_activity.data["actor"] == user.ap_id - assert unannounce_activity.data["context"] == object.data["context"] + assert unannounce_activity.data["context"] == announce_activity.data["context"] assert Repo.get(Activity, announce_activity.id) == nil end From c649ca89586ec83407b298c20f51a25318d777b9 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 22 Apr 2018 01:55:41 -0400 Subject: [PATCH 13/32] Rename make_unannounce_data helper to make_undo_data This makes it a bit more easier to adapt for unlikes as well in the future. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/activity_pub/utils.ex | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index ace230804..0eb5829ef 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -142,7 +142,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def unannounce(%User{} = actor, %Object{} = object, local \\ true) do with %Activity{} = activity <- get_existing_announce(actor.ap_id, object), - unannounce_data <- make_unannounce_data(actor, activity), + unannounce_data <- make_undo_data(actor, activity), {:ok, unannounce_activity} <- insert(unannounce_data, local), :ok <- maybe_federate(activity), {:ok, _activity} <- Repo.delete(activity), diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 9e2fa1fb2..d2a421ea4 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -279,9 +279,9 @@ defmodule Pleroma.Web.ActivityPub.Utils do end @doc """ - Make unannounce activity data for the given actor and object + Make undo activity data for the given actor and object """ - def make_unannounce_data( + def make_undo_data( %User{ap_id: ap_id} = user, %Activity{data: %{"id" => id, "context" => context}} = activity ) do From b1742eca4292f99ac256408acf6441d4f3eaa346 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 22 Apr 2018 19:42:28 -0400 Subject: [PATCH 14/32] Revert "Rename make_unannounce_data helper to make_undo_data" This reverts commit c649ca89586ec83407b298c20f51a25318d777b9. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/activity_pub/utils.ex | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 0eb5829ef..ace230804 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -142,7 +142,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def unannounce(%User{} = actor, %Object{} = object, local \\ true) do with %Activity{} = activity <- get_existing_announce(actor.ap_id, object), - unannounce_data <- make_undo_data(actor, activity), + unannounce_data <- make_unannounce_data(actor, activity), {:ok, unannounce_activity} <- insert(unannounce_data, local), :ok <- maybe_federate(activity), {:ok, _activity} <- Repo.delete(activity), diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index d2a421ea4..9e2fa1fb2 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -279,9 +279,9 @@ defmodule Pleroma.Web.ActivityPub.Utils do end @doc """ - Make undo activity data for the given actor and object + Make unannounce activity data for the given actor and object """ - def make_undo_data( + def make_unannounce_data( %User{ap_id: ap_id} = user, %Activity{data: %{"id" => id, "context" => context}} = activity ) do From 8c0806539c1eac776db0634e2888927f1dd2141d Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 22 Apr 2018 21:28:51 -0400 Subject: [PATCH 15/32] Embed announce activity data instead of linking to it --- lib/pleroma/web/activity_pub/activity_pub.ex | 9 +++++++-- lib/pleroma/web/activity_pub/utils.ex | 9 ++++++--- test/web/activity_pub/activity_pub_test.exs | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index ace230804..63d893039 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -140,9 +140,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end - def unannounce(%User{} = actor, %Object{} = object, local \\ true) do + def unannounce( + %User{} = actor, + %Object{} = object, + local \\ true, + activity_id \\ nil + ) do with %Activity{} = activity <- get_existing_announce(actor.ap_id, object), - unannounce_data <- make_unannounce_data(actor, activity), + unannounce_data <- make_unannounce_data(actor, activity, activity_id), {:ok, unannounce_activity} <- insert(unannounce_data, local), :ok <- maybe_federate(activity), {:ok, _activity} <- Repo.delete(activity), diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 9e2fa1fb2..10cc044fe 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -283,16 +283,19 @@ defmodule Pleroma.Web.ActivityPub.Utils do """ def make_unannounce_data( %User{ap_id: ap_id} = user, - %Activity{data: %{"id" => id, "context" => context}} = activity + %Activity{data: %{"context" => context}} = activity, + activity_id ) do - %{ + data = %{ "type" => "Undo", "actor" => ap_id, - "object" => id, + "object" => activity.data, "to" => [user.follower_address, activity.data["actor"]], "cc" => ["https://www.w3.org/ns/activitystreams#Public"], "context" => context } + + if activity_id, do: Map.put(data, "id", activity_id), else: data end def add_announce_to_object(%Activity{data: %{"actor" => actor}}, object) do diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index e3258ed4e..208cc42d2 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -292,9 +292,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert unannounce_activity.data["to"] == [ User.ap_followers(user), announce_activity.data["actor"] - ] + ] assert unannounce_activity.data["type"] == "Undo" - assert unannounce_activity.data["object"] == announce_activity.data["id"] + assert unannounce_activity.data["object"] == announce_activity.data assert unannounce_activity.data["actor"] == user.ap_id assert unannounce_activity.data["context"] == announce_activity.data["context"] From 0df1a4efc841af4a12f45c1551f372d867ff7e1d Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 25 Apr 2018 00:46:06 -0400 Subject: [PATCH 16/32] Fix comment grammar --- lib/pleroma/web/twitter_api/twitter_api.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index b6ae7c7f7..5477211dc 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -14,7 +14,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do def delete(%User{} = user, id) do # TwitterAPI does not have an "unretweet" endpoint; instead this is done - # via the "destroy" endpoint. Therefore, there is a need to handle + # via the "destroy" endpoint. Therefore, we need to handle # when the status to "delete" is actually an Announce (repeat) object. with %Activity{data: %{"type" => type}} <- Repo.get(Activity, id) do case type do From e981280fa74ddccb02c7deb27bd5cc5e85f9fc8f Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 25 Apr 2018 01:43:45 -0400 Subject: [PATCH 17/32] Formatting fixes --- test/web/activity_pub/activity_pub_test.exs | 7 ++++--- test/web/mastodon_api/mastodon_api_controller_test.exs | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 31ac10d70..d9f00613a 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -280,8 +280,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do user = insert(:user) # Unannouncing an object that is not announced does nothing - #{:ok, object} = ActivityPub.unannounce(user, object) - #assert object.data["announcement_count"] == 0 + # {:ok, object} = ActivityPub.unannounce(user, object) + # assert object.data["announcement_count"] == 0 {:ok, announce_activity, object} = ActivityPub.announce(user, object) assert object.data["announcement_count"] == 1 @@ -294,7 +294,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert unannounce_activity.data["to"] == [ User.ap_followers(user), announce_activity.data["actor"] - ] + ] + assert unannounce_activity.data["type"] == "Undo" assert unannounce_activity.data["object"] == announce_activity.data["id"] assert unannounce_activity.data["actor"] == user.ap_id diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 2a24037d7..14f8c3c42 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -276,8 +276,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> assign(:user, user) |> post("/api/v1/statuses/#{activity.id}/unreblog") - assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} = - json_response(conn, 200) + assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} = json_response(conn, 200) assert to_string(activity.id) == id end From 8b4ee0ea51431e268011781403bc97864b294989 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 4 May 2018 03:19:48 -0400 Subject: [PATCH 18/32] Fix formatting --- test/web/activity_pub/activity_pub_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 7735e1bf8..155965de8 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -295,7 +295,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do User.ap_followers(user), announce_activity.data["actor"] ] - + assert unannounce_activity.data["type"] == "Undo" assert unannounce_activity.data["object"] == announce_activity.data assert unannounce_activity.data["actor"] == user.ap_id From 4d5ec883b7e7f54d92574a4cf0bdda781e7423e2 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 8 May 2018 21:52:21 -0400 Subject: [PATCH 19/32] Federate correct activity --- lib/pleroma/web/activity_pub/activity_pub.ex | 12 ++++++------ lib/pleroma/web/ostatus/activity_representer.ex | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 5f11b8410..334cfcc5b 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -151,13 +151,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do local \\ true, activity_id \\ nil ) do - with %Activity{} = activity <- get_existing_announce(actor.ap_id, object), - unannounce_data <- make_unannounce_data(actor, activity, activity_id), + with %Activity{} = announce_activity <- get_existing_announce(actor.ap_id, object), + unannounce_data <- make_unannounce_data(actor, announce_activity, activity_id), {:ok, unannounce_activity} <- insert(unannounce_data, local), - :ok <- maybe_federate(activity), - {:ok, _activity} <- Repo.delete(activity), - {:ok, object} <- remove_announce_from_object(activity, object) do - {:ok, unannounce_activity, activity, object} + :ok <- maybe_federate(unannounce_activity), + {:ok, _activity} <- Repo.delete(announce_activity), + {:ok, object} <- remove_announce_from_object(announce_activity, object) do + {:ok, unannounce_activity, announce_activity, object} else _e -> {:ok, object} end diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 921a89bd0..1e9d4a7fb 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -240,7 +240,13 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do inserted_at = activity.data["published"] author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: [] - follow_activity = Activity.get_by_ap_id(activity.data["object"]) + + follow_activity = + if is_map(activity.data["object"]) do + Activity.get_by_ap_id(activity.data["object"]["id"]) + else + Activity.get_by_ap_id(activity.data["object"]) + end mentions = (activity.recipients || []) |> get_mentions From e55f69a676eab6ab30f15bdab2a4141a5f6ccf75 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 8 May 2018 23:50:19 -0400 Subject: [PATCH 20/32] Handle Undo activites containing an Announce --- .../web/activity_pub/transmogrifier.ex | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 2871a2544..8785ddaa9 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -220,9 +220,27 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do end end + def handle_incoming( + %{ + "type" => "Undo", + "object" => %{"type" => "Announce", "id" => object_id}, + "actor" => actor, + "id" => id + } = data + ) do + with %User{} = actor <- User.get_or_fetch_by_ap_id(actor), + {:ok, object} <- + get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id), + {:ok, activity} <- ActivityPub.unannounce(object, false) do + {:ok, activity} + else + e -> :error + end + end + # TODO # Accept - # Undo + # Undo for non-Announce def handle_incoming(_), do: :error From 54f6628590414193b9eda347be9def924783b115 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 8 May 2018 23:59:36 -0400 Subject: [PATCH 21/32] Change argument order and call correct # of args --- lib/pleroma/web/activity_pub/activity_pub.ex | 4 ++-- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 334cfcc5b..95671ec3b 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -148,8 +148,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def unannounce( %User{} = actor, %Object{} = object, - local \\ true, - activity_id \\ nil + activity_id \\ nil, + local \\ true ) do with %Activity{} = announce_activity <- get_existing_announce(actor.ap_id, object), unannounce_data <- make_unannounce_data(actor, announce_activity, activity_id), diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 8785ddaa9..f8fb79ac0 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -231,7 +231,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do with %User{} = actor <- User.get_or_fetch_by_ap_id(actor), {:ok, object} <- get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id), - {:ok, activity} <- ActivityPub.unannounce(object, false) do + {:ok, activity} <- ActivityPub.unannounce(actor, object, id, false) do {:ok, activity} else e -> :error From 900c7354678e2c5c0a6ec05e4e83ce6358c9666b Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 9 May 2018 00:04:14 -0400 Subject: [PATCH 22/32] Match proper number of values from unannounce --- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index f8fb79ac0..586fe2eb2 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -231,7 +231,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do with %User{} = actor <- User.get_or_fetch_by_ap_id(actor), {:ok, object} <- get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id), - {:ok, activity} <- ActivityPub.unannounce(actor, object, id, false) do + {:ok, activity, _, _} <- ActivityPub.unannounce(actor, object, id, false) do {:ok, activity} else e -> :error From 07fdc072382007812dc6af80fa2912f6b6d987b8 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 01:45:10 -0400 Subject: [PATCH 23/32] Do not send non-follow undos over ostatus for now --- .../web/ostatus/activity_representer.ex | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 1e9d4a7fb..4f1976e1e 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -250,23 +250,30 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do mentions = (activity.recipients || []) |> get_mentions - [ - {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']}, - {:"activity:verb", ['http://activitystrea.ms/schema/1.0/unfollow']}, - {:id, h.(activity.data["id"])}, - {:title, ['#{user.nickname} stopped following #{follow_activity.data["object"]}']}, - {:content, [type: 'html'], - ['#{user.nickname} stopped following #{follow_activity.data["object"]}']}, - {:published, h.(inserted_at)}, - {:updated, h.(updated_at)}, - {:"activity:object", - [ - {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/person']}, - {:id, h.(follow_activity.data["object"])}, - {:uri, h.(follow_activity.data["object"])} - ]}, - {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []} - ] ++ mentions ++ author + case follow_activity.data["type"] do + "Follow" -> + [ + {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']}, + {:"activity:verb", ['http://activitystrea.ms/schema/1.0/unfollow']}, + {:id, h.(activity.data["id"])}, + {:title, ['#{user.nickname} stopped following #{follow_activity.data["object"]}']}, + {:content, [type: 'html'], + ['#{user.nickname} stopped following #{follow_activity.data["object"]}']}, + {:published, h.(inserted_at)}, + {:updated, h.(updated_at)}, + {:"activity:object", + [ + {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/person']}, + {:id, h.(follow_activity.data["object"])}, + {:uri, h.(follow_activity.data["object"])} + ]}, + {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], + []} + ] ++ mentions ++ author + + _ -> + nil + end end def to_simple_form(%{data: %{"type" => "Delete"}} = activity, user, with_author) do From 42268b0981e47cacd9f27b985dcd0bf08819258b Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 01:48:56 -0400 Subject: [PATCH 24/32] Use [] instead of nil --- lib/pleroma/web/ostatus/activity_representer.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 4f1976e1e..26d02a831 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -271,8 +271,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do []} ] ++ mentions ++ author - _ -> - nil + _ -> [] end end From 0b527b552887d33794c64e82da13fe037fe0b5b2 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 11:53:06 -0400 Subject: [PATCH 25/32] Revert "Use [] instead of nil" This reverts commit 42268b0981e47cacd9f27b985dcd0bf08819258b. --- lib/pleroma/web/ostatus/activity_representer.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 26d02a831..4f1976e1e 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -271,7 +271,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do []} ] ++ mentions ++ author - _ -> [] + _ -> + nil end end From 4151cbe6b279a0db8b2920b9ebfc0d496f0cb395 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 11:53:28 -0400 Subject: [PATCH 26/32] Revert "Do not send non-follow undos over ostatus for now" This reverts commit 07fdc072382007812dc6af80fa2912f6b6d987b8. --- .../web/ostatus/activity_representer.ex | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 4f1976e1e..1e9d4a7fb 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -250,30 +250,23 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do mentions = (activity.recipients || []) |> get_mentions - case follow_activity.data["type"] do - "Follow" -> - [ - {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']}, - {:"activity:verb", ['http://activitystrea.ms/schema/1.0/unfollow']}, - {:id, h.(activity.data["id"])}, - {:title, ['#{user.nickname} stopped following #{follow_activity.data["object"]}']}, - {:content, [type: 'html'], - ['#{user.nickname} stopped following #{follow_activity.data["object"]}']}, - {:published, h.(inserted_at)}, - {:updated, h.(updated_at)}, - {:"activity:object", - [ - {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/person']}, - {:id, h.(follow_activity.data["object"])}, - {:uri, h.(follow_activity.data["object"])} - ]}, - {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], - []} - ] ++ mentions ++ author - - _ -> - nil - end + [ + {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']}, + {:"activity:verb", ['http://activitystrea.ms/schema/1.0/unfollow']}, + {:id, h.(activity.data["id"])}, + {:title, ['#{user.nickname} stopped following #{follow_activity.data["object"]}']}, + {:content, [type: 'html'], + ['#{user.nickname} stopped following #{follow_activity.data["object"]}']}, + {:published, h.(inserted_at)}, + {:updated, h.(updated_at)}, + {:"activity:object", + [ + {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/person']}, + {:id, h.(follow_activity.data["object"])}, + {:uri, h.(follow_activity.data["object"])} + ]}, + {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []} + ] ++ mentions ++ author end def to_simple_form(%{data: %{"type" => "Delete"}} = activity, user, with_author) do From 271fb5ccb13cfbe38452c78d0e843840d6106cfe Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 11:59:53 -0400 Subject: [PATCH 27/32] Probably better way of handling non-follow undos in ostatus --- .../web/ostatus/activity_representer.ex | 36 ++++++++++--------- lib/pleroma/web/salmon/salmon.ex | 11 +++--- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 1e9d4a7fb..730a3ac11 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -250,23 +250,25 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do mentions = (activity.recipients || []) |> get_mentions - [ - {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']}, - {:"activity:verb", ['http://activitystrea.ms/schema/1.0/unfollow']}, - {:id, h.(activity.data["id"])}, - {:title, ['#{user.nickname} stopped following #{follow_activity.data["object"]}']}, - {:content, [type: 'html'], - ['#{user.nickname} stopped following #{follow_activity.data["object"]}']}, - {:published, h.(inserted_at)}, - {:updated, h.(updated_at)}, - {:"activity:object", - [ - {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/person']}, - {:id, h.(follow_activity.data["object"])}, - {:uri, h.(follow_activity.data["object"])} - ]}, - {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []} - ] ++ mentions ++ author + if follow_activity do + [ + {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']}, + {:"activity:verb", ['http://activitystrea.ms/schema/1.0/unfollow']}, + {:id, h.(activity.data["id"])}, + {:title, ['#{user.nickname} stopped following #{follow_activity.data["object"]}']}, + {:content, [type: 'html'], + ['#{user.nickname} stopped following #{follow_activity.data["object"]}']}, + {:published, h.(inserted_at)}, + {:updated, h.(updated_at)}, + {:"activity:object", + [ + {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/person']}, + {:id, h.(follow_activity.data["object"])}, + {:uri, h.(follow_activity.data["object"])} + ]}, + {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []} + ] ++ mentions ++ author + end end def to_simple_form(%{data: %{"type" => "Delete"}} = activity, user, with_author) do diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 10542fd00..562ec3d9c 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -187,13 +187,14 @@ defmodule Pleroma.Web.Salmon do def publish(%{info: %{"keys" => keys}} = user, %{data: %{"type" => type}} = activity, poster) when type in @supported_activities do - feed = - ActivityRepresenter.to_simple_form(activity, user, true) - |> ActivityRepresenter.wrap_with_entry() - |> :xmerl.export_simple(:xmerl_xml) - |> to_string + feed = ActivityRepresenter.to_simple_form(activity, user, true) if feed do + feed = + ActivityRepresenter.wrap_with_entry(feed) + |> :xmerl.export_simple(:xmerl_xml) + |> to_string + {:ok, private, _} = keys_from_pem(keys) {:ok, feed} = encode(private, feed) From c17c55e989a47f0722b115ffba48b7a1b45b7628 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 15:29:19 -0400 Subject: [PATCH 28/32] Log error when handling unrepeats --- lib/pleroma/web/activity_pub/transmogrifier.ex | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 586fe2eb2..0c4a62762 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -216,25 +216,24 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do {:ok, activity} <- ActivityPub.delete(object, false) do {:ok, activity} else - e -> :error + e -> + Logger.error(e) + :error end end def handle_incoming( - %{ - "type" => "Undo", - "object" => %{"type" => "Announce", "id" => object_id}, - "actor" => actor, - "id" => id - } = data - ) do + %{"type" => "Undo", "object" => %{"type" => "Announce", "id" => object_id}, "actor" => actor, "id" => id} = data + ) do with %User{} = actor <- User.get_or_fetch_by_ap_id(actor), {:ok, object} <- get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id), {:ok, activity, _, _} <- ActivityPub.unannounce(actor, object, id, false) do {:ok, activity} else - e -> :error + e -> + Logger.error(e) + :error end end From 16b793656d2eb79e19224462180d2d21fb57cc29 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 15:30:47 -0400 Subject: [PATCH 29/32] Add tests for unrepeats --- test/fixtures/mastodon-undo-announce.json | 47 +++++++++++++++++++ test/web/activity_pub/transmogrifier_test.exs | 28 +++++++++++ 2 files changed, 75 insertions(+) create mode 100644 test/fixtures/mastodon-undo-announce.json diff --git a/test/fixtures/mastodon-undo-announce.json b/test/fixtures/mastodon-undo-announce.json new file mode 100644 index 000000000..2d8bca436 --- /dev/null +++ b/test/fixtures/mastodon-undo-announce.json @@ -0,0 +1,47 @@ +{ + "type": "Undo", + "signature": { + "type": "RsaSignature2017", + "signatureValue": "VU9AmHf3Pus9cWtMG/TOdxr+MRQfPHdTVKBBgFJBXhAlMhxEtcbxsu7zmqBgfIz6u0HpTCi5jRXEMftc228OJf/aBUkr4hyWADgcdmhPQgpibouDLgQf9BmnrPqb2rMbzZyt49GJkQZma8taLh077TTq6OKcnsAAJ1evEKOcRYS4OxBSwh4nI726bOXzZWoNzpTcrnm+llcUEN980sDSAS0uyZdb8AxZdfdG6DJQX4AkUD5qTpfqP/vC1ISirrNphvVhlxjUV9Amr4SYTsLx80vdZe5NjeL5Ir4jTIIQLedpxaDu1M9Q+Jpc0fYByQ2hOwUq8JxEmvHvarKjrq0Oww==", + "creator": "http://mastodon.example.org/users/admin#main-key", + "created": "2018-05-11T16:23:45Z" + }, + "object": { + "type": "Announce", + "to": [ + "http://www.w3.org/ns/activitystreams#Public" + ], + "published": "2018-05-11T16:23:37Z", + "object": "http://lostallofmy.faith/objects/acc592f0-093a-4326-856e-2ab30947ef11", + "id": "http://mastodon.example.org/users/admin/statuses/100011594053806179/activity", + "cc": [ + "http://lostallofmy.faith/users/admin", + "http://mastodon.example.org/users/admin/followers" + ], + "atomUri": "http://mastodon.example.org/users/admin/statuses/100011594053806179/activity", + "actor": "http://mastodon.example.org/users/admin" + }, + "id": "http://mastodon.example.org/users/admin#announces/100011594053806179/undo", + "actor": "http://mastodon.example.org/users/admin", + "@context": [ + "http://www.w3.org/ns/activitystreams", + "http://w3id.org/security/v1", + { + "toot": "http://joinmastodon.org/ns#", + "sensitive": "as:sensitive", + "ostatus": "http://ostatus.org#", + "movedTo": "as:movedTo", + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "focalPoint": { + "@id": "toot:focalPoint", + "@container": "@list" + }, + "featured": "toot:featured", + "conversation": "ostatus:conversation", + "atomUri": "ostatus:atomUri", + "Hashtag": "as:Hashtag", + "Emoji": "toot:Emoji" + } + ] +} diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index eb093262f..a3408da9d 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -232,6 +232,34 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do refute Repo.get(Activity, activity.id) end + + test "it works for incoming unannounces with an existing notice" do + user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"}) + + announce_data = + File.read!("test/fixtures/mastodon-announce.json") + |> Poison.decode!() + |> Map.put("object", activity.data["object"]["id"]) + + {:ok, %Activity{data: announce_data, local: false}} = + Transmogrifier.handle_incoming(announce_data) + + data = + File.read!("test/fixtures/mastodon-undo-announce.json") + |> Poison.decode!() + |> Map.put("object", announce_data) + |> Map.put("actor", announce_data["actor"]) + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + + assert data["type"] == "Undo" + assert data["object"]["type"] == "Announce" + assert data["object"]["object"] == activity.data["object"]["id"] + + assert data["object"]["id"] == + "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity" + end end describe "prepare outgoing" do From 4d887475618ebceacd76840a2a7be6d6ad4987e6 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 15:34:46 -0400 Subject: [PATCH 30/32] Revert "Log error when handling unrepeats" This reverts commit c17c55e989a47f0722b115ffba48b7a1b45b7628. --- lib/pleroma/web/activity_pub/transmogrifier.ex | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 0c4a62762..586fe2eb2 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -216,24 +216,25 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do {:ok, activity} <- ActivityPub.delete(object, false) do {:ok, activity} else - e -> - Logger.error(e) - :error + e -> :error end end def handle_incoming( - %{"type" => "Undo", "object" => %{"type" => "Announce", "id" => object_id}, "actor" => actor, "id" => id} = data - ) do + %{ + "type" => "Undo", + "object" => %{"type" => "Announce", "id" => object_id}, + "actor" => actor, + "id" => id + } = data + ) do with %User{} = actor <- User.get_or_fetch_by_ap_id(actor), {:ok, object} <- get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id), {:ok, activity, _, _} <- ActivityPub.unannounce(actor, object, id, false) do {:ok, activity} else - e -> - Logger.error(e) - :error + e -> :error end end From 694e3769542ae661d3967c1c03d24be0496d98cc Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sat, 12 May 2018 11:10:49 -0400 Subject: [PATCH 31/32] Update test fixture --- test/fixtures/mastodon-undo-announce.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/fixtures/mastodon-undo-announce.json b/test/fixtures/mastodon-undo-announce.json index 2d8bca436..05332bed2 100644 --- a/test/fixtures/mastodon-undo-announce.json +++ b/test/fixtures/mastodon-undo-announce.json @@ -12,13 +12,13 @@ "http://www.w3.org/ns/activitystreams#Public" ], "published": "2018-05-11T16:23:37Z", - "object": "http://lostallofmy.faith/objects/acc592f0-093a-4326-856e-2ab30947ef11", - "id": "http://mastodon.example.org/users/admin/statuses/100011594053806179/activity", + "object": "http://mastodon.example.org/@admin/99541947525187367", + "id": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity", "cc": [ - "http://lostallofmy.faith/users/admin", + "http://mastodon.example.org/users/admin", "http://mastodon.example.org/users/admin/followers" ], - "atomUri": "http://mastodon.example.org/users/admin/statuses/100011594053806179/activity", + "atomUri": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity", "actor": "http://mastodon.example.org/users/admin" }, "id": "http://mastodon.example.org/users/admin#announces/100011594053806179/undo", From 54ccbd8479a77f613e8efd9568b3611c28d21742 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 13 May 2018 03:42:31 -0400 Subject: [PATCH 32/32] Use original status id instead of announce id --- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 586fe2eb2..7f12f4489 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -223,7 +223,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do def handle_incoming( %{ "type" => "Undo", - "object" => %{"type" => "Announce", "id" => object_id}, + "object" => %{"type" => "Announce", "object" => object_id}, "actor" => actor, "id" => id } = data