From 316fe20d864711c2854401eaa2cb08f627d5e536 Mon Sep 17 00:00:00 2001 From: Sadposter Date: Fri, 5 Apr 2019 14:59:34 +0100 Subject: [PATCH] Make subscriptions the same direction as blocks That being, user - subscribes to -> users, rather than user - has subscribers -> users --- lib/pleroma/user.ex | 7 ++++++- lib/pleroma/web/common_api/utils.ex | 9 +++++---- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 70db520ca..6b213df58 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1006,7 +1006,12 @@ def blocked_users(user), do: Repo.all(from(u in User, where: u.ap_id in ^user.info.blocks)) def subscribed_users(user), - do: Repo.all(from(u in User, where: u.ap_id in ^user.info.subscriptions)) + do: + Repo.all( + from(u in User, + where: fragment("?->'subscriptions' @> ?", u.info, ^user.ap_id) + ) + ) def block_domain(user, domain) do info_cng = diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index effc49a01..087778dfe 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -336,10 +336,11 @@ def maybe_notify_mentioned_recipients( def maybe_notify_mentioned_recipients(recipients, _), do: recipients def maybe_notify_subscribers( - recipients, - %Activity{data: %{"actor" => actor, "type" => type}} - ) when type == "Create" do - with %User{} = user <- User.get_by_ap_id(actor) do + recipients, + %Activity{data: %{"actor" => actor, "type" => type}} + ) + when type == "Create" do + with %User{} = user <- User.get_by_ap_id(actor) do subscriber_ids = user |> User.subscribed_users() diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index af4c0a60e..0732705e6 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -279,7 +279,7 @@ def subscribe(%{assigns: %{user: user}} = conn, params) do {:error, msg} -> forbidden_json_reply(conn, msg) end - end + end def unsubscribe(%{assigns: %{user: user}} = conn, params) do case TwitterAPI.unsubscribe(user, params) do @@ -287,7 +287,7 @@ def unsubscribe(%{assigns: %{user: user}} = conn, params) do conn |> put_view(UserView) |> render("show.json", %{user: unsubscribed, for: user}) - + {:error, msg} -> forbidden_json_reply(conn, msg) end