Uniformize spam-checker API, part 3: Expand check_event_for_spam with the ability to return additional fields (#12846)

Signed-off-by: David Teller <davidt@element.io>
This commit is contained in:
David Teller 2022-05-30 18:24:56 +02:00 committed by GitHub
parent 1fd1856afc
commit af7db19e1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 17 deletions

View file

@ -895,6 +895,21 @@ class EventCreationHandler:
spam_check = await self.spam_checker.check_event_for_spam(event)
if spam_check is not synapse.spam_checker_api.Allow.ALLOW:
if isinstance(spam_check, tuple):
try:
[code, dict] = spam_check
raise SynapseError(
403,
"This message had been rejected as probable spam",
code,
dict,
)
except ValueError:
logger.error(
"Spam-check module returned invalid error value. Expecting [code, dict], got %s",
spam_check,
)
spam_check = Codes.FORBIDDEN
raise SynapseError(
403, "This message had been rejected as probable spam", spam_check
)