MishkaCmsCore.Notify.LiveHooks (Mishka CMS Core v0.0.1)

Copy Markdown View Source

on_mount hook that makes the topbar bell live for the current user — with zero per-page wiring.

It never blocks the page: mount assigns an empty bell (notification_count: 0, notification_recent: []) and defers the query to a post-mount message (loaded async, off the render path). It subscribes to the user's own notification:<user_id>:* PubSub topics and attaches two hooks: a :handle_info hook that re-counts on any of those broadcasts, and a :handle_event hook so the dropdown's actions — open a notification, mark one read, mark all read — work on every admin page.

The badge counts unread notifications (read_at IS NULL); reading (per row, all, or by opening) decrements it live. Attached right after MishkaCmsCore.Layouts.Nav in MishkaCmsCore.ExtensionLiveView, so it overrides Nav's placeholder count. Subscribes on MishkaCmsCore.PubSub, matching the resource's Ash.Notifier.PubSub topics.

Summary

Functions

The current user's notifications for the bell dropdown (empty when signed out). Unread rows take priority — the newest unread first, then recent already-read rows only fill the remaining slots.

The current user's unread-notification count (0 when signed out).

Functions

on_mount(atom, params, session, socket)

recent(user)

The current user's notifications for the bell dropdown (empty when signed out). Unread rows take priority — the newest unread first, then recent already-read rows only fill the remaining slots.

unread_count(user)

The current user's unread-notification count (0 when signed out).