13
13
# See the License for the specific language governing permissions and
14
14
# limitations under the License.
15
15
import logging
16
+ from typing import List , Tuple
16
17
17
18
from synapse .api .constants import (
18
19
EventTypes ,
@@ -52,18 +53,15 @@ def __init__(self, hs):
52
53
and not hs .config .hs_disabled
53
54
)
54
55
55
- async def maybe_send_server_notice_to_user (self , user_id ) :
56
+ async def maybe_send_server_notice_to_user (self , user_id : str ) -> None :
56
57
"""Check if we need to send a notice to this user, this will be true in
57
58
two cases.
58
59
1. The server has reached its limit does not reflect this
59
60
2. The room state indicates that the server has reached its limit when
60
61
actually the server is fine
61
62
62
63
Args:
63
- user_id (str): user to check
64
-
65
- Returns:
66
- Deferred
64
+ user_id: user to check
67
65
"""
68
66
if not self ._enabled :
69
67
return
@@ -115,36 +113,38 @@ async def maybe_send_server_notice_to_user(self, user_id):
115
113
elif not currently_blocked and limit_msg :
116
114
# Room is not notifying of a block, when it ought to be.
117
115
await self ._apply_limit_block_notification (
118
- user_id , limit_msg , limit_type
116
+ user_id , limit_msg , limit_type # type: ignore
119
117
)
120
118
except SynapseError as e :
121
119
logger .error ("Error sending resource limits server notice: %s" , e )
122
120
123
- async def _remove_limit_block_notification (self , user_id , ref_events ):
121
+ async def _remove_limit_block_notification (
122
+ self , user_id : str , ref_events : List [str ]
123
+ ) -> None :
124
124
"""Utility method to remove limit block notifications from the server
125
125
notices room.
126
126
127
127
Args:
128
- user_id (str) : user to notify
129
- ref_events (list[str]) : The event_ids of pinned events that are unrelated to
130
- limit blocking and need to be preserved.
128
+ user_id: user to notify
129
+ ref_events: The event_ids of pinned events that are unrelated to
130
+ limit blocking and need to be preserved.
131
131
"""
132
132
content = {"pinned" : ref_events }
133
133
await self ._server_notices_manager .send_notice (
134
134
user_id , content , EventTypes .Pinned , ""
135
135
)
136
136
137
137
async def _apply_limit_block_notification (
138
- self , user_id , event_body , event_limit_type
139
- ):
138
+ self , user_id : str , event_body : str , event_limit_type : str
139
+ ) -> None :
140
140
"""Utility method to apply limit block notifications in the server
141
141
notices room.
142
142
143
143
Args:
144
- user_id (str) : user to notify
145
- event_body(str) : The human readable text that describes the block.
146
- event_limit_type(str) : Specifies the type of block e.g. monthly active user
147
- limit has been exceeded.
144
+ user_id: user to notify
145
+ event_body: The human readable text that describes the block.
146
+ event_limit_type: Specifies the type of block e.g. monthly active user
147
+ limit has been exceeded.
148
148
"""
149
149
content = {
150
150
"body" : event_body ,
@@ -162,7 +162,7 @@ async def _apply_limit_block_notification(
162
162
user_id , content , EventTypes .Pinned , ""
163
163
)
164
164
165
- async def _check_and_set_tags (self , user_id , room_id ) :
165
+ async def _check_and_set_tags (self , user_id : str , room_id : str ) -> None :
166
166
"""
167
167
Since server notices rooms were originally not with tags,
168
168
important to check that tags have been set correctly
@@ -182,17 +182,16 @@ async def _check_and_set_tags(self, user_id, room_id):
182
182
)
183
183
self ._notifier .on_new_event ("account_data_key" , max_id , users = [user_id ])
184
184
185
- async def _is_room_currently_blocked (self , room_id ) :
185
+ async def _is_room_currently_blocked (self , room_id : str ) -> Tuple [ bool , List [ str ]] :
186
186
"""
187
187
Determines if the room is currently blocked
188
188
189
189
Args:
190
- room_id(str) : The room id of the server notices room
190
+ room_id: The room id of the server notices room
191
191
192
192
Returns:
193
- Deferred[Tuple[bool, List]]:
194
193
bool: Is the room currently blocked
195
- list: The list of pinned events that are unrelated to limit blocking
194
+ list: The list of pinned event IDs that are unrelated to limit blocking
196
195
This list can be used as a convenience in the case where the block
197
196
is to be lifted and the remaining pinned event references need to be
198
197
preserved
@@ -207,7 +206,7 @@ async def _is_room_currently_blocked(self, room_id):
207
206
# The user has yet to join the server notices room
208
207
pass
209
208
210
- referenced_events = []
209
+ referenced_events = [] # type: List[str]
211
210
if pinned_state_event is not None :
212
211
referenced_events = list (pinned_state_event .content .get ("pinned" , []))
213
212
0 commit comments