Merge branch 'ecto-rollback-in-test-env' into 'develop'
[akkoma] / lib / pleroma / user / notification_setting.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.User.NotificationSetting do
6 use Ecto.Schema
7 import Ecto.Changeset
8
9 @derive Jason.Encoder
10 @primary_key false
11
12 embedded_schema do
13 field(:block_from_strangers, :boolean, default: false)
14 field(:hide_notification_contents, :boolean, default: false)
15 end
16
17 def changeset(schema, params) do
18 schema
19 |> cast(prepare_attrs(params), [
20 :block_from_strangers,
21 :hide_notification_contents
22 ])
23 end
24
25 defp prepare_attrs(params) do
26 Enum.reduce(params, %{}, fn
27 {k, v}, acc when is_binary(v) ->
28 Map.put(acc, k, String.downcase(v))
29
30 {k, v}, acc ->
31 Map.put(acc, k, v)
32 end)
33 end
34 end