projects
/
akkoma
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
089d72d
)
Refactor notification settings
author
Mark Felder
<feld@FreeBSD.org>
Thu, 28 May 2020 15:16:09 +0000
(10:16 -0500)
committer
Mark Felder
<feld@FreeBSD.org>
Thu, 28 May 2020 15:16:09 +0000
(10:16 -0500)
CHANGELOG.md
patch
|
blob
|
history
docs/API/pleroma_api.md
patch
|
blob
|
history
lib/pleroma/notification.ex
patch
|
blob
|
history
lib/pleroma/user/notification_setting.ex
patch
|
blob
|
history
lib/pleroma/web/api_spec/schemas/account.ex
patch
|
blob
|
history
test/notification_test.exs
patch
|
blob
|
history
test/web/mastodon_api/views/account_view_test.exs
patch
|
blob
|
history
test/web/twitter_api/util_controller_test.exs
patch
|
blob
|
history
diff --git
a/CHANGELOG.md
b/CHANGELOG.md
index dabc2a85ab527ea72da819b20faf1993a2272538..fba2366088ea11e786827996da25b5047a289b30 100644
(file)
--- a/
CHANGELOG.md
+++ b/
CHANGELOG.md
@@
-9,6
+9,9
@@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
<details>
<summary>API Changes</summary>
- **Breaking:** Emoji API: changed methods and renamed routes.
<details>
<summary>API Changes</summary>
- **Breaking:** Emoji API: changed methods and renamed routes.
+- **Breaking:** Notification Settings API for suppressing notification
+ now supports the following controls: `from_followers`, `from_following`,
+ and `from_strangers`.
</details>
### Removed
</details>
### Removed
diff --git
a/docs/API/pleroma_api.md
b/docs/API/pleroma_api.md
index 70d4755b7ce2362bd6357529ae42a122a447bfbb..2cb0792db3e25940edab6051f093651e1fd3cd26 100644
(file)
--- a/
docs/API/pleroma_api.md
+++ b/
docs/API/pleroma_api.md
@@
-287,10
+287,9
@@
See [Admin-API](admin_api.md)
* Method `PUT`
* Authentication: required
* Params:
* Method `PUT`
* Authentication: required
* Params:
- * `followers`: BOOLEAN field, receives notifications from followers
- * `follows`: BOOLEAN field, receives notifications from people the user follows
- * `remote`: BOOLEAN field, receives notifications from people on remote instances
- * `local`: BOOLEAN field, receives notifications from people on the local instance
+ * `from_followers`: BOOLEAN field, receives notifications from followers
+ * `from_following`: BOOLEAN field, receives notifications from people the user follows
+ * `from_strangers`: BOOLEAN field, receives notifications from people without an established relationship
* `privacy_option`: BOOLEAN field. When set to true, it removes the contents of a message from the push notification.
* Response: JSON. Returns `{"status": "success"}` if the update was successful, otherwise returns `{"error": "error_msg"}`
* `privacy_option`: BOOLEAN field. When set to true, it removes the contents of a message from the push notification.
* Response: JSON. Returns `{"status": "success"}` if the update was successful, otherwise returns `{"error": "error_msg"}`
diff --git
a/lib/pleroma/notification.ex
b/lib/pleroma/notification.ex
index 7eca55ac9fd76dd80b4cc4f6b2737d4444c4a890..ca556f0bbc5d4498cd8afbe0b9a6fcd32f88f70e 100644
(file)
--- a/
lib/pleroma/notification.ex
+++ b/
lib/pleroma/notification.ex
@@
-459,10
+459,9
@@
defmodule Pleroma.Notification do
def skip?(%Activity{} = activity, %User{} = user) do
[
:self,
def skip?(%Activity{} = activity, %User{} = user) do
[
:self,
- :followers,
- :follows,
- :non_followers,
- :non_follows,
+ :from_followers,
+ :from_following,
+ :from_strangers,
:recently_followed
]
|> Enum.find(&skip?(&1, activity, user))
:recently_followed
]
|> Enum.find(&skip?(&1, activity, user))
@@
-476,9
+475,9
@@
defmodule Pleroma.Notification do
end
def skip?(
end
def skip?(
- :followers,
+ :f
rom_f
ollowers,
%Activity{} = activity,
%Activity{} = activity,
- %User{notification_settings: %{followers: false}} = user
+ %User{notification_settings: %{f
rom_f
ollowers: false}} = user
) do
actor = activity.data["actor"]
follower = User.get_cached_by_ap_id(actor)
) do
actor = activity.data["actor"]
follower = User.get_cached_by_ap_id(actor)
@@
-486,9
+485,9
@@
defmodule Pleroma.Notification do
end
def skip?(
end
def skip?(
- :
non_follow
ers,
+ :
from_strang
ers,
%Activity{} = activity,
%Activity{} = activity,
- %User{notification_settings: %{
non_follow
ers: false}} = user
+ %User{notification_settings: %{
from_strang
ers: false}} = user
) do
actor = activity.data["actor"]
follower = User.get_cached_by_ap_id(actor)
) do
actor = activity.data["actor"]
follower = User.get_cached_by_ap_id(actor)
@@
-496,25
+495,15
@@
defmodule Pleroma.Notification do
end
def skip?(
end
def skip?(
- :f
ollows
,
+ :f
rom_following
,
%Activity{} = activity,
%Activity{} = activity,
- %User{notification_settings: %{f
ollows
: false}} = user
+ %User{notification_settings: %{f
rom_following
: false}} = user
) do
actor = activity.data["actor"]
followed = User.get_cached_by_ap_id(actor)
User.following?(user, followed)
end
) do
actor = activity.data["actor"]
followed = User.get_cached_by_ap_id(actor)
User.following?(user, followed)
end
- def skip?(
- :non_follows,
- %Activity{} = activity,
- %User{notification_settings: %{non_follows: false}} = user
- ) do
- actor = activity.data["actor"]
- followed = User.get_cached_by_ap_id(actor)
- !User.following?(user, followed)
- end
-
# To do: consider defining recency in hours and checking FollowingRelationship with a single SQL
def skip?(:recently_followed, %Activity{data: %{"type" => "Follow"}} = activity, %User{} = user) do
actor = activity.data["actor"]
# To do: consider defining recency in hours and checking FollowingRelationship with a single SQL
def skip?(:recently_followed, %Activity{data: %{"type" => "Follow"}} = activity, %User{} = user) do
actor = activity.data["actor"]
diff --git
a/lib/pleroma/user/notification_setting.ex
b/lib/pleroma/user/notification_setting.ex
index 4bd55e139d2c8c916f3ca5020e06dfaa5033aa3b..e47ac4cab130048899f997dcc11313532a6410cf 100644
(file)
--- a/
lib/pleroma/user/notification_setting.ex
+++ b/
lib/pleroma/user/notification_setting.ex
@@
-10,20
+10,18
@@
defmodule Pleroma.User.NotificationSetting do
@primary_key false
embedded_schema do
@primary_key false
embedded_schema do
- field(:followers, :boolean, default: true)
- field(:follows, :boolean, default: true)
- field(:non_follows, :boolean, default: true)
- field(:non_followers, :boolean, default: true)
+ field(:from_followers, :boolean, default: true)
+ field(:from_following, :boolean, default: true)
+ field(:from_strangers, :boolean, default: true)
field(:privacy_option, :boolean, default: false)
end
def changeset(schema, params) do
schema
|> cast(prepare_attrs(params), [
field(:privacy_option, :boolean, default: false)
end
def changeset(schema, params) do
schema
|> cast(prepare_attrs(params), [
- :followers,
- :follows,
- :non_follows,
- :non_followers,
+ :from_followers,
+ :from_following,
+ :from_strangers,
:privacy_option
])
end
:privacy_option
])
end
diff --git
a/lib/pleroma/web/api_spec/schemas/account.ex
b/lib/pleroma/web/api_spec/schemas/account.ex
index d54e2158d7ac2618ede9c0905feadc91d76d9a20..ed90ef3dbda4c75bd5a86ecd8dade3b6ae0b1958 100644
(file)
--- a/
lib/pleroma/web/api_spec/schemas/account.ex
+++ b/
lib/pleroma/web/api_spec/schemas/account.ex
@@
-57,10
+57,9
@@
defmodule Pleroma.Web.ApiSpec.Schemas.Account do
notification_settings: %Schema{
type: :object,
properties: %{
notification_settings: %Schema{
type: :object,
properties: %{
- followers: %Schema{type: :boolean},
- follows: %Schema{type: :boolean},
- non_followers: %Schema{type: :boolean},
- non_follows: %Schema{type: :boolean},
+ from_followers: %Schema{type: :boolean},
+ from_following: %Schema{type: :boolean},
+ from_strangers: %Schema{type: :boolean},
privacy_option: %Schema{type: :boolean}
}
},
privacy_option: %Schema{type: :boolean}
}
},
@@
-123,10
+122,9
@@
defmodule Pleroma.Web.ApiSpec.Schemas.Account do
"unread_conversation_count" => 0,
"tags" => [],
"notification_settings" => %{
"unread_conversation_count" => 0,
"tags" => [],
"notification_settings" => %{
- "followers" => true,
- "follows" => true,
- "non_followers" => true,
- "non_follows" => true,
+ "from_followers" => true,
+ "from_following" => true,
+ "from_strangers" => true,
"privacy_option" => false
},
"relationship" => %{
"privacy_option" => false
},
"relationship" => %{
diff --git
a/test/notification_test.exs
b/test/notification_test.exs
index 37c255fee5130e96f3d10a4f07f1b7243f3330e2..fd59aceb508608e1bf8d8c45a199e6837f89dcd6 100644
(file)
--- a/
test/notification_test.exs
+++ b/
test/notification_test.exs
@@
-237,19
+237,19
@@
defmodule Pleroma.NotificationTest do
follower = insert(:user)
followed =
follower = insert(:user)
followed =
- insert(:user, notification_settings: %Pleroma.User.NotificationSetting{followers: false})
+ insert(:user, notification_settings: %Pleroma.User.NotificationSetting{f
rom_f
ollowers: false})
User.follow(follower, followed)
{:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"})
refute Notification.create_notification(activity, followed)
end
User.follow(follower, followed)
{:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"})
refute Notification.create_notification(activity, followed)
end
- test "it disables notifications from
non-follow
ers" do
+ test "it disables notifications from
strang
ers" do
follower = insert(:user)
followed =
insert(:user,
follower = insert(:user)
followed =
insert(:user,
- notification_settings: %Pleroma.User.NotificationSetting{
non_follow
ers: false}
+ notification_settings: %Pleroma.User.NotificationSetting{
from_strang
ers: false}
)
{:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"})
)
{:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"})
@@
-258,7
+258,7
@@
defmodule Pleroma.NotificationTest do
test "it disables notifications from people the user follows" do
follower =
test "it disables notifications from people the user follows" do
follower =
- insert(:user, notification_settings: %Pleroma.User.NotificationSetting{f
ollows
: false})
+ insert(:user, notification_settings: %Pleroma.User.NotificationSetting{f
rom_following
: false})
followed = insert(:user)
User.follow(follower, followed)
followed = insert(:user)
User.follow(follower, followed)
@@
-267,15
+267,6
@@
defmodule Pleroma.NotificationTest do
refute Notification.create_notification(activity, follower)
end
refute Notification.create_notification(activity, follower)
end
- test "it disables notifications from people the user does not follow" do
- follower =
- insert(:user, notification_settings: %Pleroma.User.NotificationSetting{non_follows: false})
-
- followed = insert(:user)
- {:ok, activity} = CommonAPI.post(followed, %{status: "hey @#{follower.nickname}"})
- refute 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"])
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/views/account_view_test.exs
b/test/web/mastodon_api/views/account_view_test.exs
index 487ec26c2e6894b8ebdc89dece74a815c1ebc4a1..2e01689ff01c45c45d1f805b898ceaf5855eb566 100644
(file)
--- a/
test/web/mastodon_api/views/account_view_test.exs
+++ b/
test/web/mastodon_api/views/account_view_test.exs
@@
-94,10
+94,9
@@
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
user = insert(:user)
notification_settings = %{
user = insert(:user)
notification_settings = %{
- followers: true,
- follows: true,
- non_followers: true,
- non_follows: true,
+ from_followers: true,
+ from_following: true,
+ from_strangers: true,
privacy_option: false
}
privacy_option: false
}
diff --git
a/test/web/twitter_api/util_controller_test.exs
b/test/web/twitter_api/util_controller_test.exs
index ad919d341ad67a6e24d4271df9dec775e588a344..1133107f49cd63208b4572f4504aa49fb116ad7b 100644
(file)
--- a/
test/web/twitter_api/util_controller_test.exs
+++ b/
test/web/twitter_api/util_controller_test.exs
@@
-191,7
+191,7
@@
defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
test "it updates notification settings", %{user: user, conn: conn} do
conn
|> put("/api/pleroma/notification_settings", %{
test "it updates notification settings", %{user: user, conn: conn} do
conn
|> put("/api/pleroma/notification_settings", %{
- "followers" => false,
+ "f
rom_f
ollowers" => false,
"bar" => 1
})
|> json_response(:ok)
"bar" => 1
})
|> json_response(:ok)
@@
-199,10
+199,9
@@
defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
user = refresh_record(user)
assert %Pleroma.User.NotificationSetting{
user = refresh_record(user)
assert %Pleroma.User.NotificationSetting{
- followers: false,
- follows: true,
- non_follows: true,
- non_followers: true,
+ from_followers: false,
+ from_following: true,
+ from_strangers: true,
privacy_option: false
} == user.notification_settings
end
privacy_option: false
} == user.notification_settings
end
@@
-215,10
+214,9
@@
defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
user = refresh_record(user)
assert %Pleroma.User.NotificationSetting{
user = refresh_record(user)
assert %Pleroma.User.NotificationSetting{
- followers: true,
- follows: true,
- non_follows: true,
- non_followers: true,
+ from_followers: true,
+ from_following: true,
+ from_strangers: true,
privacy_option: true
} == user.notification_settings
end
privacy_option: true
} == user.notification_settings
end