Attach discussions to an authorized resource
A comment belongs to a document, task, or other business record, not merely a tenant-wide string identifier. Store tenant and resource identity explicitly, then check the actor's current ability to access that resource when listing or creating comments. Guessing a discussion ID must never reveal its contents.
Define whether participants can read historical discussion after access changes. Prefer evaluating current resource permissions to preserving accidental access through old notifications. Separate the ability to read, comment, edit one's own message, moderate, and resolve a thread; those are different capabilities.
Keep thread state separate from message content
Represent threads and messages independently. A thread can be open, resolved, reopened, or archived while retaining its messages. Use stable IDs and explicit reply relationships. Decide whether nested replies are supported and bound their depth so rendering and moderation remain manageable.
Use a server-generated ordering key with a stable tie-breaker rather than relying on browser timestamps. A retry after a lost response should converge on one message through a scoped request identity. Commit the message and any durable notification intent together so a successful post cannot silently lose its delivery work.
Resolve mentions as identities, not parsed display names
Use a structured mention node containing an immutable user identity, with display text generated separately. Revalidate the mentioned user on the server: they must belong to the allowed audience and satisfy the product's resource-access rules. A stale autocomplete result is not permission to notify someone.
Decide what happens when an author types a plain-text @name without choosing an identity. Do not guess between similarly named users. Limit mentions per message and rate-limit abusive fan-out. Mentioning a person should not automatically grant them resource access unless a separate, explicit sharing workflow authorizes it.
Treat stored discussion content as untrusted
Choose a constrained content format and validate its structure. Render plain text safely, or sanitize supported rich text through a maintained implementation appropriate to the actual renderer. Avoid executing embedded HTML, event handlers, or arbitrary URLs simply because the content was written by an authenticated employee.
Handle links and attachments under explicit policy. File access should remain authorized independently of a comment URL. Keep previews from fetching arbitrary internal addresses, and avoid including sensitive discussion text in analytics, error reports, or third-party resources loaded by the discussion panel.
Notify from committed state with bounded fan-out
Create durable notification work after the comment is accepted, carrying message ID, thread ID, tenant, and intended recipient identity. Deduplicate delivery for a user who is both mentioned and subscribed. Recheck access before exposing message content in an email or other external channel.
Distinguish delivery from reading. A provider accepting an email does not mean the recipient saw it. Respect preference and unsubscribe rules for the relevant notification category, and avoid sending the author a redundant alert about their own message. Give users a clear path to mute a noisy thread.
Define edits and deletion without rewriting accountability
Keep a message revision when an edit needs conflict protection or history. If two clients edit simultaneously, reject a stale base revision rather than silently overwriting. Show an edited indicator and decide which history moderators and ordinary participants may inspect.
Recompute mention changes deliberately. Adding a new mention may create a notification; removing one cannot retract an email already delivered. For deletion, distinguish a visible tombstone from physical erasure. Preserve enough structure for replies to remain intelligible without retaining deleted sensitive text beyond policy.
Make the discussion usable with a keyboard
Label the editor, send action, attachment controls, and thread status. Keep mention suggestions keyboard-operable and make selection intentional. Do not force focus into the thread whenever a new message arrives; let the reader stay in control of their current task.
Show pending submission, failed delivery to the application, and a retry path without losing the draft. Announce concise status changes rather than every character of new discussion. When a thread is resolved, preserve a clear way to review or reopen it if the user has permission.
Test access changes and delivery races
Test duplicate post requests, removed recipients, permission loss after enqueue, message edits before delivery, a deleted attachment, a resolved thread receiving a late reply, and two tenants with similar resource identifiers. Confirm that notifications cannot become an alternate unauthorized read API.
Monitor queue age, failed fan-out, repeated mention rejection, and moderation actions using safe identifiers. Keep operational diagnostics separate from message bodies. A reliable discussion feature makes participation understandable while keeping every read and notification inside the resource's current access boundary.
Build a more dependable Next.js application
Endurance Softwares helps teams design, build, test, and operate production-ready Next.js platforms.
