some clean up

This commit is contained in:
Alexander Strizhakov 2020-06-18 10:40:25 +03:00
parent 9f33c5fe63
commit f6ae86a081
No known key found for this signature in database
GPG Key ID: 022896A53AEF1381
4 changed files with 12 additions and 21 deletions

View File

@ -74,8 +74,12 @@ defmodule Pleroma.Notification do
reblog
}
@notification_types_excluding_chat List.delete(@notification_types, "pleroma:chat_mention")
def types, do: @notification_types
def types_excluding_chat, do: @notification_types_excluding_chat
def changeset(%Notification{} = notification, attrs) do
notification
|> cast(attrs, [:seen, :type])

View File

@ -56,7 +56,8 @@ defmodule Pleroma.Web.MastoFEController 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)
settings
|> Enum.map(fn {k, v} -> if v == false, do: k end)
|> Enum.reject(&is_nil/1)
notification_settings =

View File

@ -42,19 +42,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationController do
end
end
@default_notification_types ~w{
mention
follow
follow_request
reblog
favourite
move
pleroma:emoji_reaction
}
def index(%{assigns: %{user: user}} = conn, params) do
params =
Map.new(params, fn {k, v} -> {to_string(k), v} end)
|> Map.put_new("include_types", @default_notification_types)
params
|> Map.new(fn {k, v} -> {to_string(k), v} end)
|> Map.put_new("include_types", Pleroma.Notification.types_excluding_chat())
notifications = MastodonAPI.get_notifications(user, params)

View File

@ -50,16 +50,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
end
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
params
|> Map.put_new("exclude_types", user.notification_settings.exclude_types)
|> cast_params()
user
|> Notification.for_user_query(options)