From 89603eda9ea51c5bd3c681fce958a4a6b446debe Mon Sep 17 00:00:00 2001 From: Pierrick Brun Date: Mon, 7 May 2018 20:51:14 +0200 Subject: [PATCH] do not create notification for yourself --- lib/pleroma/notification.ex | 3 ++- test/notification_test.exs | 7 +++++++ test/web/twitter_api/twitter_api_controller_test.exs | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) 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 @@ def create_notifications(_), do: {:ok, []} # 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) diff --git a/test/notification_test.exs b/test/notification_test.exs index 568ad642c..2ca1ac13d 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -33,6 +33,13 @@ test "it doesn't create a notification for user if the user blocks the activity 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 diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index d7113979a..896fe246d 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -257,8 +257,10 @@ test "without valid credentials", %{conn: conn} 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