aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/user.ex
diff options
context:
space:
mode:
authorMaksim Pechnikov <parallel588@gmail.com>2019-10-28 12:47:23 +0300
committerMaksim Pechnikov <parallel588@gmail.com>2019-11-28 22:08:30 +0300
commita52da55eb9c6bbf8a08bf1d90d59a48dc25f5907 (patch)
tree766d151dfa013931b636b723746061bbeb4f1429 /lib/pleroma/user.ex
parentca1acfa314a57f78c2f5f8e60a4bd1380350e483 (diff)
downloadpleroma-a52da55eb9c6bbf8a08bf1d90d59a48dc25f5907.tar.gz
added User.NotificationSetting struct
Diffstat (limited to 'lib/pleroma/user.ex')
-rw-r--r--lib/pleroma/user.ex26
1 files changed, 6 insertions, 20 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index b18a4c6a5..94fca2a9f 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -105,13 +105,10 @@ defmodule Pleroma.User do
field(:invisible, :boolean, default: false)
field(:skip_thread_containment, :boolean, default: false)
- field(:notification_settings, :map,
- default: %{
- "followers" => true,
- "follows" => true,
- "non_follows" => true,
- "non_followers" => true
- }
+ embeds_one(
+ :notification_settings,
+ Pleroma.User.NotificationSetting,
+ on_replace: :update
)
has_many(:notifications, Notification)
@@ -1095,20 +1092,9 @@ defmodule Pleroma.User do
end
def update_notification_settings(%User{} = user, settings) do
- settings =
- settings
- |> Enum.map(fn {k, v} -> {k, v in [true, "true", "True", "1"]} end)
- |> Map.new()
-
- notification_settings =
- user.notification_settings
- |> Map.merge(settings)
- |> Map.take(["followers", "follows", "non_follows", "non_followers"])
-
- params = %{notification_settings: notification_settings}
-
user
- |> cast(params, [:notification_settings])
+ |> cast(%{notification_settings: settings}, [])
+ |> cast_embed(:notification_settings)
|> validate_required([:notification_settings])
|> update_and_set_cache()
end