PhoenixKit.Modules.Publishing.Comments (PhoenixKitPublishing v0.4.5)

Copy Markdown View Source

Optional seam to phoenix_kit_comments — same posture as the phoenix_kit_og plugin seam: publishing has NO dep on the comments package; every call is Code.ensure_loaded? + function_exported? guarded and rescued, so a host without the module (or with it disabled from /admin/modules) renders publishing pages with no comments UI and no crashes.

Comments attach to resource_type: "publishing_post" with the post uuid, matching the ecosystem convention (staff/CRM tabs, core's media annotations). Public commenting is logged-in only for now — the comments schema requires a user_uuid; guest commenting needs a comments-module change (tracked in the roadmap as a cross-repo follow-up).

Summary

Functions

True when the comments module is installed AND enabled.

The comments module's one-per-page markdown styles, or nothing.

Published-comment count for a post.

Creates a comment on a post for a logged-in user. Returns the comments module's result verbatim ({:ok, comment} or {:error, reason}:content_too_long, :empty_comment, :max_depth_exceeded, …).

Everything the post page needs in one read, pre-partitioned

Published comments for a post, oldest first, with authors preloaded.

Renders a comment's markdown content — the comments module's sanitized comment_markdown/1 component when available, escaped plain text with line breaks otherwise.

Total node count of a comment tree (a panel's thread size).

Functions

available?()

True when the comments module is installed AND enabled.

content_styles()

The comments module's one-per-page markdown styles, or nothing.

count(post_uuid)

Published-comment count for a post.

create(post_uuid, user_uuid, content, opts \\ [])

Creates a comment on a post for a logged-in user. Returns the comments module's result verbatim ({:ok, comment} or {:error, reason}:content_too_long, :empty_comment, :max_depth_exceeded, …).

Options

  • :parent_uuid — makes this a reply. The parent must be a published comment on the SAME post (the comments module computes depth from the parent but does not check resource ownership — a crafted uuid could otherwise thread onto another post's comment). A reply inherits its parent's note_id, so a thread never straddles the main list and a note panel.
  • :note_id — anchors the comment to an author note (posted from the note's slide-out panel). Stored in metadata["note_id"].

for_post_page(post_uuid, known_note_ids \\ nil)

Everything the post page needs in one read, pre-partitioned:

  • :thread — the main comment thread as a nested tree (each comment gets a :children list), replies attached via parent_uuid;
  • :note_comments%{note_id => [comments]} for comments carrying a metadata["note_id"] (posted from a note's slide-out panel), each note's list a nested tree like the main thread (replies inherit the parent's note_id, so a whole thread lives in one panel);
  • :count — main-thread comment count (replies included, note comments excluded — the "N comments" header describes the thread the reader is looking at).

list(post_uuid)

Published comments for a post, oldest first, with authors preloaded.

render_content(content)

Renders a comment's markdown content — the comments module's sanitized comment_markdown/1 component when available, escaped plain text with line breaks otherwise.

tree_size(comments)

Total node count of a comment tree (a panel's thread size).