2024-07-12 02:30:25 +02:00
|
|
|
from collections.abc import Iterable, Sequence
|
2022-04-14 23:35:09 +02:00
|
|
|
|
2024-07-30 14:43:40 +02:00
|
|
|
from django.db import transaction
|
|
|
|
|
2022-04-14 23:35:09 +02:00
|
|
|
from zerver.lib.alert_words import add_user_alert_words, remove_user_alert_words
|
|
|
|
from zerver.models import UserProfile
|
2024-07-30 14:43:40 +02:00
|
|
|
from zerver.tornado.django_api import send_event_on_commit
|
2022-04-14 23:35:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
def notify_alert_words(user_profile: UserProfile, words: Sequence[str]) -> None:
|
|
|
|
event = dict(type="alert_words", alert_words=words)
|
2024-07-30 14:43:40 +02:00
|
|
|
send_event_on_commit(user_profile.realm, event, [user_profile.id])
|
2022-04-14 23:35:09 +02:00
|
|
|
|
|
|
|
|
2024-09-03 13:23:08 +02:00
|
|
|
@transaction.atomic(durable=True)
|
2022-04-14 23:35:09 +02:00
|
|
|
def do_add_alert_words(user_profile: UserProfile, alert_words: Iterable[str]) -> None:
|
|
|
|
words = add_user_alert_words(user_profile, alert_words)
|
|
|
|
notify_alert_words(user_profile, words)
|
|
|
|
|
|
|
|
|
2024-09-03 13:23:08 +02:00
|
|
|
@transaction.atomic(durable=True)
|
2022-04-14 23:35:09 +02:00
|
|
|
def do_remove_alert_words(user_profile: UserProfile, alert_words: Iterable[str]) -> None:
|
|
|
|
words = remove_user_alert_words(user_profile, alert_words)
|
|
|
|
notify_alert_words(user_profile, words)
|