Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add config to change the delay before sending a notification email
Browse files Browse the repository at this point in the history
  • Loading branch information
MatMaul committed Nov 27, 2023
1 parent 8751f0e commit 34f6ee6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/16696.feature
@@ -0,0 +1 @@
Add a setting to be able to tweak the delay without interaction before an email is sent following a notification.
2 changes: 2 additions & 0 deletions docs/usage/configuration/config_documentation.md
Expand Up @@ -663,6 +663,8 @@ This setting has the following sub-options:
has missed. Disabled by default.
* `notif_for_new_users`: Set to false to disable automatic subscription to email
notifications for new users. Enabled by default.
* `delay_before_mail`: Time we always wait before ever emailing about a notification
(to give the user a chance to respond to other push or notice the window). Defaults to 10 minutes.
* `client_base_url`: Custom URL for client links within the email notifications. By default
links will be based on "https://matrix.to". (This setting used to be called `riot_base_url`;
the old name is still supported for backwards-compatibility but is now deprecated.)
Expand Down
3 changes: 3 additions & 0 deletions synapse/config/emailconfig.py
Expand Up @@ -294,6 +294,9 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
self.email_riot_base_url = email_config.get(
"client_base_url", email_config.get("riot_base_url", None)
)
self.delay_before_mail_ms = Config.parse_duration(
email_config.get("delay_before_mail", "10m")
)

if self.root.account_validity.account_validity_renew_by_email_enabled:
expiry_template_html = email_config.get(
Expand Down
10 changes: 4 additions & 6 deletions synapse/push/emailpusher.py
Expand Up @@ -30,10 +30,6 @@

logger = logging.getLogger(__name__)

# The amount of time we always wait before ever emailing about a notification
# (to give the user a chance to respond to other push or notice the window)
DELAY_BEFORE_MAIL_MS = 10 * 60 * 1000

# THROTTLE is the minimum time between mail notifications sent for a given room.
# Each room maintains its own throttle counter, but each new mail notification
# sends the pending notifications for all rooms.
Expand Down Expand Up @@ -80,6 +76,8 @@ def __init__(self, hs: "HomeServer", pusher_config: PusherConfig, mailer: Mailer
except ValueError:
raise PusherConfigException("Invalid email")

self._delay_before_mail_ms = self.hs.config.email.delay_before_mail_ms

def on_started(self, should_check_for_notifs: bool) -> None:
"""Called when this pusher has been started.
Expand Down Expand Up @@ -180,7 +178,7 @@ async def _unsafe_process(self) -> None:
received_at = push_action.received_ts
if received_at is None:
received_at = 0
notif_ready_at = received_at + DELAY_BEFORE_MAIL_MS
notif_ready_at = received_at + self._delay_before_mail_ms

room_ready_at = self.room_ready_to_notify_at(push_action.room_id)

Expand All @@ -196,7 +194,7 @@ async def _unsafe_process(self) -> None:
"room_id": push_action.room_id,
"now": self.clock.time_msec(),
"received_at": received_at,
"delay_before_mail_ms": DELAY_BEFORE_MAIL_MS,
"delay_before_mail_ms": self._delay_before_mail_ms,
"last_sent_ts": self.get_room_last_sent_ts(push_action.room_id),
"throttle_ms": self.get_room_throttle_ms(push_action.room_id),
}
Expand Down

0 comments on commit 34f6ee6

Please sign in to comment.