2121 Awaitable ,
2222 Callable ,
2323 Collection ,
24+ Dict ,
2425 List ,
2526 Optional ,
2627 Tuple ,
4243logger = logging .getLogger (__name__ )
4344
4445
45- # A boolean returned value, kept for backwards compatibility but deprecated.
46- DEPRECATED_BOOL = bool
47-
48- # A string returned value, kept for backwards compatibility but deprecated.
49- DEPRECATED_STR = str
50-
5146CHECK_EVENT_FOR_SPAM_CALLBACK = Callable [
5247 ["synapse.events.EventBase" ],
53- Awaitable [Union [Allow , Codes , DEPRECATED_BOOL , DEPRECATED_STR ]],
48+ Awaitable [
49+ Union [
50+ Allow ,
51+ Codes ,
52+ # Highly experimental, not officially part of the spamchecker API, may
53+ # disappear without warning depending on the results of ongoing
54+ # experiments.
55+ # Use this to return additional information as part of an error.
56+ Tuple [Codes , Dict ],
57+ # Deprecated
58+ bool ,
59+ # Deprecated
60+ str ,
61+ ]
62+ ],
5463]
5564USER_MAY_JOIN_ROOM_CALLBACK = Callable [[str , str , bool ], Awaitable [bool ]]
5665USER_MAY_INVITE_CALLBACK = Callable [[str , str , str ], Awaitable [bool ]]
@@ -252,7 +261,7 @@ def register_callbacks(
252261
253262 async def check_event_for_spam (
254263 self , event : "synapse.events.EventBase"
255- ) -> Union [Decision , str ]:
264+ ) -> Union [Decision , Tuple [ Codes , Dict ], str ]:
256265 """Checks if a given event is considered "spammy" by this server.
257266
258267 If the server considers an event spammy, then it will be rejected if
@@ -275,9 +284,9 @@ async def check_event_for_spam(
275284 with Measure (
276285 self .clock , "{}.{}" .format (callback .__module__ , callback .__qualname__ )
277286 ):
278- res : Union [Decision , str , bool ] = await delay_cancellation (
279- callback ( event )
280- )
287+ res : Union [
288+ Decision , Tuple [ Codes , Dict ], str , bool
289+ ] = await delay_cancellation ( callback ( event ) )
281290 if res is False or res is Allow .ALLOW :
282291 # This spam-checker accepts the event.
283292 # Other spam-checkers may reject it, though.
@@ -287,8 +296,9 @@ async def check_event_for_spam(
287296 # return value `True`
288297 return Codes .FORBIDDEN
289298 else :
290- # This spam-checker rejects the event either with a `str`
291- # or with a `Codes`. In either case, we stop here.
299+ # This spam-checker rejects the event either with a `str`,
300+ # with a `Codes` or with a `Tuple[Codes, Dict]`. In either
301+ # case, we stop here.
292302 return res
293303
294304 # No spam-checker has rejected the event, let it pass.
0 commit comments