notifications: Fix sending push notifications on muted streams.

Apparently, the stream muting feature did not take priority over the
stream_push_notify feature.  This fixes that gap.

Fixes zulip/zulip-mobile#1314.
This commit is contained in:
Tim Abbott
2017-10-17 22:38:54 -07:00
parent 31ce96ff2a
commit 024c27dd3e
2 changed files with 24 additions and 3 deletions

View File

@@ -782,6 +782,7 @@ def get_recipient_info(recipient, sender_id):
).values(
'user_profile_id',
'push_notifications',
'in_home_view',
).order_by('user_profile_id')
user_ids = [
row['user_profile_id']
@@ -790,7 +791,8 @@ def get_recipient_info(recipient, sender_id):
stream_push_user_ids = {
row['user_profile_id']
for row in subscription_rows
if row['push_notifications']
# Note: muting a stream overrides stream_push_notify
if row['push_notifications'] and row['in_home_view']
}
elif recipient.type == Recipient.HUDDLE:

View File

@@ -204,6 +204,25 @@ class MissedMessageNotificationsTest(ZulipTestCase):
True, "Denmark", False, True,
{'email_notified': False, 'push_notified': False}))
# Clean up the state
sub.push_notifications = True
# Clear the event queue, now repeat with stream message with stream_push_notify
# on a muted stream, which we should not push notify for
client_descriptor.event_queue.pop()
self.assertTrue(client_descriptor.event_queue.empty())
sub.in_home_view = False
sub.save()
msg_id = self.send_message(self.example_email("iago"), "Denmark", Recipient.STREAM,
content="what's up everyone?")
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
# Clear the event queue, before repeating with a private message
missedmessage_hook(user_profile.id, client_descriptor, True)
mock_enqueue.assert_called_once()
args_list = mock_enqueue.call_args_list[0][0]
self.assertEqual(args_list, (user_profile.id, msg_id, False, False,
False, "Denmark", False, True,
{'email_notified': False, 'push_notified': False}))
# Clean up the state we just changed (not necessary unless we add more test code below)
sub.push_notifications = True
sub.in_home_view = True
sub.save()