do not create notification for yourself
authorPierrick Brun <brun.pierrick@protonmail.com>
Mon, 7 May 2018 18:51:14 +0000 (20:51 +0200)
committerPierrick Brun <brun.pierrick@protonmail.com>
Fri, 11 May 2018 09:31:17 +0000 (11:31 +0200)
lib/pleroma/notification.ex
test/notification_test.exs
test/web/twitter_api/twitter_api_controller_test.exs

index e26e49c8cc5d01468f3e47beba2084869c81dc74..e0dcd98236eb8984a4b2b36ae13b15b65d4d97b4 100644 (file)
@@ -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)
index 568ad642cf37ee764864915c0e5fa0bf6dfc579f..2ca1ac13daf679c136c587ba981dd1f74821c57b 100644 (file)
@@ -33,6 +33,13 @@ defmodule Pleroma.NotificationTest do
 
       assert nil == Notification.create_notification(activity, user)
     end
+
+    test "it doesn't create a notification for user if he is the activity author" do
+      activity = insert(:note_activity)
+      author = User.get_by_ap_id(activity.data["actor"])
+
+      assert nil == Notification.create_notification(activity, author)
+    end
   end
 
   describe "get notification" do
index d7113979ac0262af26bbcd1b92ef1b45cadbf0e0..896fe246d0d42c9790be2694bf83bfcc6afc9587 100644 (file)
@@ -257,8 +257,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
     end
 
     test "with credentials", %{conn: conn, user: current_user} do
+      other_user = insert(:user)
+
       {:ok, activity} =
-        ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: current_user})
+        ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
 
       conn =
         conn