mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 19:06:09 +00:00
alert words: Refactor alert word detection.
The bugdown parser no longer has a concept of which users need which alert words, since it can't really do anything actionable with that info from a rendering standpoint. Instead, our calling code passes in a set of search words to the parser. The parser returns the list of words it finds in the message. Then the model method builds up the list of user ids that should be flagged as having alert words in the message. This refactoring is a little more involved than I'd like, but there are still some circular dependency issues with rendering code, so I need to pass in the rather complicated realm_alert_words data structure all the way from the action through the model to the renderer. This change shouldn't change the overall behavior of the system, except that it does remove some duplicate regex checks that were occurring when multiple users may have had the same alert word.
This commit is contained in:
@@ -25,6 +25,7 @@ from zerver.models import Realm, RealmEmoji, Stream, UserProfile, UserActivity,
|
||||
ScheduledJob, realm_filters_for_domain, get_owned_bot_dicts, \
|
||||
get_old_unclaimed_attachments, get_cross_realm_users
|
||||
|
||||
from zerver.lib.alert_words import alert_words_in_realm
|
||||
from zerver.lib.avatar import get_avatar_url, avatar_url
|
||||
|
||||
from django.db import transaction, IntegrityError
|
||||
@@ -629,8 +630,12 @@ def do_send_message(message, rendered_content = None, no_log = False, stream = N
|
||||
|
||||
def render_incoming_message(message, content):
|
||||
# type: (Message, text_type) -> text_type
|
||||
realm_alert_words = alert_words_in_realm(message.get_realm())
|
||||
try:
|
||||
rendered_content = message.render_markdown(content)
|
||||
rendered_content = message.render_markdown(
|
||||
content=content,
|
||||
realm_alert_words=realm_alert_words,
|
||||
)
|
||||
except BugdownRenderingException:
|
||||
raise JsonableError(_('Unable to render message'))
|
||||
return rendered_content
|
||||
|
||||
Reference in New Issue
Block a user