Skip to content

✨(backend) email thread participants on reply - #2802

Open
AntoLC wants to merge 5 commits into
mainfrom
feat/notify-thread-reply-email
Open

AntoLC wants to merge 5 commits into
mainfrom
feat/notify-thread-reply-email

Conversation

@AntoLC

@AntoLC AntoLC commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Purpose

Participants of a comment thread were never told about a reply unless they were mentioned. They now get an email when someone answers in a thread they take part in.

Proposal

  • Recipients: the thread creator, the authors of earlier comments and the users mentioned in the thread, minus the reply author. Only active users with an explicit access allowed to comment (same rule as mentions); users the author just mentioned are skipped as the mention email covers them
  • Queue the email in a Celery task so SMTP stays out of the request; queuing is best effort and never fails the creation of the comment
  • Guard against duplicate emails when a task is delivered twice, and a failing recipient does not block the others
  • Throttle a conversation per recipient: a user is emailed at most once per THREAD_REPLY_NOTIFICATION_COOLDOWN_MINUTES in a thread (default 15, 0 disables). The delay is per user, so a participant who was not emailed yet is never silenced by the emails sent to the others: A creates a thread, B replies and A is emailed, A replies 5 minutes later and B is emailed (A is not, again). The delay is fixed from the email, the following replies do not extend it, so an active thread cannot keep a user uninformed. It is released when the email could not be sent

New env

# Comment threads
THREAD_REPLY_NOTIFICATION_COOLDOWN_MINUTES = values.IntegerValue(
15,
environ_name="THREAD_REPLY_NOTIFICATION_COOLDOWN_MINUTES",
environ_prefix=None,
)

Email Demo

image

Known limitations

  • A user who was just emailed does not get another email for the replies posted during their delay. The email only links to the document, so they see everything when they open it, but they are not told that newer replies exist.
  • A user mentioned by the reply author in the thread, within MENTION_NOTIFICATION_COOLDOWN_MINUTES, is skipped because the mention email covers them. If that mention email was itself suppressed by the mention cooldown, the user gets neither email.

Possible follow-up: a "seen" notion

Both limitations (and the repeated mention of a user in the same context within the mention cooldown) come from throttling on time only. We could throttle on whether the user has seen the thread instead:

  • Record when each user last saw a thread (one row per (thread, user) with last_seen_at; a user's own reply counts as seen).
  • On a reply, queue one delayed task per recipient, with a countdown of THREAD_REPLY_NOTIFICATION_COOLDOWN_MINUTES. When it runs, send the email only if the user has not seen the thread since the comment was created, and was not already emailed about an earlier unseen reply.
  • Open question, how to detect "seen": mark the thread as seen when its comments are fetched (backend only, cheap but approximate, since the frontend refetches threads on a ping and a background tab would count), or an explicit POST threads/{id}/seen/ called when the thread is displayed (accurate, but needs a small frontend change and has to work with the offline queue).
  • Trade-offs: a new model and migration, a rework of the notification task, and an email a few minutes after the reply instead of immediately.

@AntoLC AntoLC added feature add a new feature backend labels Oct 8, 2026
@AntoLC AntoLC self-assigned this Oct 8, 2026
@AntoLC
AntoLC force-pushed the feat/notify-thread-reply-email branch from 00b98d4 to 5b3ffbb Compare October 8, 2026 09:02
@AntoLC
AntoLC requested review from lunika and removed request for lunika October 8, 2026 10:01
@AntoLC
AntoLC force-pushed the feat/notify-thread-reply-email branch from 5b3ffbb to b1e3e36 Compare October 8, 2026 10:20
@AntoLC
AntoLC requested a review from lunika October 8, 2026 10:31
@virgile-dev

Copy link
Copy Markdown
Collaborator
  • Do we have a link that open the comment modal and scrolls to the right spot ?

For the email content this is my suggestion.

Subject: {{User_name}} replied to a comment in "{{document_title}}"

Title:
{{User_name}} replied to a comment in the following document:
{{document_title}}

Button: {{Open}}

Docs: Your essential tool for organizing, sharing, and collaborating on documents as a team.

A solution by La Suite Numérique.

AntoLC added 4 commits October 9, 2026 14:52
Add the logic computing who must hear about a new comment in an existing
thread and the email sent to them. The recipients are the participants of the
thread (its creator, the authors of the earlier comments and the users
mentioned in it) minus the author of the reply, deduplicated, and only active
users holding an explicit access allowed to comment, like for mentions.
Users the reply author just mentioned are skipped as the mention email
already covers them. A per recipient guard avoids duplicates when a task is
delivered twice and a failing recipient does not block the others.

Signed-off-by: Anthony LC <anthony.le-courric@mail.numerique.gouv.fr>
Queue a Celery task when a comment is added to an existing thread, so the
SMTP round-trips stay out of the request. Queuing is best effort and a
failure to send never fails the creation of the comment. The first comment of
a thread is created with the thread by another code path and is not notified.

Signed-off-by: Anthony LC <anthony.le-courric@mail.numerique.gouv.fr>
Participants of a thread that keep answering each other got one email per
reply. A user is now emailed at most once per
THREAD_REPLY_NOTIFICATION_COOLDOWN_MINUTES (default 15, 0 disables it) in a
thread. The delay is per user, so a participant not emailed yet is never
silenced by the emails sent to the others, and it is fixed from the email,
so a long conversation cannot keep a user uninformed.

Signed-off-by: Anthony LC <anthony.le-courric@mail.numerique.gouv.fr>
@AntoLC
AntoLC force-pushed the feat/notify-thread-reply-email branch from b1e3e36 to 570b500 Compare October 9, 2026 13:53
@AntoLC

AntoLC commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

Do we have a link that open the comment modal and scrolls to the right spot ?

I added a commit frontend side to do it.

Docs: Your essential tool for organizing, sharing, and collaborating on documents as a team.

A solution by La Suite Numérique.

I updated the main email message.
The part mentioned is not modified, I suggest that we change it in another PR because it is not directly linked to this PR, all the email have this message, it will probably break lot of tests.

The reply email links to #thread=<id>,comment=<id>
but nothing read that hash. Open the thread, scroll
the editor to the commented text and
the thread to the comment. Block anchors
ignore this hash.
@AntoLC
AntoLC force-pushed the feat/notify-thread-reply-email branch from 570b500 to a0f816f Compare October 9, 2026 14:01
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Size Change: +1 kB (+0.02%)

Total Size: 4.06 MB

📦 View Changed
Filename Size Change
apps/impress/out/_next/static/7cceab40/_buildManifest.js 697 B +697 B (new file) 🆕
apps/impress/out/_next/static/chunks/1519.js 69 kB +636 B (+0.93%)
apps/impress/out/_next/static/chunks/2253.js 0 B -284 kB (removed) 🏆
apps/impress/out/_next/static/chunks/6277.js 0 B -156 kB (removed) 🏆
apps/impress/out/_next/static/chunks/7064.js 283 kB +283 kB (new file) 🆕
apps/impress/out/_next/static/chunks/7986.js 157 kB +157 kB (new file) 🆕
apps/impress/out/_next/static/eea248e3/_buildManifest.js 0 B -701 B (removed) 🏆

compressed-size-action

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend feature add a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants