Skip to content

feat: polls, snippets, quotes and questions - #153

Closed
ArtMin96 wants to merge 7 commits into
dev-null-sh:productionfrom
ArtMin96:feat/commit-types
Closed

ArtMin96 wants to merge 7 commits into
dev-null-sh:productionfrom
ArtMin96:feat/commit-types

Conversation

@ArtMin96

@ArtMin96 ArtMin96 commented Oct 15, 2026 •

Copy link
Copy Markdown

Stacked on #152 (commit types + Release). Review that first. This PR's own commits, and nothing from #152, are in the compare view: ArtMin96/dev-null.sh@feat/commit-types-foundation...feat/commit-types

Four more commit types on the contract from #152, plus the two notifications two of them need. Each type is a DTO, a migration or column, a card and composer fields, and one line in the shared loader. The request, the create action, the controllers and the query classes keep the shape they had after #152.

Summary

  • Poll: 2 to 4 options, open for 1 hour / 1 day / 3 days / 7 days from approval. Select-then-Vote, one final vote per voter, results hidden server-side until you vote. Authors don't vote.
  • Snippet: code in one of 28 languages, highlighted on the server with tempest/highlight, with a filename, a copy button, and folding past 15 lines. Introduces the shared CodeHighlighter.
  • Quote: any approved commit, embedded under your own, with [deleted] / [unavailable] tombstones.
  • Question: the author accepts one direct reply as the answer.
  • Notifications for quotes and accepted answers, and the personal data export of every type's data.
  • 296 tests added (966 → 1262), 100% line and type coverage, PHPStan level: max.

Why this design

Every type here is added the five-step way #152 describes, which keeps the shared surface small and the types independent of each other:

  • A type's state checks live in an App\Rules rule and its visibility in authorize(), never in an action, so the actions stay create/update/delete only and ArchTest passes.
  • withContentFor() stays the one eager-loading point. A log page or the moderation queue that mixes every type costs the same number of queries as one with a single commit: two tests (loads a log of every commit type with a bounded number of queries, renders every commit type in the queue with a bounded number of queries) triple every type on the page and assert the query count is unchanged.
  • Each type adds its own withContentFor() relation, its own commit-type-content.tsx case and its own composer-types.ts entry, and the one ?CommitTypeData argument carries all of them through CreateCommit::handle().

What's included

Poll

polls (duration as a PollDuration enum of minutes, closes_at), poll_options (label, position) and poll_votes (unique per poll and voter). PollData validates 2 to 4 options, distinct once trimmed and case-folded, up to 50 characters each, with emoji shortcodes expanded; it forbids images (allowsImages() is false). The clock starts when the commit is approved (UpdatePollsClosesAt, called from UpdateCommitStatuses), so moderation never shortens a poll; re-approval never extends it.

Voting is two steps because a vote is final: the options are a native radio group in a fieldset with a legend, picking one casts nothing, and the "Vote" button submits optimistically with rollback on failure. Focus stays on the poll after voting, and the bars skip their animation under reduced motion. POST commits/{commit}/poll/votes (CommitPollVoteController, invokable) checks visibility in authorize() (denyAsNotFound) and the poll's state in a VotablePoll rule that returns a reason per refusal (not open yet, your own poll, closed), shown in the toast. The vote is idempotent: a second or racing vote keeps the first.

Results are hidden server-side until you may see them. Poll::toArray() sends each option's votes_count as null unless you voted, you are the author, or the poll closed; who voted for what is never serialized. Percentages use the largest-remainder method, so the shares always total 100.

Light Dark
Composer
Before voting (results hidden)
Option selected, Vote ready
After voting
Closed
Pending, in moderation

Mobile: open light / dark, voted light / dark.

Create → approve → vote (MP4):

A poll is created, approved by a moderator, then voted on

Snippet

snippets (language as a SnippetLanguage enum, nullable filename, code). SnippetData caps the code at 4000 characters or 200 lines, normalizes line breaks to \n, and keeps the code exactly as typed. The new CodeHighlighter service (scoped) highlights server-side with tempest/highlight and validates the result: it keeps the highlighted HTML only when it is the escaped code wrapped in hl-* spans, and otherwise falls back to the plain escaped code. It caches per language and code, and a page of snippets reads the cache once (afterQuery prefetch), so the same code is highlighted once however often it appears. The card shows the filename or language label and a copy button, with the code folded past 15 lines.

Light Dark
Composer
Card, folded
Card, expanded

Mobile: folded light / dark.

Quote

A nullable self-referencing commits.quoted_commit_id (null on delete), set in the same insert that creates the quote (via the contract's attributes(), no extra update). QuotableCommit allows only approved commits that still exist. withContentFor() loads the quoted commit scoped to the viewer, so a quote only ever shows what the viewer may see: a deleted quoted commit is a [deleted] tombstone, one hidden since is [unavailable], and authors still see their own once it stops being public. Moderators reviewing a pending quote see what it quotes whatever its status. The quote button sits after the star wherever the star shows, with the q shortcut (in the keyboard-shortcuts dialog) and a "Quote @handle" dialog that has its own mentions, images and stash. CreateQuoteNotifications notifies the quoted author once the quote is approved (never for quoting yourself), the mention path dedupes a quoted author who is also mentioned, and the notification is removed when the quoted commit is deleted.

Light Dark
Quote button in the row
Dialog
Card
Quoted commit deleted
Quoted commit unavailable

Mobile: card light / dark.

Quoting from the feed (MP4):

Quoting a release from the feed

Question

A nullable self-referencing commits.accepted_answer_id (null on delete). QuestionData has no fields: a question is its body. PUT and DELETE commits/{commit}/accepted-answer (CommitAnswerAcceptanceController / CommitAnswerRevocationController, invokable) let only the question's author accept or remove an answer, and only an approved, non-deleted direct reply. Accepting locks the question row, replaces the previous answer and its notification, and notifies the new answer's author (not when you accept your own reply). withContentFor() derives is_answered (true only while the accepted answer exists and is approved). The card shows a question or answered badge; the thread shows "Accept answer" / "Unaccept" to the author and an "Accepted answer" badge on the chosen reply, updated optimistically.

Light Dark
Composer
Open question
Answered thread

Mobile: answered thread light / dark.

Notifications and export

NotificationType gains Quoted and AnswerAccepted; NotificationBuilder::relevant() keeps each only while its commit is approved, the same rule as replies and mentions. The notifications page shows "quoted your commit" and "accepted your answer".

Notifications (light) Notifications (dark)

CreateExport adds each commit's type and data, and the user's own poll votes on polls everyone can still see. The combined composer toolbar with every type's toggle: light / dark.

Performance & security

  • Feed and moderation query counts are constant across every type, asserted by the two mixed-type tests above.
  • Snippet highlighting is cached and prefetched per page; the highlighter output is validated and falls back to escaped plain code.
  • Poll results are withheld server-side, so a non-voter never receives the counts; voters are never serialized; guests see no poll, counts or voters (tested).
  • Poll voting authorizes with denyAsNotFound and validates state in a rule; quotes only point at approved, visible commits.

Testing

296 tests added (966 after #152 → 1262), 100% line and type coverage, PHPStan level: max.

By area
  • Poll: PollCommitTest, CommitPollVoteControllerTest, PollApprovalTest (lifecycle: opens on approval for its full duration, admins at once, re-approval never extends, no votes before approval), CreateCommitPollVoteTest (final vote, racing votes, counts), CreatePollCommitTest. Visibility: results hidden from non-voters, shown to the author and after close, never who voted, never to guests.
  • Snippet: SnippetCommitTest, CodeHighlighterTest (highlights, plain text as-is, escapes markup, falls back when the output is not clean, caches once per page).
  • Quote: QuoteCommitsTest, CreateQuoteNotificationsTest (approved only, not yourself, not deleted, idempotent), tombstones, moderator view, guest non-exposure, notification cleanup, mention dedupe.
  • Question: QuestionCommitTest, AcceptedAnswerControllerTest, UpdateAcceptedAnswerTest, DeleteAcceptedAnswerTest.
  • Notifications and export: NotificationControllerTest, NotificationBuilderTest, ExportControllerTest.

Related work

Notes for reviewers

🤖 Generated with Claude Code

ArtMin96 and others added 7 commits October 16, 2026 01:49
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@brendt

brendt commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Some good things here, but we've already merged some individual features :)

@brendt brendt closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants