Merge branch 'follow-request-notifications' into 'develop'
authorrinpatch <rinpatch@sdf.org>
Sat, 2 May 2020 12:24:49 +0000 (12:24 +0000)
committerrinpatch <rinpatch@sdf.org>
Sat, 2 May 2020 15:59:12 +0000 (18:59 +0300)
Follow request notifications enforcement

See merge request pleroma/pleroma!2451

config/config.exs
config/description.exs
lib/pleroma/notification.ex
test/notification_test.exs

index 6b881e1b2fb98da4270643a7c6fa3756a58869c8..3357e23e724b5804f629cb921b69d73e6bf18dda 100644 (file)
@@ -581,8 +581,6 @@ config :pleroma, :email_notifications,
     inactivity_threshold: 7
   }
 
-config :pleroma, :notifications, enable_follow_request_notifications: false
-
 config :pleroma, :oauth2,
   token_expires_in: 600,
   issue_new_refresh_token: true,
index 19ff555406e42323760469fc834bb3909805b46a..5a1e9e9affe3b53a1ed516d3f0a249e1f5d14a70 100644 (file)
@@ -2286,20 +2286,6 @@ config :pleroma, :config_description, [
       }
     ]
   },
-  %{
-    group: :pleroma,
-    key: :notifications,
-    type: :group,
-    description: "Notification settings",
-    children: [
-      %{
-        key: :enable_follow_request_notifications,
-        type: :boolean,
-        description:
-          "Enables notifications on new follow requests (causes issues with older PleromaFE versions)."
-      }
-    ]
-  },
   %{
     group: :pleroma,
     key: Pleroma.Emails.UserEmail,
index 94dc0c2b0201e79a3d71c26c4f049159739963c4..815356a5e5ed12c5b46753865428dec2144dcca0 100644 (file)
@@ -293,17 +293,8 @@ defmodule Pleroma.Notification do
     end
   end
 
-  def create_notifications(%Activity{data: %{"type" => "Follow"}} = activity) do
-    if Pleroma.Config.get([:notifications, :enable_follow_request_notifications]) ||
-         Activity.follow_accepted?(activity) do
-      do_create_notifications(activity)
-    else
-      {:ok, []}
-    end
-  end
-
   def create_notifications(%Activity{data: %{"type" => type}} = activity)
-      when type in ["Like", "Announce", "Move", "EmojiReact"] do
+      when type in ["Follow", "Like", "Announce", "Move", "EmojiReact"] do
     do_create_notifications(activity)
   end
 
index 8553d96520cef135f636c14695ce3b69491211f3..e12418db3cda85fe9bff09b3343473665bcb7dc4 100644 (file)
@@ -312,9 +312,7 @@ defmodule Pleroma.NotificationTest do
                })
     end
 
-    test "if `follow_request` notifications are enabled, " <>
-           "it creates `follow_request` notification for pending Follow activity" do
-      clear_config([:notifications, :enable_follow_request_notifications], true)
+    test "it creates `follow_request` notification for pending Follow activity" do
       user = insert(:user)
       followed_user = insert(:user, locked: true)
 
@@ -333,21 +331,6 @@ defmodule Pleroma.NotificationTest do
       assert %{type: "follow"} = NotificationView.render("show.json", render_opts)
     end
 
-    test "if `follow_request` notifications are disabled, " <>
-           "it does NOT create `follow*` notification for pending Follow activity" do
-      clear_config([:notifications, :enable_follow_request_notifications], false)
-      user = insert(:user)
-      followed_user = insert(:user, locked: true)
-
-      {:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
-      refute FollowingRelationship.following?(user, followed_user)
-      assert [] = Notification.for_user(followed_user)
-
-      # After request is accepted, no new notifications are generated:
-      assert {:ok, _} = CommonAPI.accept_follow_request(user, followed_user)
-      assert [] = Notification.for_user(followed_user)
-    end
-
     test "it doesn't create a notification for follow-unfollow-follow chains" do
       user = insert(:user)
       followed_user = insert(:user, locked: false)
@@ -362,6 +345,15 @@ defmodule Pleroma.NotificationTest do
       notification_id = notification.id
       assert [%{id: ^notification_id}] = Notification.for_user(followed_user)
     end
+
+    test "dismisses the notification on follow request rejection" do
+      user = insert(:user, locked: true)
+      follower = insert(:user)
+      {:ok, _, _, _follow_activity} = CommonAPI.follow(follower, user)
+      assert [notification] = Notification.for_user(user)
+      {:ok, _follower} = CommonAPI.reject_follow_request(follower, user)
+      assert [] = Notification.for_user(user)
+    end
   end
 
   describe "get notification" do