2019-10-28 02:47:23 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 12:38:50 -08:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-10-28 02:47:23 -07: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-06-26 09:24:28 -07:00
|
|
|
field(:block_from_strangers, :boolean, default: false)
|
2020-06-26 10:45:46 -07:00
|
|
|
field(:hide_notification_contents, :boolean, default: false)
|
2019-10-28 02:47:23 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def changeset(schema, params) do
|
|
|
|
schema
|
|
|
|
|> cast(prepare_attrs(params), [
|
2020-06-26 09:24:28 -07:00
|
|
|
:block_from_strangers,
|
2020-06-26 10:45:46 -07:00
|
|
|
:hide_notification_contents
|
2019-10-28 02:47:23 -07:00
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
defp prepare_attrs(params) do
|
|
|
|
Enum.reduce(params, %{}, fn
|
2019-10-29 11:33:17 -07:00
|
|
|
{k, v}, acc when is_binary(v) ->
|
2019-10-28 02:47:23 -07:00
|
|
|
Map.put(acc, k, String.downcase(v))
|
|
|
|
|
|
|
|
{k, v}, acc ->
|
|
|
|
Map.put(acc, k, v)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|