Make subscriptions the same direction as blocks
authorSadposter <hannah+pleroma@coffee-and-dreams.uk>
Fri, 5 Apr 2019 13:59:34 +0000 (14:59 +0100)
committerHannah Ward <Hannah.ward9001@gmail.com>
Fri, 5 Apr 2019 14:30:26 +0000 (15:30 +0100)
That being, user - subscribes to -> users, rather than
user - has subscribers -> users

lib/pleroma/user.ex
lib/pleroma/web/common_api/utils.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex

index 70db520ca9dafe583507e5e4c2d6c4b31e5f0452..6b213df580f0a47d298f8d1f3e93ca206f446bad 100644 (file)
@@ -1006,7 +1006,12 @@ defmodule Pleroma.User do
     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 =
index effc49a01e5b3ded55f2be386f0e181e4ad972f1..087778dfe9f54b47cce5ab62c07ef928be4ace3f 100644 (file)
@@ -336,10 +336,11 @@ defmodule Pleroma.Web.CommonAPI.Utils do
   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()
index af4c0a60e376cdbd2b2e35e3f1db4fc2f14b7c42..0732705e68f0cf0be8bfd5b4353e54b79ac9f960 100644 (file)
@@ -279,7 +279,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller 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 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
         conn
         |> put_view(UserView)
         |> render("show.json", %{user: unsubscribed, for: user})
+
       {:error, msg} ->
         forbidden_json_reply(conn, msg)
     end