akkoma/lib/pleroma/user/notification_setting.ex

39 lines
934 B
Elixir
Raw Normal View History

2019-10-28 09:47:23 +00:00
# Pleroma: A lightweight social networking server
2020-03-03 22:44:49 +00:00
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
2019-10-28 09:47:23 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User.NotificationSetting do
use Ecto.Schema
import Ecto.Changeset
@derive Jason.Encoder
@primary_key false
embedded_schema do
2020-05-28 15:16:09 +00:00
field(:from_followers, :boolean, default: true)
field(:from_following, :boolean, default: true)
field(:from_strangers, :boolean, default: true)
field(:privacy_option, :boolean, default: false)
2019-10-28 09:47:23 +00:00
end
def changeset(schema, params) do
schema
|> cast(prepare_attrs(params), [
2020-05-28 15:16:09 +00:00
:from_followers,
:from_following,
:from_strangers,
2019-10-28 09:47:23 +00:00
:privacy_option
])
end
defp prepare_attrs(params) do
Enum.reduce(params, %{}, fn
{k, v}, acc when is_binary(v) ->
2019-10-28 09:47:23 +00:00
Map.put(acc, k, String.downcase(v))
{k, v}, acc ->
Map.put(acc, k, v)
end)
end
end