PhoenixKitInbox (PhoenixKitInbox v0.2.0)

Copy Markdown View Source

Internal mailbox for PhoenixKit — an in-app email client for messages between the users of your application.

The UI is the familiar three-pane webmail layout (folders, message list, reading pane) and the data model is the familiar one too: a message is stored once and delivered as one row per recipient mailbox, so read/starred/foldered state is per-person.

What it is, and isn't

Inbox is internal. Messages are addressed to mailboxes inside this application; nothing is fetched over IMAP and nothing is relayed to the outside world. What it can do, when the host also runs phoenix_kit_emails, is send a short "you have a new message" nudge to a recipient's real email address — a soft, Code.ensure_loaded?/1-guarded integration with no dependency in mix.exs, off by default behind the inbox_email_nudges_enabled setting. See PhoenixKitInbox.Notify.

If you want outbound campaign email, that's phoenix_kit_newsletters; for delivery tracking and SES integration, phoenix_kit_emails; for customer ticketing, phoenix_kit_customer_support. Inbox is the messages your users send each other.

Mailboxes

Every user gets one personal mailbox, created lazily on first visit. Admins can also create shared mailboxes (support, sales, …) and grant other users read / write / admin access to them — the same own-it-or-be-granted-it model phoenix_kit_calendar uses for calendars. The module-level "inbox" permission decides who can open Inbox at all; grants decide which mailboxes they see inside it.

Database

Unlike older PhoenixKit modules, Inbox owns its migrations. Tables are created by PhoenixKitInbox.Migrations (returned from migration_module/0) and applied by mix phoenix_kit.update, not by a versioned migration in core. Nothing has to be released in phoenix_kit for this module's schema to change.

Installation

# mix.exs
{:phoenix_kit_inbox, "~> 0.2"}

Then mix deps.get and mix phoenix_kit.update. PhoenixKit auto-discovers the module at startup — the tab appears in the admin sidebar and the Modules page with no config.

Summary

Functions

Admin sidebar tabs.

OTP apps whose templates Tailwind should scan for CSS classes.

Disables the module.

Whether new-message email nudges are on.

Enables the module.

Whether the module is currently enabled.

Stats shown on the admin Modules page.

Module-owned versioned migrations.

Unique key for this module. Used in settings, permissions, and PubSub events.

Display name shown in the admin UI.

Notification types this module contributes.

Permission metadata for the roles/permissions matrix.

Resolves Inbox messages for phoenix_kit_comments' moderation admin, so a comment attached to a message links back to it.

Turns the new-message email nudge on or off.

Version string. Shown on the admin Modules page.

Functions

admin_tabs()

Admin sidebar tabs.

Three visible pages plus one hidden route for the compose view. Folder navigation is not a tab per folder — the mailbox is a single LiveView and folders are query params, so switching folders is a push_patch rather than a remount (see PhoenixKitInbox.Paths.inbox/1).

css_sources()

OTP apps whose templates Tailwind should scan for CSS classes.

disable_system()

Disables the module.

email_nudges_enabled?()

@spec email_nudges_enabled?() :: boolean()

Whether new-message email nudges are on.

Off by default. The nudge only fires when it is on and the host also runs phoenix_kit_emails — see PhoenixKitInbox.Notify.

enable_system()

Enables the module.

enabled?()

Whether the module is currently enabled.

Defensive on purpose: enabled?/0 is called during startup and route compilation, before the DB is guaranteed to be up. Every failure mode (missing table, dead pool, sandbox owner gone) returns false so callers never have to special-case boot ordering.

get_config()

Stats shown on the admin Modules page.

migration_module()

Module-owned versioned migrations.

This is the callback that keeps Inbox's DDL out of core. mix phoenix_kit.update reads it, compares the installed version against PhoenixKitInbox.Migrations.current_version/0, and generates a host migration when behind.

module_key()

Unique key for this module. Used in settings, permissions, and PubSub events.

module_name()

Display name shown in the admin UI.

notification_types()

Notification types this module contributes.

One toggle: a user who mutes "Inbox" stops getting in-app notifications for new messages. The actions list must match the action strings PhoenixKitInbox.Notify emits.

permission_metadata()

Permission metadata for the roles/permissions matrix.

The :key MUST match module_key/0 — PhoenixKit validates this at startup.

resolve_comment_resources(uuids)

@spec resolve_comment_resources([binary()]) :: %{required(binary()) => map()}

Resolves Inbox messages for phoenix_kit_comments' moderation admin, so a comment attached to a message links back to it.

Registered by the host:

config :phoenix_kit, :comment_resource_handlers, %{
  "inbox_message" => PhoenixKitInbox
}

set_email_nudges(enabled)

@spec set_email_nudges(boolean()) :: term()

Turns the new-message email nudge on or off.

version()

Version string. Shown on the admin Modules page.