summary refs log tree commit diff
diff options
context:
space:
mode:
authorNeil Johnson <neil@matrix.org>2019-10-04 17:53:45 +0100
committerNeil Johnson <neil@matrix.org>2019-10-04 17:53:45 +0100
commit11ccbc657618c37678b93264a17c4226d801efd3 (patch)
tree0e57755f48bea386aa87aa6d5f9c4ea92fb0974b
parentMerge pull request #6147 from matrix-org/babolivier/3pid-invite-revoked (diff)
downloadsynapse-11ccbc657618c37678b93264a17c4226d801efd3.tar.xz
wip commit to suppress mau alerting for small instances
-rw-r--r--synapse/config/server.py8
-rw-r--r--synapse/server_notices/resource_limits_server_notices.py12
2 files changed, 20 insertions, 0 deletions
diff --git a/synapse/config/server.py b/synapse/config/server.py
index 709bd387e5..9df21b4acb 100644
--- a/synapse/config/server.py
+++ b/synapse/config/server.py
@@ -169,6 +169,7 @@ class ServerConfig(Config):
         )
 
         self.mau_trial_days = config.get("mau_trial_days", 0)
+        self.mau_alerting_threshold = config.get('mau_alerting_threshold', 0)
 
         # How long to keep redacted events in the database in unredacted form
         # before redacting them.
@@ -693,9 +694,16 @@ class ServerConfig(Config):
         # sign up in a short space of time never to return after their initial
         # session.
         #
+        # 'mau_alerting_threshold' is a means of limiting client side alerting
+        # should the mau limit be reached. This is useful for small instances
+        # where the admin has 5 mau seats (say) for 5 specific people and no
+        # interest increasing the mau limit further. Defaults to 0 which denotes
+        # that the option is disabled.
+        #
         #limit_usage_by_mau: False
         #max_mau_value: 50
         #mau_trial_days: 2
+        #mau_alerting_threshold: 10
 
         # If enabled, the metrics for the number of monthly active users will
         # be populated, however no one will be limited. If limit_usage_by_mau
diff --git a/synapse/server_notices/resource_limits_server_notices.py b/synapse/server_notices/resource_limits_server_notices.py
index 81c4aff496..57228e0caa 100644
--- a/synapse/server_notices/resource_limits_server_notices.py
+++ b/synapse/server_notices/resource_limits_server_notices.py
@@ -91,6 +91,18 @@ class ResourceLimitsServerNotices(object):
         currently_blocked, ref_events = yield self._is_room_currently_blocked(room_id)
 
         try:
+            if (
+                self._config.mau_alerting_threshold > 0
+                and self._config.mau_alerting_threshold > self._config.max_mau_value
+            ):
+                # Alerting disabled, reset room if necessary and return
+                if currently_blocked:
+                    content = {"pinned": ref_events}
+                    yield self._server_notices_manager.send_notice(
+                        user_id, content, EventTypes.Pinned, ""
+                    )
+                return
+
             # Normally should always pass in user_id if you have it, but in
             # this case are checking what would happen to other users if they
             # were to arrive.