summary refs log tree commit diff
path: root/synapse/handlers/message.py
diff options
context:
space:
mode:
authorBrendan Abolivier <babolivier@matrix.org>2022-05-31 12:04:53 +0200
committerGitHub <noreply@github.com>2022-05-31 12:04:53 +0200
commit8fd87739bf9653a77fff9669d4f307e8b1bcd1eb (patch)
treef0b209980fdb2c0818320b7e91ba0a7a95530e5c /synapse/handlers/message.py
parent1.60.0rc2 (diff)
downloadsynapse-8fd87739bf9653a77fff9669d4f307e8b1bcd1eb.tar.xz
Fix import in module_api module and docs on the new check_event_for_spam signature (#12918)
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Diffstat (limited to 'synapse/handlers/message.py')
-rw-r--r--synapse/handlers/message.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index cb1bc4c06f..22cdad3f33 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -23,7 +23,6 @@ from canonicaljson import encode_canonical_json
 
 from twisted.internet.interfaces import IDelayedCall
 
-import synapse
 from synapse import event_auth
 from synapse.api.constants import (
     EventContentFields,
@@ -886,10 +885,22 @@ class EventCreationHandler:
                 event.sender,
             )
 
-            spam_check = await self.spam_checker.check_event_for_spam(event)
-            if spam_check is not synapse.spam_checker_api.Allow.ALLOW:
+            spam_check_result = await self.spam_checker.check_event_for_spam(event)
+            if spam_check_result != self.spam_checker.NOT_SPAM:
+                if isinstance(spam_check_result, Codes):
+                    raise SynapseError(
+                        403,
+                        "This message has been rejected as probable spam",
+                        spam_check_result,
+                    )
+
+                # Backwards compatibility: if the return value is not an error code, it
+                # means the module returned an error message to be included in the
+                # SynapseError (which is now deprecated).
                 raise SynapseError(
-                    403, "This message had been rejected as probable spam", spam_check
+                    403,
+                    spam_check_result,
+                    Codes.FORBIDDEN,
                 )
 
             ev = await self.handle_new_client_event(