summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorMathieu Velten <matmaul@gmail.com>2023-12-12 11:28:56 +0100
committerGitHub <noreply@github.com>2023-12-12 10:28:56 +0000
commit9f6c64482535db0d0bc265a2d7d21ce4d618dd45 (patch)
tree675ebb54c2d8ac1731f937516c87f152102b0950 /synapse
parentBump isort from 5.13.0 to 5.13.1 (#16752) (diff)
downloadsynapse-9f6c64482535db0d0bc265a2d7d21ce4d618dd45.tar.xz
Add config to change the delay before sending a notification email (#16696)
Diffstat (limited to 'synapse')
-rw-r--r--synapse/config/emailconfig.py5
-rw-r--r--synapse/push/emailpusher.py15
2 files changed, 11 insertions, 9 deletions
diff --git a/synapse/config/emailconfig.py b/synapse/config/emailconfig.py
index a3af35b7c4..e33791fab9 100644
--- a/synapse/config/emailconfig.py
+++ b/synapse/config/emailconfig.py
@@ -294,6 +294,11 @@ class EmailConfig(Config):
             self.email_riot_base_url = email_config.get(
                 "client_base_url", email_config.get("riot_base_url", None)
             )
+            # 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)
+            self.notif_delay_before_mail_ms = Config.parse_duration(
+                email_config.get("notif_delay_before_mail", "10m")
+            )
 
         if self.root.account_validity.account_validity_renew_by_email_enabled:
             expiry_template_html = email_config.get(
diff --git a/synapse/push/emailpusher.py b/synapse/push/emailpusher.py
index cf45fd09a8..be7631e8d0 100644
--- a/synapse/push/emailpusher.py
+++ b/synapse/push/emailpusher.py
@@ -30,14 +30,9 @@ if TYPE_CHECKING:
 
 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.
-THROTTLE_START_MS = 10 * 60 * 1000
 THROTTLE_MAX_MS = 24 * 60 * 60 * 1000  # 24h
 # THROTTLE_MULTIPLIER = 6              # 10 mins, 1 hour, 6 hours, 24 hours
 THROTTLE_MULTIPLIER = 144  # 10 mins, 24 hours - i.e. jump straight to 1 day
@@ -80,6 +75,8 @@ class EmailPusher(Pusher):
         except ValueError:
             raise PusherConfigException("Invalid email")
 
+        self._delay_before_mail_ms = self.hs.config.email.notif_delay_before_mail_ms
+
     def on_started(self, should_check_for_notifs: bool) -> None:
         """Called when this pusher has been started.
 
@@ -180,7 +177,7 @@ class EmailPusher(Pusher):
             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)
 
@@ -196,7 +193,7 @@ class EmailPusher(Pusher):
                     "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),
                 }
@@ -300,10 +297,10 @@ class EmailPusher(Pusher):
         current_throttle_ms = self.get_room_throttle_ms(room_id)
 
         if gap > THROTTLE_RESET_AFTER_MS:
-            new_throttle_ms = THROTTLE_START_MS
+            new_throttle_ms = self._delay_before_mail_ms
         else:
             if current_throttle_ms == 0:
-                new_throttle_ms = THROTTLE_START_MS
+                new_throttle_ms = self._delay_before_mail_ms
             else:
                 new_throttle_ms = min(
                     current_throttle_ms * THROTTLE_MULTIPLIER, THROTTLE_MAX_MS