Comments 0.4.0: Comments keyed by metadata, and translated sidebar labels
Comments 0.4.0 is mainly for developers who build on the PhoenixKit comments module: threads can be found and updated by their metadata, reply counts come in one query, and the resource handler contract is now declared. Admins get translated sidebar labels and corrected Estonian and Russian texts.
Comments keyed by metadata
A comment is attached to a record by a resource type and a uuid. Plenty of apps key their threads on something else, such as a source, a slug and a chapter. They had to invent a throwaway uuid, keep the real key in the comment’s metadata, and then query the module’s table with their own SQL to list such a thread.
list_comments/3 now takes a :metadata map of keys that must match, and :any in place of the uuid to list across a whole resource type:
list_comments("chapter", :any, metadata: %{"source" => "mangadex", "slug" => slug})
Two new functions write metadata in a single atomic statement, so they cannot lose keys a concurrent writer added. update_metadata/2 patches one comment. merge_metadata/3 patches every comment of a type that matches, which covers a rename: when a slug changes, every comment that carries the old one follows. An empty match is refused instead of being read as “every comment”.
Reply counts in one query
count_replies/2 returns a count of replies for a batch of parent comments from one grouped query, with a 0 entry for every uuid asked about. A list of threads can show its reply counts without one query per thread. A failed query is now logged before the function falls back to zeros, so “0 replies” on a thread that has replies leaves a trace.
A declared resource handler contract
PhoenixKitComments.ResourceHandler now lists its callbacks with callbacks/0 and event_callbacks/0. Handlers are called only if a function with the right name and arity exists, so a misspelled callback simply never fires. Adopting the behaviour lets the compiler catch that.
Translations
The Comments tabs in the admin sidebar and in Settings now declare the module’s translation backend, so their labels appear in the admin’s language. Several Estonian and Russian entries that carried another string’s translation, or that Gettext ignored as fuzzy, are fixed. Two plural forms had lost their action word, so a bulk result read “5 comments” instead of “5 comments deleted”.
Upgrading
No migration and no configuration. Comments 0.4.0 needs phoenix_kit 2.x, as 0.3.0 did. Update the dependency. Existing calls to list_comments/3 and count_comments/3 behave as before.
Full release notes: Comments 0.4.0
0.4.0 · 11 August 2026
Metadata-keyed reads and writes, a declared resource-handler contract, and the translated sidebar labels.
Added
-
Metadata-keyed reads (#34).
list_comments/3takes a:metadatamap of keys that must match, and:anyin place of a resource uuid to list across a whole resource type.resource_uuidis a UUID column and plenty of hosts key their comments on something that isn’t one — a(source, slug, chapter)triple — so they mint a throwaway uuid and put the real key inmetadata. The listing they actually want was not expressible, and they dropped to schemaless SQL against this package’s own table to get it. -
update_metadata/2andmerge_metadata/3(#34). Single atomicmetadata || patchwrites, so they cannot lose a concurrent writer’s keys the way read-modify-write does.merge_metadata/3is the rename case — a host renames a slug and every comment carrying the old one has to follow. An empty match is refused rather than treated as “everything”. -
count_replies/2(#34) —parent_uuid => countfor a batch of parents in one grouped query, with a0entry for every uuid asked about, so a thread list renders uniformly without an N+1. -
PhoenixKitComments.ResourceHandler.callbacks/0andevent_callbacks/0(#35), and the rationale for adopting the behaviour at all: dispatch is byfunction_exported?/3, so a misnamed or wrong-arity callback is indistinguishable from one you chose not to write — nothing fires and there is no error to find it by.
Changed
- Sidebar tab labels are translated (#33). The admin and settings tabs
declare
gettext_backendandgettext_domain, which they need in order to resolve at all.
Fixed
-
Estonian and Russian entries that carried another string’s translation (#33), and entries whose
fuzzyflag meant Gettext ignored them at runtime and showed the English msgid instead. Two plural forms had also dropped their%{action}interpolation, so a bulk-action result read “5 comments” instead of “5 comments deleted”. -
count_replies/2reported zeros silently on a failed query. “0 replies” on a thread that has replies is a plausible-looking wrong answer rather than an obviously broken one, and nothing anywhere distinguished it from a quiet thread. It now logs before degrading.
Comments 0.4.0. Install or update: {:phoenix_kit_comments, "~> 0.4"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.