refactor(messages): MessageActor enum for render-time actor identity (LC-77) #194
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/lc-77-message-actor-enum"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Replace
MessageView::author_is_webhook+webhook_avatar_url(a bool + Option pair) with a singleactor: MessageActorsum type. This is the LC-62 "refactor before feature" prep for LC-77 per-room email ingress: the email synthetic actor lands asMessageActor::EmailInboxin the next commit, sitting cleanly next to the existingWebhookandUserarms.Behavior-preserving for LC-74 incoming webhooks. The fixture committed in the first commit on this branch pins the rendered HTML byte-for-byte; the refactor commit's identical rendered output is the proof.
Why this refactor before the email feature
Reply-by-email (the deferred LC-77 sibling) is a known fourth case. Extract-the-abstraction-now is the right call when the next caller is committed (the email arm IS committed, scheduled for the very next commit), not speculative. Doing the boolean -> enum conversion mid-feature would either bloat the email PR or leave LC-74 with a stopgap shape that would need unwinding later.
Behavior preservation
tests/lc77_webhook_render_fixture.rsconstructsMessageViewwith deterministic values for two cases (webhook without avatar URL, webhook with avatar URL), renders viaNewMessageFragment(the same fragment the WS hub broadcasts), and asserts the rendered HTML matches the committed fixture files undertests/fixtures/.Fixture files captured in the first commit (BEFORE the refactor). The refactor commit's
cargo testpasses byte-equal on both fixtures, no DOM-equal fallback needed. The Askama{% match %}emitted identical whitespace to the previous{% if %}chain.What changed
server/src/views/message_actor.rs.MessageActorenum withUserunit variant andWebhook(Option<String>)tuple variant carrying the webhook avatar URL. Tuple variant chosen to match the only Askama match precedent in this repo (room/moderators.htmluses{% when Some with (d) %}). ConstructorMessageActor::from_webhook_flag(is_webhook, avatar_url)keeps the if/else logic in one place so every construction site stays one line.MessageView:author_is_webhook: boolandwebhook_avatar_url: Option<String>removed; replaced withactor: MessageActor.templates/room/message.htmllines 17-42:{% if message.author_is_webhook %}converted to{% match message.actor %}with explicitWebhookandUserarms. The template uses the fully qualified pathcrate::views::message_actor::MessageActor::...so no import is needed in the Template-deriving modules that include this partial (views/ws_fragments.rs,views/room.rs,views/dm.rs).routes/mod.rs(1),routes/dm.rs(1),routes/room.rs(4),routes/ws.rs(3),tests/lc77_webhook_render_fixture.rs(1, post-refactor shape). Each callsMessageActor::from_webhook_flag(...).Anti-scope
user_id,username,avatar_ext,status,custom_status,author_is_bot) stay onMessageViewsince they're shared across actor types. The User variant is intentionally unit.MessageActor. The template branches via{% match %}directly. If commit 3 needs accessors for the EmailInbox arm they can be added then.Test plan
cargo check --workspaceclean.cargo check --no-default-features --features lets-chat-server/saasclean.cargo test -p lets-chat-server --testsall 50 binaries pass under default features.cargo test -p lets-chat-server --tests --no-default-features --features saasall 50 binaries pass under saas.cargo clippy -p lets-chat-server -- -D warningsclean.cargo fmt --checkclean for files in this PR. Pre-existing fmt diffs inviews/math.rs+views/markdown.rspredate this branch (LC-59 carryover onmain); separate hygiene followup ticket tracked.Followups out of scope for this PR
Tracked as LC-77 sub-issues so they don't evaporate:
LC-77-SMTP-SEAL(migrate SMTP password to VAPID-sealed pattern),LC-77-REPLY(reply-by-email),LC-77-MID-DEDUP(exactly-once dedup),LC-77-DEAD-LETTER(optional dead-letter IMAP folder),LC-77-FMT-CARRYOVER(math.rs/markdown.rs fmt cleanup from LC-59).