The feed in the app's LiveViews: an on_mount hook that gives each
LiveView of a live_session the @chime assign, for the components of
Chime.Components.
live_session :app,
on_mount: [
{MyAppWeb.UserAuth, :ensure_authenticated},
Chime.Live
] do
...
endPut it after the app's own hooks: the config's resolver reads the
person from the socket's assigns (Chime.Resolver.resolve_recipient/1).
Options, as {Chime.Live, limit: 20}:
:limit- the notifications of the panel, and of each "Show more" (10).
@chime (Chime.Live.State) holds the person, their counts, and, once
the panel is open, its notifications. It stays live: a notification
that comes reaches every open page of the person at once, with no
query but their own, and seeing or reading in one tab clears the
others. For nobody (the resolver gives nil), @chime.recipient is nil
and the components render nothing.
The events chime:toggle, chime:open and chime:close open the panel
(which marks the feed seen) and close it; chime:more loads more;
chime:filter (%{"filter" => "unread"} or "inbox") shows the
unread or all; chime:read and chime:archive (%{"id" => id}) mark
one; chime:read_all marks them all read; chime:action
(%{"id" => id, "action" => key}) takes an action (Chime.act/3), and
goes where it says; chime:visit (%{"id" => id}) marks one read and goes to its :url. The components send them,
and a LiveView's own buttons can too (phx-click="chime:toggle"). The
hook handles them, and the messages of the PubSub, before the LiveView
sees them.