Merge remote-tracking branch 'origin/develop' into global-status-expiration
[akkoma] / lib / pleroma / user / notification_setting.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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(:followers, :boolean, default: true)
14 field(:follows, :boolean, default: true)
15 field(:non_follows, :boolean, default: true)
16 field(:non_followers, :boolean, default: true)
17 field(:privacy_option, :boolean, default: false)
18 end
19
20 def changeset(schema, params) do
21 schema
22 |> cast(prepare_attrs(params), [
23 :followers,
24 :follows,
25 :non_follows,
26 :non_followers,
27 :privacy_option
28 ])
29 end
30
31 defp prepare_attrs(params) do
32 Enum.reduce(params, %{}, fn
33 {k, v}, acc when is_binary(v) ->
34 Map.put(acc, k, String.downcase(v))
35
36 {k, v}, acc ->
37 Map.put(acc, k, v)
38 end)
39 end
40 end