Commit Graph
1 Commits
Author SHA1 Message Date
CatoandClaude Opus 5 6746d490a9 refactor(messages): one thread hook for both sides of the conversation
The patient's thread view and the clinician's thread view are the same
conversation from opposite chairs, and each carried its own copy of the same
sixty lines: fetch the thread, poll it while the tab is visible, scroll to the
newest message, post a reply, clear the box, say "Failed to send" the same way.

That is behaviour, not markup, and behaviour that is written twice drifts. If
the poll interval or the failed-send handling changed on one side only, a
clinician and a patient would disagree about whether a message had been
delivered — in a clinical conversation, on a medical platform.

/api/messages/[threadId] is already ONE endpoint for both: the server decides
who "you" are and marks each message `mine`. So the hook does not know, and
does not need to know, which side is asking — it takes the thread type as a
parameter and leaves the rest alone.

What stays per-page is what genuinely differs: the markup, the back link, the
wording ("Type a message…" vs "Reply to patient…"), the participants line the
patient sees, and the patient header the clinician sees. The portal's Retry
button now calls the hook's `retry`, which clears the failed state first so a
second failure is visible rather than silent.

No change to what either side renders or to any request made.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8
2026-09-15 11:46:29 +02:00