aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/pleroma/notification.ex37
-rw-r--r--lib/pleroma/user/info.ex14
-rw-r--r--lib/pleroma/web/twitter_api/views/user_view.ex7
-rw-r--r--priv/repo/migrations/20190525071417_add_non_follows_and_non_followers_fields_to_notification_settings.exs10
-rw-r--r--test/notification_test.exs41
-rw-r--r--test/web/mastodon_api/account_view_test.exs6
-rw-r--r--test/web/twitter_api/util_controller_test.exs9
-rw-r--r--test/web/twitter_api/views/user_view_test.exs2
8 files changed, 84 insertions, 42 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index 844264307..35beffb87 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -166,7 +166,16 @@ defmodule Pleroma.Notification do
def get_notified_from_activity(_, _local_only), do: []
def skip?(activity, user) do
- [:self, :blocked, :local, :muted, :followers, :follows, :recently_followed]
+ [
+ :self,
+ :blocked,
+ :muted,
+ :followers,
+ :follows,
+ :non_followers,
+ :non_follows,
+ :recently_followed
+ ]
|> Enum.any?(&skip?(&1, activity, user))
end
@@ -179,12 +188,6 @@ defmodule Pleroma.Notification do
User.blocks?(user, %{ap_id: actor})
end
- def skip?(:local, %{local: true}, %{info: %{notification_settings: %{"local" => false}}}),
- do: true
-
- def skip?(:local, %{local: false}, %{info: %{notification_settings: %{"remote" => false}}}),
- do: true
-
def skip?(:muted, activity, user) do
actor = activity.data["actor"]
@@ -201,12 +204,32 @@ defmodule Pleroma.Notification do
User.following?(follower, user)
end
+ def skip?(
+ :non_followers,
+ activity,
+ %{info: %{notification_settings: %{"non_followers" => false}}} = user
+ ) do
+ actor = activity.data["actor"]
+ follower = User.get_cached_by_ap_id(actor)
+ !User.following?(follower, user)
+ end
+
def skip?(:follows, activity, %{info: %{notification_settings: %{"follows" => false}}} = user) do
actor = activity.data["actor"]
followed = User.get_cached_by_ap_id(actor)
User.following?(user, followed)
end
+ def skip?(
+ :non_follows,
+ activity,
+ %{info: %{notification_settings: %{"non_follows" => false}}} = user
+ ) do
+ actor = activity.data["actor"]
+ followed = User.get_cached_by_ap_id(actor)
+ !User.following?(user, followed)
+ end
+
def skip?(:recently_followed, %{data: %{"type" => "Follow"}} = activity, user) do
actor = activity.data["actor"]
diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex
index ef506c8da..88bec76a7 100644
--- a/lib/pleroma/user/info.ex
+++ b/lib/pleroma/user/info.ex
@@ -46,7 +46,12 @@ defmodule Pleroma.User.Info do
field(:emoji, {:array, :map}, default: [])
field(:notification_settings, :map,
- default: %{"remote" => true, "local" => true, "followers" => true, "follows" => true}
+ default: %{
+ "followers" => true,
+ "follows" => true,
+ "non_follows" => true,
+ "non_followers" => true
+ }
)
# Found in the wild
@@ -67,10 +72,15 @@ defmodule Pleroma.User.Info do
end
def update_notification_settings(info, settings) do
+ settings =
+ settings
+ |> Enum.map(fn {k, v} -> {k, v in [true, "true", "True", "1"]} end)
+ |> Map.new()
+
notification_settings =
info.notification_settings
|> Map.merge(settings)
- |> Map.take(["remote", "local", "followers", "follows"])
+ |> Map.take(["followers", "follows", "non_follows", "non_followers"])
params = %{notification_settings: notification_settings}
diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex
index f0a4ddbd3..550f35f5f 100644
--- a/lib/pleroma/web/twitter_api/views/user_view.ex
+++ b/lib/pleroma/web/twitter_api/views/user_view.ex
@@ -121,6 +121,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
"tags" => user.tags
}
|> maybe_with_activation_status(user, for_user)
+ |> with_notification_settings(user, for_user)
}
|> maybe_with_user_settings(user, for_user)
|> maybe_with_role(user, for_user)
@@ -132,6 +133,12 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
end
end
+ defp with_notification_settings(data, %User{id: user_id} = user, %User{id: user_id}) do
+ Map.put(data, "notification_settings", user.info.notification_settings)
+ end
+
+ defp with_notification_settings(data, _, _), do: data
+
defp maybe_with_activation_status(data, user, %User{info: %{is_admin: true}}) do
Map.put(data, "deactivated", user.info.deactivated)
end
diff --git a/priv/repo/migrations/20190525071417_add_non_follows_and_non_followers_fields_to_notification_settings.exs b/priv/repo/migrations/20190525071417_add_non_follows_and_non_followers_fields_to_notification_settings.exs
new file mode 100644
index 000000000..a88b0ea61
--- /dev/null
+++ b/priv/repo/migrations/20190525071417_add_non_follows_and_non_followers_fields_to_notification_settings.exs
@@ -0,0 +1,10 @@
+defmodule Pleroma.Repo.Migrations.AddNonFollowsAndNonFollowersFieldsToNotificationSettings do
+ use Ecto.Migration
+
+ def change do
+ execute("""
+ update users set info = jsonb_set(info, '{notification_settings}', '{"local": true, "remote": true, "follows": true, "followers": true, "non_follows": true, "non_followers": true}')
+ where local=true
+ """)
+ end
+end
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 581db58a8..be292abd9 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -78,33 +78,6 @@ defmodule Pleroma.NotificationTest do
assert nil == Notification.create_notification(activity, muter)
end
- test "it disables notifications from people on remote instances" do
- user = insert(:user, info: %{notification_settings: %{"remote" => false}})
- other_user = insert(:user)
-
- create_activity = %{
- "@context" => "https://www.w3.org/ns/activitystreams",
- "type" => "Create",
- "to" => ["https://www.w3.org/ns/activitystreams#Public"],
- "actor" => other_user.ap_id,
- "object" => %{
- "type" => "Note",
- "content" => "Hi @#{user.nickname}",
- "attributedTo" => other_user.ap_id
- }
- }
-
- {:ok, %{local: false} = activity} = Transmogrifier.handle_incoming(create_activity)
- assert nil == Notification.create_notification(activity, user)
- end
-
- test "it disables notifications from people on the local instance" do
- user = insert(:user, info: %{notification_settings: %{"local" => false}})
- other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})
- assert nil == Notification.create_notification(activity, user)
- end
-
test "it disables notifications from followers" do
follower = insert(:user)
followed = insert(:user, info: %{notification_settings: %{"followers" => false}})
@@ -113,6 +86,13 @@ defmodule Pleroma.NotificationTest do
assert nil == Notification.create_notification(activity, followed)
end
+ test "it disables notifications from non-followers" do
+ follower = insert(:user)
+ followed = insert(:user, info: %{notification_settings: %{"non_followers" => false}})
+ {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
+ assert nil == Notification.create_notification(activity, followed)
+ end
+
test "it disables notifications from people the user follows" do
follower = insert(:user, info: %{notification_settings: %{"follows" => false}})
followed = insert(:user)
@@ -122,6 +102,13 @@ defmodule Pleroma.NotificationTest do
assert nil == Notification.create_notification(activity, follower)
end
+ test "it disables notifications from people the user does not follow" do
+ follower = insert(:user, info: %{notification_settings: %{"non_follows" => false}})
+ followed = insert(:user)
+ {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
+ assert nil == Notification.create_notification(activity, follower)
+ end
+
test "it doesn't create a notification for user if he is the activity author" do
activity = insert(:note_activity)
author = User.get_cached_by_ap_id(activity.data["actor"])
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index aaf2261bb..23f250990 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -78,10 +78,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
user = insert(:user)
notification_settings = %{
- "remote" => true,
- "local" => true,
"followers" => true,
- "follows" => true
+ "follows" => true,
+ "non_follows" => true,
+ "non_followers" => true
}
privacy = user.info.default_scope
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 2cd82b3e7..cab9e5d90 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -102,7 +102,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
conn
|> assign(:user, user)
|> put("/api/pleroma/notification_settings", %{
- "remote" => false,
"followers" => false,
"bar" => 1
})
@@ -110,8 +109,12 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
user = Repo.get(User, user.id)
- assert %{"remote" => false, "local" => true, "followers" => false, "follows" => true} ==
- user.info.notification_settings
+ assert %{
+ "followers" => false,
+ "follows" => true,
+ "non_follows" => true,
+ "non_followers" => true
+ } == user.info.notification_settings
end
end
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 74526673c..a48fc9b78 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -112,9 +112,11 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
as_user = UserView.render("show.json", %{user: user, for: user})
assert as_user["default_scope"] == user.info.default_scope
assert as_user["no_rich_text"] == user.info.no_rich_text
+ assert as_user["pleroma"]["notification_settings"] == user.info.notification_settings
as_stranger = UserView.render("show.json", %{user: user})
refute as_stranger["default_scope"]
refute as_stranger["no_rich_text"]
+ refute as_stranger["pleroma"]["notification_settings"]
end
test "A user for a given other follower", %{user: user} do