mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
push_notifications: Skip enqueuing notif for users without push devices.
Previously, we enqueued events to "missedmessage_mobile_notifications" even for users who had no registered push devices. 'handle_push_notification' later used to perform the check & skip if there were no registered devices. This commit avoids putting such events into the "missedmessage_mobile_notifications" queue at all. By doing so, we reduce unnecessary churn.
This commit is contained in:
committed by
Tim Abbott
parent
aa317ee844
commit
421637ce31
@@ -16,7 +16,7 @@ from zerver.actions.user_topics import do_set_user_topic_visibility_policy
|
||||
from zerver.lib.cache import cache_delete, get_muting_users_cache_key
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.lib.test_helpers import HostRequestMock, dummy_handler, mock_queue_publish
|
||||
from zerver.models import Recipient, Subscription, UserProfile, UserTopic
|
||||
from zerver.models import PushDevice, Recipient, Subscription, UserProfile, UserTopic
|
||||
from zerver.models.streams import get_stream
|
||||
from zerver.tornado.event_queue import (
|
||||
ClientDescriptor,
|
||||
@@ -194,6 +194,7 @@ class MissedMessageHookTest(ZulipTestCase):
|
||||
do_change_user_setting(
|
||||
self.user_profile, "enable_online_push_notifications", False, acting_user=None
|
||||
)
|
||||
self.register_push_device(self.user_profile.id)
|
||||
self.iago = self.example_user("iago")
|
||||
self.client_descriptor = self.allocate_event_queue(self.user_profile)
|
||||
self.assertTrue(self.client_descriptor.event_queue.empty())
|
||||
@@ -306,6 +307,28 @@ class MissedMessageHookTest(ZulipTestCase):
|
||||
already_notified={"email_notified": True, "push_notified": False},
|
||||
)
|
||||
|
||||
def test_no_push_device_registered(self) -> None:
|
||||
# When `enable_offline_push_notifications` is `true` but no push device registered,
|
||||
# push notifications should not be sent.
|
||||
do_change_user_setting(
|
||||
self.user_profile, "enable_offline_push_notifications", True, acting_user=None
|
||||
)
|
||||
PushDevice.objects.all().delete()
|
||||
msg_id = self.send_personal_message(self.iago, self.user_profile)
|
||||
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
|
||||
missedmessage_hook(self.user_profile.id, self.client_descriptor, True)
|
||||
mock_enqueue.assert_called_once()
|
||||
args_dict = mock_enqueue.call_args_list[0][1]
|
||||
|
||||
self.assert_maybe_enqueue_notifications_call_args(
|
||||
args_dict=args_dict,
|
||||
message_id=msg_id,
|
||||
user_id=self.user_profile.id,
|
||||
dm_email_notify=True,
|
||||
dm_push_notify=False,
|
||||
already_notified={"email_notified": True, "push_notified": False},
|
||||
)
|
||||
|
||||
def test_topic_wildcard_mention(self) -> None:
|
||||
# By default, topic wildcard mentions should send notifications, just like regular mentions
|
||||
self.send_stream_message(self.user_profile, "Denmark")
|
||||
|
||||
Reference in New Issue
Block a user