summary refs log tree commit diff
path: root/synapse/server_notices
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/server_notices')
-rw-r--r--synapse/server_notices/consent_server_notices.py3
-rw-r--r--synapse/server_notices/resource_limits_server_notices.py21
-rw-r--r--synapse/server_notices/server_notices_manager.py4
3 files changed, 20 insertions, 8 deletions
diff --git a/synapse/server_notices/consent_server_notices.py b/synapse/server_notices/consent_server_notices.py
index 5e3044d164..6d5caedb08 100644
--- a/synapse/server_notices/consent_server_notices.py
+++ b/synapse/server_notices/consent_server_notices.py
@@ -22,6 +22,7 @@ from synapse.api.errors import SynapseError
 from synapse.api.urls import ConsentURIBuilder
 from synapse.config import ConfigError
 from synapse.types import get_localpart_from_id
+from synapse.api.constants import EventTypes
 
 logger = logging.getLogger(__name__)
 
@@ -103,7 +104,7 @@ class ConsentServerNotices(object):
                     },
                 )
                 yield self._server_notices_manager.send_notice(
-                    user_id, content,
+                    user_id, content, EventTypes.Message
                 )
                 yield self._store.user_set_consent_server_notice_sent(
                     user_id, self._current_consent_version,
diff --git a/synapse/server_notices/resource_limits_server_notices.py b/synapse/server_notices/resource_limits_server_notices.py
index e4be836439..2f49dae168 100644
--- a/synapse/server_notices/resource_limits_server_notices.py
+++ b/synapse/server_notices/resource_limits_server_notices.py
@@ -17,6 +17,7 @@ import logging
 from twisted.internet import defer
 
 from synapse.api.errors import AuthError, SynapseError
+from synapse.api.constants import EventTypes
 
 logger = logging.getLogger(__name__)
 
@@ -61,22 +62,32 @@ class ResourceLimitsServerNotices(object):
                 # In practice, not sure we can ever get here
                 return
             try:
+                # 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.
                 yield self.auth.check_auth_blocking()
                 self._resouce_limited = False
                 # Need to start removing notices
                 if user_id in self._notified_of_blocking:
                     # Send message to remove warning - needs updating
-                    content = "remove warning"
+                    content = {
+                        'body': '',
+                        'admin_email': '',
+                    }
                     self._send_server_notice(user_id, content)
                     self._notified_of_blocking.remove(user_id)
 
-            except AuthError:
+            except AuthError as e:
                 # Need to start notifying of blocking
 
                 self._resouce_limited = True
                 if user_id not in self._notified_of_blocking:
-                    # Send message to add warning - needs updating
-                    content = "add warning"
+                    # TODO use admin email contained in error once PR lands
+                    content = {
+                        'body': e.msg,
+                        'admin_email': 'stunt@adminemail.com',
+                        'msgtype': 'm.text'
+                    }
                     self._send_server_notice(user_id, content)
                     self._notified_of_blocking.add(user_id)
 
@@ -93,7 +104,7 @@ class ResourceLimitsServerNotices(object):
         """
         try:
             yield self._server_notices_manager.send_notice(
-                user_id, content,
+                user_id, content, EventTypes.ServerNoticeLimitReached
             )
         except SynapseError as e:
             logger.error("Error sending server notice about resource limits: %s", e)
diff --git a/synapse/server_notices/server_notices_manager.py b/synapse/server_notices/server_notices_manager.py
index a26deace53..4806977a89 100644
--- a/synapse/server_notices/server_notices_manager.py
+++ b/synapse/server_notices/server_notices_manager.py
@@ -46,7 +46,7 @@ class ServerNoticesManager(object):
         return self._config.server_notices_mxid is not None
 
     @defer.inlineCallbacks
-    def send_notice(self, user_id, event_content):
+    def send_notice(self, user_id, event_content, type):
         """Send a notice to the given user
 
         Creates the server notices room, if none exists.
@@ -67,7 +67,7 @@ class ServerNoticesManager(object):
 
         yield self._event_creation_handler.create_and_send_nonmember_event(
             requester, {
-                "type": EventTypes.Message,
+                "type": type,
                 "room_id": room_id,
                 "sender": system_mxid,
                 "content": event_content,