alias Pleroma.User.Info
+ @type t :: %__MODULE__{}
+
embedded_schema do
field(:banner, :map, default: %{})
field(:background, :map, default: %{})
field(:hide_follows, :boolean, default: false)
field(:pinned_activities, {:array, :string}, default: [])
field(:flavour, :string, default: nil)
+ field(:email_notifications, :map, default: %{"digest" => true})
field(:notification_settings, :map,
default: %{"remote" => true, "local" => true, "followers" => true, "follows" => true}
|> validate_required([:notification_settings])
end
+ @doc """
+ Update email notifications in the given User.Info struct.
+
+ Examples:
+
+ iex> update_email_notifications(%Pleroma.User.Info{email_notifications: %{"digest" => false}}, %{"digest" => true})
+ %Pleroma.User.Info{email_notifications: %{"digest" => true}}
+
+ """
+ @spec update_email_notifications(t(), map()) :: Ecto.Changeset.t()
+ def update_email_notifications(info, settings) do
+ email_notifications =
+ info.email_notifications
+ |> Map.merge(settings)
+ |> Map.take(["digest"])
+
+ params = %{email_notifications: email_notifications}
+ fields = [:email_notifications]
+
+ info
+ |> cast(params, fields)
+ |> validate_required(fields)
+ end
+
def add_to_note_count(info, number) do
set_note_count(info, info.note_count + number)
end
--- /dev/null
+defmodule Pleroma.UserInfoTest do
+ alias Pleroma.Repo
+ alias Pleroma.User.Info
+
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+
+ describe "update_email_notifications/2" do
+ setup do
+ user = insert(:user, %{info: %{email_notifications: %{"digest" => true}}})
+
+ {:ok, user: user}
+ end
+
+ test "Notifications are updated", %{user: user} do
+ true = user.info.email_notifications["digest"]
+ changeset = Info.update_email_notifications(user.info, %{"digest" => false})
+ assert changeset.valid?
+ {:ok, result} = Ecto.Changeset.apply_action(changeset, :insert)
+ assert result.email_notifications["digest"] == false
+ end
+ end
+end