From b949577472d5e4db1aeacb9ff2162eb89440130c Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sat, 14 Apr 2018 03:39:16 -0400 Subject: 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 +++++++++ .../web/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(+) (limited to 'lib') 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}) -- cgit v1.2.3 From d16877251a42545bfbef383b1a023aa029730c44 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Mon, 16 Apr 2018 10:59:32 -0400 Subject: doc fixes --- lib/pleroma/web/activity_pub/utils.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') 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, -- cgit v1.2.3 From 42279f54cfa6b1728f71de0a14cfde8e615141e7 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Mon, 16 Apr 2018 23:30:52 -0400 Subject: Return target status in MastoAPI endpoint instead of reblog activity --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3 From 85bd191291fdf0fb5f1807b3aa95913a607ddc6a Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 17 Apr 2018 04:12:16 -0400 Subject: Remove unretweet function for now --- lib/pleroma/web/twitter_api/twitter_api.ex | 7 ------- 1 file changed, 7 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3 From c9e7b984d5d09f6b1ecdeb04e888b9000de6e11c Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 17 Apr 2018 04:13:08 -0400 Subject: Add make_unannounce_data helper function --- lib/pleroma/web/activity_pub/utils.ex | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib') 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) -- cgit v1.2.3 From 0251690e96d683fb5f5eee11e2dfff4c008676cf Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 17 Apr 2018 20:35:07 -0400 Subject: 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(-) (limited to 'lib') 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 -- cgit v1.2.3 From 687db1bc3a13d3303865a104f0475a6fc4671037 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 18 Apr 2018 03:39:42 -0400 Subject: 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 ++-- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3 From 7b4f55238eeb8561c6a8e43321cd965667cefabe Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 18 Apr 2018 06:00:40 -0400 Subject: Handle unrepeats via the TwitterAPI --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- .../web/mastodon_api/mastodon_api_controller.ex | 2 +- lib/pleroma/web/twitter_api/twitter_api.ex | 18 ++++++++++++++++++ lib/pleroma/web/twitter_api/twitter_api_controller.ex | 10 ++-------- 4 files changed, 22 insertions(+), 10 deletions(-) (limited to 'lib') 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}) -- cgit v1.2.3 From 32a26eb91048bb92abfd3c7770dc0d72855101c3 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 18 Apr 2018 20:41:12 -0400 Subject: Fix TwitterAPI.delete call --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') 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 -- cgit v1.2.3 From 4b9f2ab526104d27441dad31820ca746bbb94f0e Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 20 Apr 2018 23:09:19 -0400 Subject: Fix federation of unreblog activity --- lib/pleroma/web/activity_pub/activity_pub.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') 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} -- cgit v1.2.3 From f0798440de96139f5717e90582e41ddb6ce5a0ce Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 20 Apr 2018 23:22:16 -0400 Subject: Use correct activity for undo --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/activity_pub/utils.ex | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') 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 } -- cgit v1.2.3 From c649ca89586ec83407b298c20f51a25318d777b9 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 22 Apr 2018 01:55:41 -0400 Subject: 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(-) (limited to 'lib') 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 -- cgit v1.2.3 From b1742eca4292f99ac256408acf6441d4f3eaa346 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 22 Apr 2018 19:42:28 -0400 Subject: 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(-) (limited to 'lib') 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 -- cgit v1.2.3 From 8c0806539c1eac776db0634e2888927f1dd2141d Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 22 Apr 2018 21:28:51 -0400 Subject: 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 ++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3 From 0df1a4efc841af4a12f45c1551f372d867ff7e1d Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 25 Apr 2018 00:46:06 -0400 Subject: Fix comment grammar --- lib/pleroma/web/twitter_api/twitter_api.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') 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 -- cgit v1.2.3 From a3d1d4894fdd8dd0133e1d2c6fde9d95f49dfcc7 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 29 Apr 2018 02:53:19 +0000 Subject: ActivityPub core: fix handling of unlisted statuses by leveraging a similar strategy as for blocks --- lib/pleroma/web/activity_pub/activity_pub.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 984d1162d..9e0b038ed 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -212,11 +212,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do Repo.all(query) end - # TODO: Make this work properly with unlisted. def fetch_public_activities(opts \\ %{}) do q = fetch_activities_query(["https://www.w3.org/ns/activitystreams#Public"], opts) q + |> restrict_unlisted() |> Repo.all() |> Enum.reverse() end @@ -321,6 +321,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_blocked(query, _), do: query + defp restrict_unlisted(query) do + from( + activity in query, + where: fragment("not (?->'cc' \\?| ?)", activity.data, ^["https://www.w3.org/ns/activitystreams#Public"]) + ) + end + def fetch_activities_query(recipients, opts \\ %{}) do base_query = from( -- cgit v1.2.3 From 4d5ec883b7e7f54d92574a4cf0bdda781e7423e2 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 8 May 2018 21:52:21 -0400 Subject: 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(-) (limited to 'lib') 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 -- cgit v1.2.3 From e55f69a676eab6ab30f15bdab2a4141a5f6ccf75 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 8 May 2018 23:50:19 -0400 Subject: Handle Undo activites containing an Announce --- lib/pleroma/web/activity_pub/transmogrifier.ex | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lib') 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 -- cgit v1.2.3 From 54f6628590414193b9eda347be9def924783b115 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 8 May 2018 23:59:36 -0400 Subject: 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(-) (limited to 'lib') 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 -- cgit v1.2.3 From 900c7354678e2c5c0a6ec05e4e83ce6358c9666b Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 9 May 2018 00:04:14 -0400 Subject: Match proper number of values from unannounce --- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') 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 -- cgit v1.2.3 From e9e6f37bda2620147a18eb0edb472a1aec46e8f9 Mon Sep 17 00:00:00 2001 From: href Date: Thu, 10 May 2018 18:34:09 +0200 Subject: Chain policies - The `:pleroma, :instance, :rewrite_policy` can now be either a policy or a list of policies - Made a behaviour for MRF policies --- lib/pleroma/web/activity_pub/activity_pub.ex | 5 ++--- lib/pleroma/web/activity_pub/mrf.ex | 21 +++++++++++++++++++++ lib/pleroma/web/activity_pub/mrf/drop_policy.ex | 2 ++ lib/pleroma/web/activity_pub/mrf/noop_policy.ex | 3 +++ lib/pleroma/web/activity_pub/mrf/simple_policy.ex | 2 ++ 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 lib/pleroma/web/activity_pub/mrf.ex (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index fde6e12d7..956c223ee 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -1,6 +1,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do alias Pleroma.{Activity, Repo, Object, Upload, User, Notification} - alias Pleroma.Web.ActivityPub.Transmogrifier + alias Pleroma.Web.ActivityPub.{Transmogrifier, MRF} alias Pleroma.Web.WebFinger alias Pleroma.Web.Federator alias Pleroma.Web.OStatus @@ -11,7 +11,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do @httpoison Application.get_env(:pleroma, :httpoison) @instance Application.get_env(:pleroma, :instance) - @rewrite_policy Keyword.get(@instance, :rewrite_policy) def get_recipients(data) do (data["to"] || []) ++ (data["cc"] || []) @@ -20,7 +19,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do 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, map} <- @rewrite_policy.filter(map), + {:ok, map} <- MRF.filter(map), :ok <- insert_full_object(map) do {:ok, activity} = Repo.insert(%Activity{ diff --git a/lib/pleroma/web/activity_pub/mrf.ex b/lib/pleroma/web/activity_pub/mrf.ex new file mode 100644 index 000000000..6d5aa9515 --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf.ex @@ -0,0 +1,21 @@ +defmodule Pleroma.Web.ActivityPub.MRF do + + @callback filter(Map.t) :: {:ok | :reject, Map.t} + + def filter(object) do + get_policies() + |> Enum.reduce({:ok, object}, fn + (policy, {:ok, object}) -> + policy.filter(object) + (_, error) -> error + end) + end + + def get_policies() do + Application.get_env(:pleroma, :instance, []) + |> Keyword.get(:rewrite_policy, []) + |> get_policies() + end + def get_policies(policy) when is_atom(policy), do: [policy] + def get_policies(policies) when is_list(policies), do: policies +end diff --git a/lib/pleroma/web/activity_pub/mrf/drop_policy.ex b/lib/pleroma/web/activity_pub/mrf/drop_policy.ex index 4333bca28..811947943 100644 --- a/lib/pleroma/web/activity_pub/mrf/drop_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/drop_policy.ex @@ -1,6 +1,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.DropPolicy do require Logger + @behaviour Pleroma.Web.ActivityPub.MRF + @impl true def filter(object) do Logger.info("REJECTING #{inspect(object)}") {:reject, object} diff --git a/lib/pleroma/web/activity_pub/mrf/noop_policy.ex b/lib/pleroma/web/activity_pub/mrf/noop_policy.ex index 9dd3acb04..e26f60d26 100644 --- a/lib/pleroma/web/activity_pub/mrf/noop_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/noop_policy.ex @@ -1,4 +1,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do + @behaviour Pleroma.Web.ActivityPub.MRF + + @impl true def filter(object) do {:ok, object} end diff --git a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex index d840d759d..8d770387d 100644 --- a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex @@ -1,5 +1,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do alias Pleroma.User + @behaviour Pleroma.Web.ActivityPub.MRF @mrf_policy Application.get_env(:pleroma, :mrf_simple) @@ -69,6 +70,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do end end + @impl true def filter(object) do actor_info = URI.parse(object["actor"]) -- cgit v1.2.3 From c220a6db432f9b508dcf2ee9edf4ceee660672fc Mon Sep 17 00:00:00 2001 From: href Date: Thu, 10 May 2018 18:51:58 +0200 Subject: format & made get_policies/1 private --- lib/pleroma/web/activity_pub/mrf.ex | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf.ex b/lib/pleroma/web/activity_pub/mrf.ex index 6d5aa9515..0a4e2bf80 100644 --- a/lib/pleroma/web/activity_pub/mrf.ex +++ b/lib/pleroma/web/activity_pub/mrf.ex @@ -1,13 +1,14 @@ defmodule Pleroma.Web.ActivityPub.MRF do - - @callback filter(Map.t) :: {:ok | :reject, Map.t} + @callback filter(Map.t()) :: {:ok | :reject, Map.t()} def filter(object) do get_policies() |> Enum.reduce({:ok, object}, fn - (policy, {:ok, object}) -> + policy, {:ok, object} -> policy.filter(object) - (_, error) -> error + + _, error -> + error end) end @@ -16,6 +17,8 @@ defmodule Pleroma.Web.ActivityPub.MRF do |> Keyword.get(:rewrite_policy, []) |> get_policies() end - def get_policies(policy) when is_atom(policy), do: [policy] - def get_policies(policies) when is_list(policies), do: policies + + defp get_policies(policy) when is_atom(policy), do: [policy] + defp get_policies(policies) when is_list(policies), do: policies + defp get_policies(_), do: [] end -- cgit v1.2.3 From 07fdc072382007812dc6af80fa2912f6b6d987b8 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 01:45:10 -0400 Subject: Do not send non-follow undos over ostatus for now --- lib/pleroma/web/ostatus/activity_representer.ex | 41 +++++++++++++++---------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3 From 42268b0981e47cacd9f27b985dcd0bf08819258b Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 01:48:56 -0400 Subject: Use [] instead of nil --- lib/pleroma/web/ostatus/activity_representer.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3 From 89603eda9ea51c5bd3c681fce958a4a6b446debe Mon Sep 17 00:00:00 2001 From: Pierrick Brun Date: Mon, 7 May 2018 20:51:14 +0200 Subject: do not create notification for yourself --- lib/pleroma/notification.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index e26e49c8c..e0dcd9823 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -91,7 +91,8 @@ defmodule Pleroma.Notification do # TODO move to sql, too. def create_notification(%Activity{} = activity, %User{} = user) do - unless User.blocks?(user, %{ap_id: activity.data["actor"]}) do + unless User.blocks?(user, %{ap_id: activity.data["actor"]}) or + user.ap_id == activity.data["actor"] do notification = %Notification{user_id: user.id, activity: activity} {:ok, notification} = Repo.insert(notification) Pleroma.Web.Streamer.stream("user", notification) -- cgit v1.2.3 From 0b527b552887d33794c64e82da13fe037fe0b5b2 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 11:53:06 -0400 Subject: Revert "Use [] instead of nil" This reverts commit 42268b0981e47cacd9f27b985dcd0bf08819258b. --- lib/pleroma/web/ostatus/activity_representer.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') 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 -- cgit v1.2.3 From 4151cbe6b279a0db8b2920b9ebfc0d496f0cb395 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 11:53:28 -0400 Subject: Revert "Do not send non-follow undos over ostatus for now" This reverts commit 07fdc072382007812dc6af80fa2912f6b6d987b8. --- lib/pleroma/web/ostatus/activity_representer.ex | 41 ++++++++++--------------- 1 file changed, 17 insertions(+), 24 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3 From 271fb5ccb13cfbe38452c78d0e843840d6106cfe Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 11:59:53 -0400 Subject: Probably better way of handling non-follow undos in ostatus --- lib/pleroma/web/ostatus/activity_representer.ex | 36 +++++++++++++------------ lib/pleroma/web/salmon/salmon.ex | 11 ++++---- 2 files changed, 25 insertions(+), 22 deletions(-) (limited to 'lib') 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) -- cgit v1.2.3 From c17c55e989a47f0722b115ffba48b7a1b45b7628 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 15:29:19 -0400 Subject: Log error when handling unrepeats --- lib/pleroma/web/activity_pub/transmogrifier.ex | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3 From 4d887475618ebceacd76840a2a7be6d6ad4987e6 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 15:34:46 -0400 Subject: 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(-) (limited to 'lib') 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 -- cgit v1.2.3 From 54ccbd8479a77f613e8efd9568b3611c28d21742 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 13 May 2018 03:42:31 -0400 Subject: Use original status id instead of announce id --- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') 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 -- cgit v1.2.3 From 29376fcc13ed997140f32973ee257d2406d759ae Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 13 May 2018 10:56:44 +0200 Subject: Format. --- lib/pleroma/web/activity_pub/activity_pub.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 6a413c69c..ae94b447a 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -325,7 +325,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_unlisted(query) do from( activity in query, - where: fragment("not (?->'cc' \\?| ?)", activity.data, ^["https://www.w3.org/ns/activitystreams#Public"]) + where: + fragment( + "not (?->'cc' \\?| ?)", + activity.data, + ^["https://www.w3.org/ns/activitystreams#Public"] + ) ) end -- cgit v1.2.3 From ec531ca281008e7d8d9d659e6f046a551fcb7c8a Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 13 May 2018 11:18:48 +0200 Subject: Add test. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index ae94b447a..8086c830c 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -327,7 +327,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do activity in query, where: fragment( - "not (?->'cc' \\?| ?)", + "(?->'to' \\?| ?)", activity.data, ^["https://www.w3.org/ns/activitystreams#Public"] ) -- cgit v1.2.3 From 3c3933e40bce7001b5025bf2e05412dd9c128f0f Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 13 May 2018 11:58:03 +0200 Subject: Unlisted fetching: Reverse logic Generates a faster query. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 8086c830c..d43f85ee4 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -327,7 +327,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do activity in query, where: fragment( - "(?->'to' \\?| ?)", + "not (coalesce(?->'cc', '{}'::jsonb) \\?| ?)", activity.data, ^["https://www.w3.org/ns/activitystreams#Public"] ) -- cgit v1.2.3 From 1027d1f6963b495a5abc67b05447619ce7d429db Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 13 May 2018 12:07:11 +0200 Subject: Remove 'unlisted' handling for now. It's just too slow (over 1 second on small systems, haven't looked at the queries in detail yet). We'll need some other way to handle it. --- lib/pleroma/web/activity_pub/activity_pub.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 491ad3705..4bd56d123 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -233,7 +233,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do q = fetch_activities_query(["https://www.w3.org/ns/activitystreams#Public"], opts) q - |> restrict_unlisted() + # Too slow + # |> restrict_unlisted() |> Repo.all() |> Enum.reverse() end -- cgit v1.2.3 From c7a85de35c3ef8cfca447ffdb85cd929258642df Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 13 May 2018 12:38:13 +0200 Subject: Revert "Remove 'unlisted' handling for now." This reverts commit 1027d1f6963b495a5abc67b05447619ce7d429db. --- lib/pleroma/web/activity_pub/activity_pub.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 4bd56d123..491ad3705 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -233,8 +233,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do q = fetch_activities_query(["https://www.w3.org/ns/activitystreams#Public"], opts) q - # Too slow - # |> restrict_unlisted() + |> restrict_unlisted() |> Repo.all() |> Enum.reverse() end -- cgit v1.2.3 From a16117225f9a4da9da08013ae256d8ac02ee3ec5 Mon Sep 17 00:00:00 2001 From: Syldexia Date: Fri, 11 May 2018 12:32:59 +0100 Subject: Added endpoint for user account deletion --- lib/pleroma/web/common_api/utils.ex | 17 +++++++++++++++++ lib/pleroma/web/router.ex | 2 ++ lib/pleroma/web/twitter_api/twitter_api_controller.ex | 13 +++++++++++++ 3 files changed, 32 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 57f8be894..5c2123f2d 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -1,7 +1,9 @@ defmodule Pleroma.Web.CommonAPI.Utils do alias Pleroma.{Repo, Object, Formatter, Activity} alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.User alias Calendar.Strftime + alias Comeonin.Pbkdf2 # This is a hack for twidere. def get_by_id_or_ap_id(id) do @@ -184,4 +186,19 @@ defmodule Pleroma.Web.CommonAPI.Utils do String.slice(name, 0..30) <> "…" end end + + def confirm_current_password(user, params) do + case user do + nil -> + {:error, "Invalid credentials."} + + _ -> + with %User{local: true} = db_user <- Repo.get(User, user.id), + true <- Pbkdf2.checkpw(params["password"], db_user.password_hash) do + {:ok, db_user} + else + _ -> {:error, "Invalid password."} + end + end + end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index c202cb810..829d9fc7b 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -211,6 +211,8 @@ defmodule Pleroma.Web.Router do post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner) post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background) + post("/account/delete_account", TwitterAPI.Controller, :delete_account) + post( "/account/most_recent_notification", TwitterAPI.Controller, diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index a99487738..a51cfa036 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -364,6 +364,19 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def delete_account(%{assigns: %{user: user}} = conn, params) do + case CommonAPI.Utils.confirm_current_password(user, params) do + {:ok, user} -> + case User.delete(user) do + :ok -> json(conn, %{status: "success"}) + :error -> error_json(conn, "Unable to delete user.") + end + + {:error, msg} -> + forbidden_json_reply(conn, msg) + end + end + def search(%{assigns: %{user: user}} = conn, %{"q" => _query} = params) do activities = TwitterAPI.search(user, params) -- cgit v1.2.3 From 5bfb7b4ce6c23f84c27643e9871b78b867f86b7e Mon Sep 17 00:00:00 2001 From: Syldexia Date: Sun, 13 May 2018 14:24:15 +0100 Subject: Moved account deletion stuff to somewhere that hopefully makes more sense --- lib/pleroma/web/common_api/utils.ex | 16 +++++----------- lib/pleroma/web/router.ex | 3 +-- .../web/twitter_api/controllers/util_controller.ex | 14 ++++++++++++++ lib/pleroma/web/twitter_api/twitter_api_controller.ex | 13 ------------- 4 files changed, 20 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 5c2123f2d..d9f80ee0f 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -188,17 +188,11 @@ defmodule Pleroma.Web.CommonAPI.Utils do end def confirm_current_password(user, params) do - case user do - nil -> - {:error, "Invalid credentials."} - - _ -> - with %User{local: true} = db_user <- Repo.get(User, user.id), - true <- Pbkdf2.checkpw(params["password"], db_user.password_hash) do - {:ok, db_user} - else - _ -> {:error, "Invalid password."} - end + with %User{local: true} = db_user <- Repo.get(User, user.id), + true <- Pbkdf2.checkpw(params["password"], db_user.password_hash) do + {:ok, db_user} + else + _ -> {:error, "Invalid password."} end end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 829d9fc7b..2b5209b75 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -73,6 +73,7 @@ defmodule Pleroma.Web.Router do scope "/api/pleroma", Pleroma.Web.TwitterAPI do pipe_through(:authenticated_api) post("/follow_import", UtilController, :follow_import) + post("/delete_account", UtilController, :delete_account) end scope "/oauth", Pleroma.Web.OAuth do @@ -211,8 +212,6 @@ defmodule Pleroma.Web.Router do post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner) post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background) - post("/account/delete_account", TwitterAPI.Controller, :delete_account) - post( "/account/most_recent_notification", TwitterAPI.Controller, diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index ea540b34c..3f3ddb9e4 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -4,6 +4,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do alias Pleroma.Web alias Pleroma.Web.OStatus alias Pleroma.Web.WebFinger + alias Pleroma.Web.CommonAPI alias Comeonin.Pbkdf2 alias Pleroma.Formatter alias Pleroma.Web.ActivityPub.ActivityPub @@ -195,4 +196,17 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do json(conn, "job started") end + + def delete_account(%{assigns: %{user: user}} = conn, params) do + case CommonAPI.Utils.confirm_current_password(user, params) do + {:ok, user} -> + case User.delete(user) do + :ok -> json(conn, %{status: "success"}) + :error -> json(conn, %{error: "Unable to delete user."}) + end + + {:error, msg} -> + json(conn, %{error: msg}) + end + end end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index a51cfa036..a99487738 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -364,19 +364,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end - def delete_account(%{assigns: %{user: user}} = conn, params) do - case CommonAPI.Utils.confirm_current_password(user, params) do - {:ok, user} -> - case User.delete(user) do - :ok -> json(conn, %{status: "success"}) - :error -> error_json(conn, "Unable to delete user.") - end - - {:error, msg} -> - forbidden_json_reply(conn, msg) - end - end - def search(%{assigns: %{user: user}} = conn, %{"q" => _query} = params) do activities = TwitterAPI.search(user, params) -- cgit v1.2.3 From 98b36d359a1a8c10ef9877902258d46b68331363 Mon Sep 17 00:00:00 2001 From: Syldexia Date: Sun, 13 May 2018 14:56:59 +0100 Subject: Fixed formatting and test --- lib/pleroma/web/common_api/utils.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index d9f80ee0f..e774743a2 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -189,7 +189,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do def confirm_current_password(user, params) do with %User{local: true} = db_user <- Repo.get(User, user.id), - true <- Pbkdf2.checkpw(params["password"], db_user.password_hash) do + true <- Pbkdf2.checkpw(params["password"], db_user.password_hash) do {:ok, db_user} else _ -> {:error, "Invalid password."} -- cgit v1.2.3 From 93904921381300ddeefab99350cba5f551e0e2b0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 13 May 2018 23:28:56 +0000 Subject: ActivityPub create: discard activities from deactivated users --- lib/pleroma/web/activity_pub/activity_pub.ex | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 491ad3705..76cda0b4c 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -16,9 +16,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do (data["to"] || []) ++ (data["cc"] || []) end + defp check_actor_is_active(actor) do + user = User.get_cached_by_ap_id(actor) + + if user.info["deactivated"] == true do + :reject + else + :ok + end + 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 <- check_actor_is_active(map["actor"]), {:ok, map} <- MRF.filter(map), :ok <- insert_full_object(map) do {:ok, activity} = -- cgit v1.2.3 From a6a6915aaf568dda8b784438b963e341c2fc0f29 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 13 May 2018 23:33:43 +0000 Subject: add mix task for deactivating a user by nickname --- lib/mix/tasks/deactivate_user.ex | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 lib/mix/tasks/deactivate_user.ex (limited to 'lib') diff --git a/lib/mix/tasks/deactivate_user.ex b/lib/mix/tasks/deactivate_user.ex new file mode 100644 index 000000000..96b3db6e4 --- /dev/null +++ b/lib/mix/tasks/deactivate_user.ex @@ -0,0 +1,13 @@ +defmodule Mix.Tasks.DeactivateUser do + use Mix.Task + alias Pleroma.User + + @shortdoc "Toggle deactivation status for a user" + def run([nickname]) do + Mix.Task.run("app.start") + + with user <- User.get_by_nickname(nickname) do + User.deactivate(user) + end + end +end -- cgit v1.2.3 From 1d4bbec6b3239bb83b500a6a90e6686cb682cfac Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 16 May 2018 17:55:20 +0200 Subject: Fix User search. Now uses a trigram based search. This is a lot faster and gives better results. Closes #185. --- lib/mix/tasks/sample_psql.eex | 1 + lib/pleroma/user.ex | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/sample_psql.eex b/lib/mix/tasks/sample_psql.eex index 18e322efc..bc22f166c 100644 --- a/lib/mix/tasks/sample_psql.eex +++ b/lib/mix/tasks/sample_psql.eex @@ -6,3 +6,4 @@ ALTER DATABASE pleroma_dev OWNER TO pleroma; \c pleroma_dev; --Extensions made by ecto.migrate that need superuser access CREATE EXTENSION IF NOT EXISTS citext; +CREATE EXTENSION IF NOT EXISTS pg_trgm; diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 207674999..399a66787 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -21,6 +21,7 @@ defmodule Pleroma.User do field(:local, :boolean, default: true) field(:info, :map, default: %{}) field(:follower_address, :string) + field(:search_distance, :float, virtual: true) has_many(:notifications, Notification) timestamps() @@ -399,19 +400,23 @@ defmodule Pleroma.User do User.get_or_fetch_by_nickname(query) end - q = + inner = from( u in User, - where: - fragment( - "(to_tsvector('english', ?) || to_tsvector('english', ?)) @@ plainto_tsquery('english', ?)", + select_merge: %{ + search_distance: fragment( + "? <-> (? || ?)", + ^query, u.nickname, - u.name, - ^query - ), - limit: 20 + u.name + )} ) + q = from(s in subquery(inner), + order_by: s.search_distance, + limit: 20 + ) + Repo.all(q) end -- cgit v1.2.3 From 13d4b6d2b5d17c10fb5a95e02ff668de8eeb15ea Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 18 May 2018 22:17:56 -0500 Subject: remote user deactivation: fix test failures --- lib/pleroma/web/activity_pub/activity_pub.ex | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 76cda0b4c..c026f2427 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -17,10 +17,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end defp check_actor_is_active(actor) do - user = User.get_cached_by_ap_id(actor) - - if user.info["deactivated"] == true do - :reject + if not is_nil(actor) do + with user <- User.get_cached_by_ap_id(actor), + nil <- user.info["deactivated"] do + :ok + else + _e -> :reject + end else :ok end -- cgit v1.2.3 From cce5a9cb1ce0555277d11004bcedc9e7460f4ed8 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 05:43:13 +0000 Subject: webfinger: expose the application/ld+json link alongside the older application/activity+json link --- lib/pleroma/web/web_finger/web_finger.ex | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 6ffa80a43..241dfb4c8 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -86,6 +86,7 @@ defmodule Pleroma.Web.WebFinger do "href" => "data:application/magic-public-key,#{magic_key}" }, %{"rel" => "self", "type" => "application/activity+json", "href" => user.ap_id}, + %{"rel" => "self", "type" => "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", "href" => user.ap_id}, %{ "rel" => "http://ostatus.org/schema/1.0/subscribe", "template" => OStatus.remote_follow_path() @@ -117,6 +118,7 @@ defmodule Pleroma.Web.WebFinger do {:Link, %{rel: "magic-public-key", href: "data:application/magic-public-key,#{magic_key}"}}, {:Link, %{rel: "self", type: "application/activity+json", href: user.ap_id}}, + {:Link, %{rel: "self", type: "application/ld+json; profile="https://www.w3.org/ns/activitystreams"", href: user.ap_id}}, {:Link, %{rel: "http://ostatus.org/schema/1.0/subscribe", template: OStatus.remote_follow_path()}} ] -- cgit v1.2.3 From d1f6ecf607954e725e72b8e91be5f969eebe997f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 05:46:13 +0000 Subject: webfinger: interpret application/ld+json links as an alternate to application/activity+json --- lib/pleroma/web/web_finger/web_finger.ex | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 241dfb4c8..b955bc43f 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -166,6 +166,14 @@ defmodule Pleroma.Web.WebFinger do doc ) + if ap_id == nil do + ap_id = + XML.string_from_xpath( + ~s{//Link[@rel="self" and @type="application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""]/@href}, + doc + ) + end + data = %{ "magic_key" => magic_key, "topic" => topic, @@ -185,6 +193,9 @@ defmodule Pleroma.Web.WebFinger do {"application/activity+json", "self"} -> Map.put(data, "ap_id", link["href"]) + {"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", "self"} -> + Map.put(data, "ap_id", link["href"]) + {_, "magic-public-key"} -> "data:application/magic-public-key," <> magic_key = link["href"] Map.put(data, "magic_key", magic_key) -- cgit v1.2.3 From 1a250d65afa6de25c3395fa1fad0e1d57e9ee1d2 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 06:15:21 +0000 Subject: webfinger: only do ld+json on modern json webfinger --- lib/pleroma/web/web_finger/web_finger.ex | 9 --------- 1 file changed, 9 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index b955bc43f..3744dd62f 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -118,7 +118,6 @@ defmodule Pleroma.Web.WebFinger do {:Link, %{rel: "magic-public-key", href: "data:application/magic-public-key,#{magic_key}"}}, {:Link, %{rel: "self", type: "application/activity+json", href: user.ap_id}}, - {:Link, %{rel: "self", type: "application/ld+json; profile="https://www.w3.org/ns/activitystreams"", href: user.ap_id}}, {:Link, %{rel: "http://ostatus.org/schema/1.0/subscribe", template: OStatus.remote_follow_path()}} ] @@ -166,14 +165,6 @@ defmodule Pleroma.Web.WebFinger do doc ) - if ap_id == nil do - ap_id = - XML.string_from_xpath( - ~s{//Link[@rel="self" and @type="application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""]/@href}, - doc - ) - end - data = %{ "magic_key" => magic_key, "topic" => topic, -- cgit v1.2.3 From 4d2c6707c2f5f7723f1fcf03cdbf9476f2d5b3ad Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 07:03:53 +0000 Subject: activitypub: normalize the actor to ensure we have its URI --- lib/pleroma/plugs/http_signature.ex | 3 ++- lib/pleroma/web/activity_pub/utils.ex | 16 ++++++++++++++++ lib/pleroma/web/federator/federator.ex | 3 +++ lib/pleroma/web/http_signatures/http_signatures.ex | 6 +++--- 4 files changed, 24 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/plugs/http_signature.ex b/lib/pleroma/plugs/http_signature.ex index efde652f5..2d0e10cad 100644 --- a/lib/pleroma/plugs/http_signature.ex +++ b/lib/pleroma/plugs/http_signature.ex @@ -1,5 +1,6 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do alias Pleroma.Web.HTTPSignatures + alias Pleroma.Web.ActivityPub.Utils import Plug.Conn require Logger @@ -12,7 +13,7 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do end def call(conn, _opts) do - user = conn.params["actor"] + user = Utils.normalize_actor(conn.params["actor"]) Logger.debug("Checking sig for #{user}") [signature | _] = get_req_header(conn, "signature") diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index f98545336..d92db0d5f 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -5,6 +5,22 @@ defmodule Pleroma.Web.ActivityPub.Utils do alias Ecto.{Changeset, UUID} import Ecto.Query + # Some implementations send the actor URI as the actor field, others send the entire actor object, + # so figure out what the actor's URI is based on what we have. + def normalize_actor(actor) do + cond do + is_binary(actor) -> + actor + + is_map(actor) -> + actor["id"] + end + end + + def normalize_params(params) do + Map.put(params, "actor", normalize_actor(params["actor"])) + end + def make_json_ld_header do %{ "@context" => [ diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index f84af2f15..8ca530031 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -5,6 +5,7 @@ defmodule Pleroma.Web.Federator do alias Pleroma.Web.{WebFinger, Websub} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Transmogrifier + alias Pleroma.Web.ActivityPub.Utils require Logger @websub Application.get_env(:pleroma, :websub) @@ -91,6 +92,8 @@ defmodule Pleroma.Web.Federator do def handle(:incoming_ap_doc, params) do Logger.info("Handling incoming AP activity") + params = Utils.normalize_params(params) + with {:ok, _user} <- ap_enabled_actor(params["actor"]), nil <- Activity.get_by_ap_id(params["id"]), {:ok, _activity} <- Transmogrifier.handle_incoming(params) do diff --git a/lib/pleroma/web/http_signatures/http_signatures.ex b/lib/pleroma/web/http_signatures/http_signatures.ex index 9035f5eb6..dd3f825db 100644 --- a/lib/pleroma/web/http_signatures/http_signatures.ex +++ b/lib/pleroma/web/http_signatures/http_signatures.ex @@ -1,7 +1,7 @@ # https://tools.ietf.org/html/draft-cavage-http-signatures-08 defmodule Pleroma.Web.HTTPSignatures do alias Pleroma.User - alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Utils require Logger def split_signature(sig) do @@ -31,14 +31,14 @@ defmodule Pleroma.Web.HTTPSignatures do def validate_conn(conn) do # TODO: How to get the right key and see if it is actually valid for that request. # For now, fetch the key for the actor. - with actor_id <- conn.params["actor"], + with actor_id <- Utils.normalize_actor(conn.params["actor"]), {:ok, public_key} <- User.get_public_key_for_ap_id(actor_id) do if validate_conn(conn, public_key) do true else Logger.debug("Could not validate, re-fetching user and trying one more time") # Fetch user anew and try one more time - with actor_id <- conn.params["actor"], + with actor_id <- Utils.normalize_actor(conn.params["actor"]), {:ok, _user} <- ActivityPub.make_user_from_ap_id(actor_id), {:ok, public_key} <- User.get_public_key_for_ap_id(actor_id) do validate_conn(conn, public_key) -- cgit v1.2.3 From 2051530868720a23715cbb0d1a1286a6ae1a6507 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 07:30:02 +0000 Subject: activitypub transmogrifier: handle hubzilla AP actor quirks --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 ++ lib/pleroma/web/activity_pub/transmogrifier.ex | 13 +++++++++++++ 2 files changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 491ad3705..3e1977f96 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -401,6 +401,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do "url" => [%{"href" => data["image"]["url"]}] } + data = Transmogrifier.maybe_fix_user_object(data) + user_data = %{ ap_id: data["id"], info: %{ diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 463d1e59d..c10d27dcd 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -495,4 +495,17 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do Repo.delete_all(q) end end + + def maybe_fix_user_url(data) do + if is_map(data["url"]) do + data = Map.put(data, "url", data["url"]["href"]) + end + + data + end + + def maybe_fix_user_object(data) do + data + |> maybe_fix_user_url + end end -- cgit v1.2.3 From 6e8de2faae46f3dcaf6881ab40664da0057551e4 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 08:37:04 +0000 Subject: run mix format --- lib/pleroma/user.ex | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 399a66787..6a8129ac8 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -404,18 +404,22 @@ defmodule Pleroma.User do from( u in User, select_merge: %{ - search_distance: fragment( - "? <-> (? || ?)", - ^query, - u.nickname, - u.name - )} + search_distance: + fragment( + "? <-> (? || ?)", + ^query, + u.nickname, + u.name + ) + } ) - q = from(s in subquery(inner), - order_by: s.search_distance, - limit: 20 - ) + q = + from( + s in subquery(inner), + order_by: s.search_distance, + limit: 20 + ) Repo.all(q) end -- cgit v1.2.3 From 725b05d04aecaa00d5b79c81958267444bf3c91d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 08:48:15 +0000 Subject: run mix format --- lib/pleroma/user.ex | 24 ++++++++++++++---------- lib/pleroma/web/web_finger/web_finger.ex | 6 +++++- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 399a66787..6a8129ac8 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -404,18 +404,22 @@ defmodule Pleroma.User do from( u in User, select_merge: %{ - search_distance: fragment( - "? <-> (? || ?)", - ^query, - u.nickname, - u.name - )} + search_distance: + fragment( + "? <-> (? || ?)", + ^query, + u.nickname, + u.name + ) + } ) - q = from(s in subquery(inner), - order_by: s.search_distance, - limit: 20 - ) + q = + from( + s in subquery(inner), + order_by: s.search_distance, + limit: 20 + ) Repo.all(q) end diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 3744dd62f..6e5fc1401 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -86,7 +86,11 @@ defmodule Pleroma.Web.WebFinger do "href" => "data:application/magic-public-key,#{magic_key}" }, %{"rel" => "self", "type" => "application/activity+json", "href" => user.ap_id}, - %{"rel" => "self", "type" => "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", "href" => user.ap_id}, + %{ + "rel" => "self", + "type" => "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", + "href" => user.ap_id + }, %{ "rel" => "http://ostatus.org/schema/1.0/subscribe", "template" => OStatus.remote_follow_path() -- cgit v1.2.3 From df95118c819ae15f0de43519f2f9f9753ac60ec2 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 19 May 2018 11:27:14 +0200 Subject: Fix linking problem. --- lib/pleroma/formatter.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 456416fbd..395a0ac55 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -160,6 +160,7 @@ defmodule Pleroma.Formatter do links = Regex.scan(@link_regex, text) |> Enum.map(fn [url] -> {Ecto.UUID.generate(), url} end) + |> Enum.sort_by(fn ({_, url}) -> -String.length(url) end) uuid_text = links -- cgit v1.2.3 From d1366f8d46959229fdae398fe7920f6894d9d02a Mon Sep 17 00:00:00 2001 From: Syldexia Date: Sat, 19 May 2018 13:35:49 +0100 Subject: Modified deleting an account to run as a task --- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 3f3ddb9e4..23e7408a0 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -200,10 +200,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do def delete_account(%{assigns: %{user: user}} = conn, params) do case CommonAPI.Utils.confirm_current_password(user, params) do {:ok, user} -> - case User.delete(user) do - :ok -> json(conn, %{status: "success"}) - :error -> json(conn, %{error: "Unable to delete user."}) - end + Task.start(fn -> User.delete(user) end) + json(conn, %{status: "success"}) {:error, msg} -> json(conn, %{error: msg}) -- cgit v1.2.3 From 6f39ecc41be77298ae375ca0a2f51ae7dc29fbbf Mon Sep 17 00:00:00 2001 From: Thog Date: Sat, 19 May 2018 15:22:43 +0200 Subject: Support Undo like activities (Fix #139) --- lib/pleroma/formatter.ex | 2 +- lib/pleroma/web/activity_pub/activity_pub.ex | 18 +++++++++++++----- lib/pleroma/web/activity_pub/transmogrifier.ex | 18 ++++++++++++++++++ lib/pleroma/web/activity_pub/utils.ex | 17 +++++++++++++++++ .../web/mastodon_api/mastodon_api_controller.ex | 2 +- lib/pleroma/web/twitter_api/twitter_api.ex | 4 ++-- 6 files changed, 52 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 395a0ac55..53e2c204f 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -160,7 +160,7 @@ defmodule Pleroma.Formatter do links = Regex.scan(@link_regex, text) |> Enum.map(fn [url] -> {Ecto.UUID.generate(), url} end) - |> Enum.sort_by(fn ({_, url}) -> -String.length(url) end) + |> Enum.sort_by(fn {_, url} -> -String.length(url) end) uuid_text = links diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 973d18e52..4e97693a2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -131,11 +131,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end - def unlike(%User{} = actor, %Object{} = object) do - with %Activity{} = activity <- get_existing_like(actor.ap_id, object), - {:ok, _activity} <- Repo.delete(activity), - {:ok, object} <- remove_like_from_object(activity, object) do - {:ok, object} + def unlike( + %User{} = actor, + %Object{} = object, + activity_id \\ nil, + local \\ true + ) do + with %Activity{} = like_activity <- get_existing_like(actor.ap_id, object), + unlike_data <- make_unlike_data(actor, like_activity, activity_id), + {:ok, unlike_activity} <- insert(unlike_data, local), + {:ok, _activity} <- Repo.delete(like_activity), + {:ok, object} <- remove_like_from_object(like_activity, object), + :ok <- maybe_federate(unlike_activity) do + {:ok, unlike_activity, like_activity, object} else _e -> {:ok, object} end diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index c10d27dcd..a31452a63 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -241,6 +241,24 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do end end + def handle_incoming( + %{ + "type" => "Undo", + "object" => %{"type" => "Like", "object" => 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.unlike(actor, object, id, false) do + {:ok, activity} + else + e -> :error + end + end + # TODO # Accept # Undo for non-Announce diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index d92db0d5f..937f032c3 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -315,6 +315,23 @@ defmodule Pleroma.Web.ActivityPub.Utils do if activity_id, do: Map.put(data, "id", activity_id), else: data end + def make_unlike_data( + %User{ap_id: ap_id} = user, + %Activity{data: %{"context" => context}} = activity, + activity_id + ) do + data = %{ + "type" => "Undo", + "actor" => ap_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 with announcements <- [actor | object.data["announcements"] || []] |> Enum.uniq() do update_element_in_object("announcement", announcements, object) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 5475cb505..b218c269d 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -323,7 +323,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def unfav_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do - with {:ok, %{data: %{"id" => id}}} = CommonAPI.unfavorite(ap_id_or_id, user), + with {:ok, _, _, %{data: %{"id" => id}}} = CommonAPI.unfavorite(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 8177a4988..722e436e2 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -82,14 +82,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do end def fav(%User{} = user, ap_id_or_id) do - with {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.favorite(ap_id_or_id, user), + 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 {:ok, activity} end end def unfav(%User{} = user, ap_id_or_id) do - with {:ok, %{data: %{"id" => id}}} = CommonAPI.unfavorite(ap_id_or_id, user), + with {:ok, _unfav, _fav, %{data: %{"id" => id}}} = CommonAPI.unfavorite(ap_id_or_id, user), %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do {:ok, activity} end -- cgit v1.2.3 From 434601a5c367bb2d41115e3060f5d5b70572da39 Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 20 May 2018 16:15:18 +0200 Subject: Return private / direct posts on user timelines, too. --- lib/pleroma/web/activity_pub/activity_pub.ex | 19 +++++++++++++++++++ .../web/mastodon_api/mastodon_api_controller.ex | 15 ++++----------- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 8 +------- 3 files changed, 24 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 4e97693a2..24b4f045a 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -260,6 +260,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do |> Enum.reverse() end + def fetch_user_activities(user, reading_user, params \\ %{}) do + params = + params + |> Map.put("type", ["Create", "Announce"]) + |> Map.put("actor_id", user.ap_id) + |> Map.put("whole_db", true) + + recipients = + if reading_user do + ["https://www.w3.org/ns/activitystreams#Public"] ++ + [reading_user.ap_id | reading_user.following] + else + ["https://www.w3.org/ns/activitystreams#Public"] + end + + fetch_activities(recipients, params) + |> Enum.reverse() + end + defp restrict_since(query, %{"since_id" => since_id}) do from(activity in query, where: activity.id > ^since_id) end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index b218c269d..85f9c5b7b 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -204,21 +204,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) end - def user_statuses(%{assigns: %{user: user}} = conn, params) do - with %User{ap_id: ap_id} <- Repo.get(User, params["id"]) do - params = - params - |> Map.put("type", ["Create", "Announce"]) - |> Map.put("actor_id", ap_id) - |> Map.put("whole_db", true) - + def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do + with %User{} = user <- Repo.get(User, params["id"]) do + # Since Pleroma has no "pinned" posts feature, we'll just set an empty list here activities = if params["pinned"] == "true" do - # Since Pleroma has no "pinned" posts feature, we'll just set an empty list here [] else - ActivityPub.fetch_public_activities(params) - |> Enum.reverse() + ActivityPub.fetch_user_activities(user, reading_user, params) end conn diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index a99487738..dd1dc241d 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -96,13 +96,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def user_timeline(%{assigns: %{user: user}} = conn, params) do case TwitterAPI.get_user(user, params) do {:ok, target_user} -> - params = - params - |> Map.put("type", ["Create", "Announce"]) - |> Map.put("actor_id", target_user.ap_id) - |> Map.put("whole_db", true) - - activities = ActivityPub.fetch_public_activities(params) + activities = ActivityPub.fetch_user_activities(target_user, user, params) conn |> render(ActivityView, "index.json", %{activities: activities, for: user}) -- cgit v1.2.3 From ff007af0c2f229fa20cd4b83b94de89cd9fce29c Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 20 May 2018 18:01:24 +0200 Subject: Return visilility in twitter api, too. --- lib/pleroma/web/twitter_api/views/activity_view.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 580d4648c..62ce3b7b5 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -262,7 +262,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do "external_url" => object["external_url"] || object["id"], "tags" => tags, "activity_type" => "post", - "possibly_sensitive" => possibly_sensitive + "possibly_sensitive" => possibly_sensitive, + "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object) } end end -- cgit v1.2.3 From dca26f3655b97893513b96a5d17858241dca3a81 Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 20 May 2018 19:22:26 +0200 Subject: Fix specs. --- lib/pleroma/web/twitter_api/representers/activity_representer.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 9a4954de8..c2e1f07a5 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -197,7 +197,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do "external_url" => object["external_url"] || object["id"], "tags" => tags, "activity_type" => "post", - "possibly_sensitive" => possibly_sensitive + "possibly_sensitive" => possibly_sensitive, + "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object) } end -- cgit v1.2.3 From bf64208b524482e44407840b7aa66dd896c05def Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 21 May 2018 12:09:03 +0200 Subject: Add missing alias. --- lib/pleroma/web/http_signatures/http_signatures.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/web/http_signatures/http_signatures.ex b/lib/pleroma/web/http_signatures/http_signatures.ex index dd3f825db..0af414962 100644 --- a/lib/pleroma/web/http_signatures/http_signatures.ex +++ b/lib/pleroma/web/http_signatures/http_signatures.ex @@ -2,6 +2,7 @@ defmodule Pleroma.Web.HTTPSignatures do alias Pleroma.User alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.ActivityPub require Logger def split_signature(sig) do -- cgit v1.2.3 From d269c69a0b315f4767efbed3da781b04e9614c5d Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 21 May 2018 12:32:29 +0200 Subject: Actually fix missing alias. --- lib/pleroma/web/http_signatures/http_signatures.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/http_signatures/http_signatures.ex b/lib/pleroma/web/http_signatures/http_signatures.ex index 0af414962..4e0adbc1d 100644 --- a/lib/pleroma/web/http_signatures/http_signatures.ex +++ b/lib/pleroma/web/http_signatures/http_signatures.ex @@ -2,7 +2,7 @@ defmodule Pleroma.Web.HTTPSignatures do alias Pleroma.User alias Pleroma.Web.ActivityPub.Utils - alias Pleroma.Web.ActivityPub + alias Pleroma.Web.ActivityPub.ActivityPub require Logger def split_signature(sig) do -- cgit v1.2.3 From 75cfd9d34dc4be83a1ad4329f93d5121a7968b09 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 21 May 2018 12:38:12 +0000 Subject: webfinger: fix finding the XRD uri for statusnet instances --- lib/pleroma/web/web_finger/web_finger.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 6e5fc1401..9c6f1cb68 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -214,7 +214,7 @@ defmodule Pleroma.Web.WebFinger do end def get_template_from_xml(body) do - xpath = "//Link[@rel='lrdd' and @type='application/xrd+xml']/@template" + xpath = "//Link[@rel='lrdd']/@template" with doc when doc != :error <- XML.parse_document(body), template when template != nil <- XML.string_from_xpath(xpath, doc) do -- cgit v1.2.3 From 9a2d097ed822721959d0977a76a45d1f358446b8 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 21 May 2018 19:19:40 +0000 Subject: activitypub controller: note that the HTTP Host header must be forwarded for http signature validation to work --- lib/pleroma/web/activity_pub/activity_pub_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 80aae4f0f..c7d50893f 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -93,7 +93,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do Logger.info("Signature not from author, relayed message, fetching from source") ActivityPub.fetch_object_from_id(params["object"]["id"]) else - Logger.info("Signature error") + Logger.info("Signature error - make sure you are forwarding the HTTP Host header!") Logger.info("Could not validate #{params["actor"]}") Logger.info(inspect(conn.req_headers)) end -- cgit v1.2.3