The shared thread, message and composer: registries and patch points
The shared thread, message and composer
Section titled “The shared thread, message and composer”Chatter, Discuss, chat windows and embedded comment threads show messages with the same components (ADR 0148 D1.5).
Package: @erpforall/mail-thread-view (web/packages/mail-thread-view). Behavior: docs/specs/web/mail-thread-view.md.
Design: docs/design/m4-mail-thread-view.md. Executable examples: web/packages/mail-thread-view/tests/ (the test addons are
addon.test.ts); the snippets below are compiled from web/typechecks/mail-thread-view.ts.
The components read the messaging store (messaging-store.md) and never fetch: the host gives them a ThreadTransport
(posting and message operations) and a ThreadPager (the pages of the thread). A user-facing functional page for the
chatter does not exist yet.
Mounting a thread and a composer
Section titled “Mounting a thread and a composer”const registries = defineThreadViewRegistries(hub);registerBuiltins(registries);
const transport: ThreadTransport = { async post(ref, post) { const answer = await jsonRpc(`/json/2/${ref.model}/thread_post`, { ids: [ref.id], post }); // applyAnswer takes the payload as text, exactly as received. return { message_id: answer.message_id, replayed: answer.replayed, store: JSON.stringify(answer.store) }; },};const pager: ThreadPager = { loadLatest: (ref) => fetchLatestPage(ref.model, ref.id), loadOlder: (ref, before) => fetchOlderPage(ref.model, ref.id, before),};
const common = { store, ref: { model: "sale.order", id: 42 }, registries, transport, pager, self: { partnerId: 7 }, translate: createTranslator({ language: "en_US" })._t, reportError: (error: unknown) => console.error(error),};const thread = new Thread({ ...common, order: "desc" });const composer = new Composer({ ...common });host.append(thread.element, composer.element);Thread and Composer share one context per thread (the draft, the reply target and the unsent posts are local records
of the store, ADR 0148 D1.3), so a host mounts the Thread of a reference wherever it mounts that reference’s Composer:
the unsent posts are drawn by the Thread. Thread options: order (desc newest first, the chatter; asc, Discuss),
squash, threadName, scroller. Composer options: sendOnEnter, platform, silent. Shared options: allowReply,
services (each optional: pickEmoji, confirm, copyText, searchPartners, fieldLabel, now, newUid, locale,
timeZone, uploadAttachment), document. Call dispose() when the surface goes away: the thread releases its lease on the store, both stop
following it. The thread’s model must be a model of the store’s schema.
What the components read, and capabilities
Section titled “What the components read, and capabilities”Required message fields: body, message_type, date, author_id; a schema without one makes the constructor throw
ThreadViewError("schema"). Optional fields are capabilities that exist only when the schema declares them: subject,
is_internal, parent_id, tracking (the documented JSON text), attachments, reactions, starred, pinned_at,
edited_at. capabilitiesOf(store) reports them; message.hiddenActions() and composer.hiddenActions() list actions
hidden because the deployment lacks what they need, with the reason (for example “Reactions need server support”). A
transport operation that does not exist is not faked: invoking the action fails with
ThreadViewError("unavailable") naming the owner task. Until the server tasks land, reactions, bookmarks, pins and
deletion therefore stay hidden or fail loudly; attachment upload is active when uploadAttachment is configured; and the full composer is hidden with its owner.
Registries
Section titled “Registries”| Registry | Value | Built-ins |
|---|---|---|
mail.messageActions | { label(ctx), glyph?, condition?(ctx), unavailable?(ctx), pressed?(ctx), run(ctx) } | reaction 10, reply 20, bookmark 80, copy-text 85, pin 90, delete 120 |
mail.composerActions | { label(ctx), glyph?, condition?(ctx), unavailable?(ctx), run(ctx) } | emoji 20, attach 30, full-composer 40 |
mail.messageRenderers | { match(message), layout: "bubble" or "row", render(ctx) } | tracking 10, notification 20, comment 90 |
mail.suggestionProviders | { delimiter, label(ctx), search(term, ctx) } keyed by the delimiter | @ 10 |
Numbers are sequences (lower first); give yours with { sequence }. condition says whether the action applies to this
message; unavailable returns a reason when the deployment cannot do it (checked only where condition holds).
run may be async: a throw or rejection is shown on the message, announced and reported through reportError, never
swallowed. A renderer builds DOM nodes (view.document.createElement, textContent); it must not use innerHTML or insert body markup of its own: a message body reaches the page only through renderBody. A provider’s registry key must equal its delimiter, or the provider is ignored and reported. A suggestion with mention: { partnerId } becomes a structured mention; any other suggestion inserts its
insert (or label) as plain text.
export const acmeCalls: AddonRegistration = { id: "acme_calls", register(ctx) { ctx.registry.category("mail.messageActions").add( "acme_calls.flag", { label: (a) => String(a.view.translate("Flag")), glyph: "!", // Only offered where the schema has the field your addon adds (see "Capabilities"). unavailable: (a) => (a.view.capabilities().bookmark ? null : "Flagging needs the starred field"), run: async (a) => { await fetchFlag(a.message.id); }, }, { sequence: 15 }, ); ctx.registry.category("mail.messageRenderers").add( "acme_calls.call", { match: (message) => message.messageType === "acme_call", layout: "row", render: ({ view, message }) => { const card = view.document.createElement("div"); card.textContent = `Call log #${message.id}`; return card; }, }, { sequence: 5 }, ); ctx.registry.category("mail.suggestionProviders").add("#", { delimiter: "#", label: () => "Channels", search: (term) => ["general", "sales"].filter((c) => c.startsWith(term)).map((c) => ({ id: c, label: `#${c}` })), }); ctx.registry.category("mail.composerActions").add("acme_calls.log", { label: () => "Log call", run: (a) => a.insertText("[call] "), }); },};declare function fetchFlag(messageId: number): Promise<void>;Patching the components
Section titled “Patching the components”export const acmePatches: AddonRegistration = { id: "acme_patches", register(ctx) { ctx.patch(Message, (sup) => ({ authorName(message) { return `${sup.authorName.call(this, message)} (verified)`; }, })); ctx.patch(Composer, (sup) => ({ // Everything buildPost returns is sent, and kept with an unsent post for Retry. buildPost() { return { ...sup.buildPost.call(this), subject: "Re: order" }; }, })); ctx.patch(Thread, (sup) => ({ emptyLabel() { return `${sup.emptyLabel.call(this)} (yet)`; }, })); },};// The same, outside an addon (a host or a test): `patch` is the module function and returns its undo.export const undo = patch(Thread, () => ({ emptyLabel: () => "Nothing here" }));Thread: isSquashed, dayLabel, emptyLabel. Message: showSubject, authorName, timeLabel, isOwn,
rendererFor. Composer: canSend, isSendChord, placeholder, buildPost. Two addons that patch the same member
compose in registration order, and removing one addon’s patch set unwinds only its layer. buildPost() returns the
draft as a PostInput: the subject, recipients and silent flag it returns are sent and are kept with an unsent post, so
a retry sends the same thing.
Mentions and the post
Section titled “Mentions and the post”The composer keeps a plain-text draft and a list of mention spans; it never produces HTML. On send, the spans become
UTF-8 byte offsets and the transport receives only the closed thread_post object: body, message_type, subtype
(comment for Send message, note for Log note), optional parent_id, partner_ids, mentions
({ start, end, partner_id }), silent and client_uid. The answer’s store payload is applied as one request and the
new message id is placed in the thread’s window before the request settles; when it cannot be placed the pager loads the
latest page. A failed post stays as an unsent row with Retry (same client_uid, so the server replays the stored message)
and Discard.
Keyboard and accessibility
Section titled “Keyboard and accessibility”The feed is one tab stop (the current article) followed by that article’s toolbar. ArrowDown/ArrowUp and PageDown/PageUp
move between articles, Home and End jump, ArrowLeft/ArrowRight/Home/End move inside the toolbar, Escape returns from the
toolbar to its article. In the composer Ctrl+Enter (Cmd+Enter on a Mac) sends in the chatter, Enter in Discuss
(sendOnEnter); the suggestion list takes ArrowUp/ArrowDown, Enter or Tab, Escape. The feed is a role="feed" of
articles only; actions are text buttons; toggles use aria-pressed; failures use role="alert"; status messages are
announced through a polite live region. An addon’s controls must have text names and may not add positive tabindex.
Errors you handle
Section titled “Errors you handle”ThreadViewError has a closed code: schema, unavailable, bad_option, registry, data, transport, mention,
body, pending_limit, disposed. Constructor refusals are thrown; failures during use are shown in the component and
passed to the reportError option.
Not in this version
Section titled “Not in this version”Edit in place, the reaction list, pinned-messages panel, search, copy link, download files, translation, canned
responses, emoji and command providers, roles as mention targets, and the variable-height virtual list (the thread
renders its bounded window; Thread.layout is the seam). The owning slices are named in the design note.