aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/notification.ex2
-rw-r--r--lib/pleroma/user/notification_setting.ex14
-rw-r--r--lib/pleroma/web/masto_fe_controller.ex19
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api.ex9
-rw-r--r--lib/pleroma/web/push/impl.ex5
-rw-r--r--lib/pleroma/web/push/subscription.ex3
-rw-r--r--lib/pleroma/web/streamer.ex11
7 files changed, 56 insertions, 7 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index 7efbdc49a..246993f4d 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -74,6 +74,8 @@ defmodule Pleroma.Notification do
reblog
}
+ def types, do: @notification_types
+
def changeset(%Notification{} = notification, attrs) do
notification
|> cast(attrs, [:seen, :type])
diff --git a/lib/pleroma/user/notification_setting.ex b/lib/pleroma/user/notification_setting.ex
index a7cd61499..820ed903c 100644
--- a/lib/pleroma/user/notification_setting.ex
+++ b/lib/pleroma/user/notification_setting.ex
@@ -12,13 +12,25 @@ defmodule Pleroma.User.NotificationSetting do
embedded_schema do
field(:block_from_strangers, :boolean, default: false)
field(:hide_notification_contents, :boolean, default: false)
+ field(:followers, :boolean, default: true)
+ field(:follows, :boolean, default: true)
+ field(:non_follows, :boolean, default: true)
+ field(:non_followers, :boolean, default: true)
+ field(:privacy_option, :boolean, default: false)
+ field(:exclude_types, {:array, :string}, default: [])
end
def changeset(schema, params) do
schema
|> cast(prepare_attrs(params), [
:block_from_strangers,
- :hide_notification_contents
+ :hide_notification_contents,
+ :followers,
+ :follows,
+ :non_follows,
+ :non_followers,
+ :privacy_option,
+ :exclude_types
])
end
diff --git a/lib/pleroma/web/masto_fe_controller.ex b/lib/pleroma/web/masto_fe_controller.ex
index e788ab37a..6ec6fa951 100644
--- a/lib/pleroma/web/masto_fe_controller.ex
+++ b/lib/pleroma/web/masto_fe_controller.ex
@@ -53,7 +53,24 @@ defmodule Pleroma.Web.MastoFEController do
@doc "PUT /api/web/settings: Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere"
def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
- with {:ok, _} <- User.mastodon_settings_update(user, settings) do
+ with {:ok, user} <- User.mastodon_settings_update(user, settings) do
+ if settings = get_in(user.settings, ["notifications", "shows"]) do
+ notify_settings =
+ Enum.map(settings, fn {k, v} ->
+ if v == false do
+ k
+ end
+ end)
+ |> Enum.filter(& &1)
+
+ notification_settings =
+ user.notification_settings
+ |> Map.from_struct()
+ |> Map.put(:exclude_types, notify_settings)
+
+ User.update_notification_settings(user, notification_settings)
+ end
+
json(conn, %{})
else
e ->
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api.ex b/lib/pleroma/web/mastodon_api/mastodon_api.ex
index 71479550e..17cfc5443 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api.ex
@@ -52,6 +52,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
def get_notifications(user, params \\ %{}) do
options = cast_params(params)
+ user_exclude_types = user.notification_settings.exclude_types
+
+ options =
+ if (!options[:exclude_types] or options[:exclude_types] == []) and user_exclude_types != [] do
+ Map.put(options, :exclude_types, user_exclude_types)
+ else
+ options
+ end
+
user
|> Notification.for_user_query(options)
|> restrict(:include_types, options)
diff --git a/lib/pleroma/web/push/impl.ex b/lib/pleroma/web/push/impl.ex
index 83cbdc870..ec68b40f8 100644
--- a/lib/pleroma/web/push/impl.ex
+++ b/lib/pleroma/web/push/impl.ex
@@ -19,7 +19,7 @@ defmodule Pleroma.Web.Push.Impl do
@types ["Create", "Follow", "Announce", "Like", "Move", "EmojiReact"]
@doc "Performs sending notifications for user subscriptions"
- @spec perform(Notification.t()) :: list(any) | :error | {:error, :unknown_type}
+ @spec perform(Notification.t()) :: {:ok, list(any)} | {:error, :unknown_type}
def perform(
%{
activity: %{data: %{"type" => activity_type}} = activity,
@@ -164,13 +164,14 @@ defmodule Pleroma.Web.Push.Impl do
_object,
mastodon_type
)
- when type in ["Follow", "Like"] do
+ when type in ["Follow", "Like", "EmojiReact"] do
mastodon_type = mastodon_type || notification.type
case mastodon_type do
"follow" -> "@#{actor.nickname} has followed you"
"follow_request" -> "@#{actor.nickname} has requested to follow you"
"favourite" -> "@#{actor.nickname} has favorited your post"
+ "pleroma:emoji_reaction" -> "@#{actor.nickname} has reacted to your post"
end
end
diff --git a/lib/pleroma/web/push/subscription.ex b/lib/pleroma/web/push/subscription.ex
index 4f6c9bc9f..7ea32b258 100644
--- a/lib/pleroma/web/push/subscription.ex
+++ b/lib/pleroma/web/push/subscription.ex
@@ -29,7 +29,8 @@ defmodule Pleroma.Web.Push.Subscription do
@supported_alert_types ~w[follow favourite mention reblog pleroma:chat_mention pleroma:emoji_reaction]a
defp alerts(%{data: %{alerts: alerts}}) do
- alerts = Map.take(alerts, @supported_alert_types)
+ types = Enum.map(Pleroma.Notification.types(), &String.to_atom/1)
+ alerts = Map.take(alerts, types)
%{"alerts" => alerts}
end
diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex
index fc3bbb130..6c77e4a57 100644
--- a/lib/pleroma/web/streamer.ex
+++ b/lib/pleroma/web/streamer.ex
@@ -171,8 +171,15 @@ defmodule Pleroma.Web.Streamer do
end
end
- def filtered_by_user?(%User{} = user, %Notification{activity: activity}, _) do
- filtered_by_user?(user, activity, :notification)
+ def filtered_by_user?(
+ %User{} = user,
+ %Notification{activity: activity, type: notification_type},
+ _
+ ) do
+ notification_settings = user.notification_settings
+
+ notification_type not in notification_settings.exclude_types and
+ filtered_by_user?(user, activity, :notification)
end
defp do_stream("direct", item) do