Chimeway.Preferences (chimeway v1.0.0)

Copy Markdown View Source

Public context for notification preference management.

Preferences are keyed by (recipient_id, notification_key, channel). recipient_id is the same string as recipient_identity on notification rows.

Missing preferences default to enabled — channels are opt-in by default.

Summary

Functions

Returns true if the category is enabled for the recipient — defaults to true when no preference row exists (opt-in default).

Returns true if the channel is enabled for the recipient/key — defaults to true when no preference row exists (opt-in default).

Fetches the category preference row for the given recipient/category, or nil.

Fetches the preference row for the given recipient/key/channel, or nil.

Upserts a category preference. On conflict, updates :enabled and :updated_at.

Upserts a preference. On conflict, updates :enabled and :updated_at.

Functions

category_enabled?(recipient_id, notification_category)

@spec category_enabled?(String.t(), String.t()) :: boolean()

Returns true if the category is enabled for the recipient — defaults to true when no preference row exists (opt-in default).

channel_enabled?(recipient_id, notification_key, channel)

@spec channel_enabled?(String.t(), String.t(), String.t()) :: boolean()

Returns true if the channel is enabled for the recipient/key — defaults to true when no preference row exists (opt-in default).

get_category_preference(recipient_id, notification_category)

@spec get_category_preference(String.t(), String.t()) ::
  Chimeway.Preferences.CategoryPreference.t() | nil

Fetches the category preference row for the given recipient/category, or nil.

get_preference(recipient_id, notification_key, channel)

@spec get_preference(String.t(), String.t(), String.t()) ::
  Chimeway.Preferences.NotificationPreference.t() | nil

Fetches the preference row for the given recipient/key/channel, or nil.

upsert_category_preference(attrs)

@spec upsert_category_preference(map()) ::
  {:ok, Chimeway.Preferences.CategoryPreference.t()}
  | {:error, Ecto.Changeset.t()}

Upserts a category preference. On conflict, updates :enabled and :updated_at.

upsert_preference(attrs)

@spec upsert_preference(map()) ::
  {:ok, Chimeway.Preferences.NotificationPreference.t()}
  | {:error, Ecto.Changeset.t()}

Upserts a preference. On conflict, updates :enabled and :updated_at.