summary refs log tree commit diff
path: root/synapse/server_notices
diff options
context:
space:
mode:
authorAmber Brown <hawkowl@atleastfornow.net>2019-06-20 19:32:02 +1000
committerGitHub <noreply@github.com>2019-06-20 19:32:02 +1000
commit32e7c9e7f20b57dd081023ac42d6931a8da9b3a3 (patch)
tree139ef30c957535699d1ae0474e8b5ba2517196b2 /synapse/server_notices
parentMerge pull request #5042 from matrix-org/erikj/fix_get_missing_events_error (diff)
downloadsynapse-32e7c9e7f20b57dd081023ac42d6931a8da9b3a3.tar.xz
Run Black. (#5482)
Diffstat (limited to 'synapse/server_notices')
-rw-r--r--synapse/server_notices/consent_server_notices.py24
-rw-r--r--synapse/server_notices/resource_limits_server_notices.py33
-rw-r--r--synapse/server_notices/server_notices_manager.py30
-rw-r--r--synapse/server_notices/server_notices_sender.py11
-rw-r--r--synapse/server_notices/worker_server_notices_sender.py1
5 files changed, 39 insertions, 60 deletions
diff --git a/synapse/server_notices/consent_server_notices.py b/synapse/server_notices/consent_server_notices.py
index 5e3044d164..415e9c17d8 100644
--- a/synapse/server_notices/consent_server_notices.py
+++ b/synapse/server_notices/consent_server_notices.py
@@ -30,6 +30,7 @@ class ConsentServerNotices(object):
     """Keeps track of whether we need to send users server_notices about
     privacy policy consent, and sends one if we do.
     """
+
     def __init__(self, hs):
         """
 
@@ -49,12 +50,11 @@ class ConsentServerNotices(object):
             if not self._server_notices_manager.is_enabled():
                 raise ConfigError(
                     "user_consent configuration requires server notices, but "
-                    "server notices are not enabled.",
+                    "server notices are not enabled."
                 )
-            if 'body' not in self._server_notice_content:
+            if "body" not in self._server_notice_content:
                 raise ConfigError(
-                    "user_consent server_notice_consent must contain a 'body' "
-                    "key.",
+                    "user_consent server_notice_consent must contain a 'body' " "key."
                 )
 
             self._consent_uri_builder = ConsentURIBuilder(hs.config)
@@ -95,18 +95,14 @@ class ConsentServerNotices(object):
             # need to send a message.
             try:
                 consent_uri = self._consent_uri_builder.build_user_consent_uri(
-                    get_localpart_from_id(user_id),
+                    get_localpart_from_id(user_id)
                 )
                 content = copy_with_str_subst(
-                    self._server_notice_content, {
-                        'consent_uri': consent_uri,
-                    },
-                )
-                yield self._server_notices_manager.send_notice(
-                    user_id, content,
+                    self._server_notice_content, {"consent_uri": consent_uri}
                 )
+                yield self._server_notices_manager.send_notice(user_id, content)
                 yield self._store.user_set_consent_server_notice_sent(
-                    user_id, self._current_consent_version,
+                    user_id, self._current_consent_version
                 )
             except SynapseError as e:
                 logger.error("Error sending server notice about user consent: %s", e)
@@ -128,9 +124,7 @@ def copy_with_str_subst(x, substitutions):
     if isinstance(x, string_types):
         return x % substitutions
     if isinstance(x, dict):
-        return {
-            k: copy_with_str_subst(v, substitutions) for (k, v) in iteritems(x)
-        }
+        return {k: copy_with_str_subst(v, substitutions) for (k, v) in iteritems(x)}
     if isinstance(x, (list, tuple)):
         return [copy_with_str_subst(y) for y in x]
 
diff --git a/synapse/server_notices/resource_limits_server_notices.py b/synapse/server_notices/resource_limits_server_notices.py
index af15cba0ee..f183743f31 100644
--- a/synapse/server_notices/resource_limits_server_notices.py
+++ b/synapse/server_notices/resource_limits_server_notices.py
@@ -33,6 +33,7 @@ class ResourceLimitsServerNotices(object):
     """ Keeps track of whether the server has reached it's resource limit and
     ensures that the client is kept up to date.
     """
+
     def __init__(self, hs):
         """
         Args:
@@ -104,34 +105,28 @@ class ResourceLimitsServerNotices(object):
             if currently_blocked and not is_auth_blocking:
                 # Room is notifying of a block, when it ought not to be.
                 # Remove block notification
-                content = {
-                    "pinned": ref_events
-                }
+                content = {"pinned": ref_events}
                 yield self._server_notices_manager.send_notice(
-                    user_id, content, EventTypes.Pinned, '',
+                    user_id, content, EventTypes.Pinned, ""
                 )
 
             elif not currently_blocked and is_auth_blocking:
                 # Room is not notifying of a block, when it ought to be.
                 # Add block notification
                 content = {
-                    'body': event_content,
-                    'msgtype': ServerNoticeMsgType,
-                    'server_notice_type': ServerNoticeLimitReached,
-                    'admin_contact': self._config.admin_contact,
-                    'limit_type': event_limit_type
+                    "body": event_content,
+                    "msgtype": ServerNoticeMsgType,
+                    "server_notice_type": ServerNoticeLimitReached,
+                    "admin_contact": self._config.admin_contact,
+                    "limit_type": event_limit_type,
                 }
                 event = yield self._server_notices_manager.send_notice(
-                    user_id, content, EventTypes.Message,
+                    user_id, content, EventTypes.Message
                 )
 
-                content = {
-                    "pinned": [
-                        event.event_id,
-                    ]
-                }
+                content = {"pinned": [event.event_id]}
                 yield self._server_notices_manager.send_notice(
-                    user_id, content, EventTypes.Pinned, '',
+                    user_id, content, EventTypes.Pinned, ""
                 )
 
         except SynapseError as e:
@@ -156,9 +151,7 @@ class ResourceLimitsServerNotices(object):
             max_id = yield self._store.add_tag_to_room(
                 user_id, room_id, SERVER_NOTICE_ROOM_TAG, {}
             )
-            self._notifier.on_new_event(
-                "account_data_key", max_id, users=[user_id]
-            )
+            self._notifier.on_new_event("account_data_key", max_id, users=[user_id])
 
     @defer.inlineCallbacks
     def _is_room_currently_blocked(self, room_id):
@@ -188,7 +181,7 @@ class ResourceLimitsServerNotices(object):
 
         referenced_events = []
         if pinned_state_event is not None:
-            referenced_events = list(pinned_state_event.content.get('pinned', []))
+            referenced_events = list(pinned_state_event.content.get("pinned", []))
 
         events = yield self._store.get_events(referenced_events)
         for event_id, event in iteritems(events):
diff --git a/synapse/server_notices/server_notices_manager.py b/synapse/server_notices/server_notices_manager.py
index c5cc6d728e..71e7e75320 100644
--- a/synapse/server_notices/server_notices_manager.py
+++ b/synapse/server_notices/server_notices_manager.py
@@ -51,8 +51,7 @@ class ServerNoticesManager(object):
 
     @defer.inlineCallbacks
     def send_notice(
-        self, user_id, event_content,
-        type=EventTypes.Message, state_key=None
+        self, user_id, event_content, type=EventTypes.Message, state_key=None
     ):
         """Send a notice to the given user
 
@@ -82,10 +81,10 @@ class ServerNoticesManager(object):
         }
 
         if state_key is not None:
-            event_dict['state_key'] = state_key
+            event_dict["state_key"] = state_key
 
         res = yield self._event_creation_handler.create_and_send_nonmember_event(
-            requester, event_dict, ratelimit=False,
+            requester, event_dict, ratelimit=False
         )
         defer.returnValue(res)
 
@@ -104,11 +103,10 @@ class ServerNoticesManager(object):
         if not self.is_enabled():
             raise Exception("Server notices not enabled")
 
-        assert self._is_mine_id(user_id), \
-            "Cannot send server notices to remote users"
+        assert self._is_mine_id(user_id), "Cannot send server notices to remote users"
 
         rooms = yield self._store.get_rooms_for_user_where_membership_is(
-            user_id, [Membership.INVITE, Membership.JOIN],
+            user_id, [Membership.INVITE, Membership.JOIN]
         )
         system_mxid = self._config.server_notices_mxid
         for room in rooms:
@@ -132,8 +130,8 @@ class ServerNoticesManager(object):
         # avatar, we have to use both.
         join_profile = None
         if (
-            self._config.server_notices_mxid_display_name is not None or
-            self._config.server_notices_mxid_avatar_url is not None
+            self._config.server_notices_mxid_display_name is not None
+            or self._config.server_notices_mxid_avatar_url is not None
         ):
             join_profile = {
                 "displayname": self._config.server_notices_mxid_display_name,
@@ -146,22 +144,18 @@ class ServerNoticesManager(object):
             config={
                 "preset": RoomCreationPreset.PRIVATE_CHAT,
                 "name": self._config.server_notices_room_name,
-                "power_level_content_override": {
-                    "users_default": -10,
-                },
-                "invite": (user_id,)
+                "power_level_content_override": {"users_default": -10},
+                "invite": (user_id,),
             },
             ratelimit=False,
             creator_join_profile=join_profile,
         )
-        room_id = info['room_id']
+        room_id = info["room_id"]
 
         max_id = yield self._store.add_tag_to_room(
-            user_id, room_id, SERVER_NOTICE_ROOM_TAG, {},
-        )
-        self._notifier.on_new_event(
-            "account_data_key", max_id, users=[user_id]
+            user_id, room_id, SERVER_NOTICE_ROOM_TAG, {}
         )
+        self._notifier.on_new_event("account_data_key", max_id, users=[user_id])
 
         logger.info("Created server notices room %s for %s", room_id, user_id)
         defer.returnValue(room_id)
diff --git a/synapse/server_notices/server_notices_sender.py b/synapse/server_notices/server_notices_sender.py
index 6121b2f267..652bab58e3 100644
--- a/synapse/server_notices/server_notices_sender.py
+++ b/synapse/server_notices/server_notices_sender.py
@@ -24,6 +24,7 @@ class ServerNoticesSender(object):
     """A centralised place which sends server notices automatically when
     Certain Events take place
     """
+
     def __init__(self, hs):
         """
 
@@ -32,7 +33,7 @@ class ServerNoticesSender(object):
         """
         self._server_notices = (
             ConsentServerNotices(hs),
-            ResourceLimitsServerNotices(hs)
+            ResourceLimitsServerNotices(hs),
         )
 
     @defer.inlineCallbacks
@@ -43,9 +44,7 @@ class ServerNoticesSender(object):
             user_id (str): mxid of user who synced
         """
         for sn in self._server_notices:
-            yield sn.maybe_send_server_notice_to_user(
-                user_id,
-            )
+            yield sn.maybe_send_server_notice_to_user(user_id)
 
     @defer.inlineCallbacks
     def on_user_ip(self, user_id):
@@ -58,6 +57,4 @@ class ServerNoticesSender(object):
         # we check for notices to send to the user in on_user_ip as well as
         # in on_user_syncing
         for sn in self._server_notices:
-            yield sn.maybe_send_server_notice_to_user(
-                user_id,
-            )
+            yield sn.maybe_send_server_notice_to_user(user_id)
diff --git a/synapse/server_notices/worker_server_notices_sender.py b/synapse/server_notices/worker_server_notices_sender.py
index 4a133026c3..245ec7c64f 100644
--- a/synapse/server_notices/worker_server_notices_sender.py
+++ b/synapse/server_notices/worker_server_notices_sender.py
@@ -17,6 +17,7 @@ from twisted.internet import defer
 
 class WorkerServerNoticesSender(object):
     """Stub impl of ServerNoticesSender which does nothing"""
+
     def __init__(self, hs):
         """
         Args: