mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	notifications: Fix missed message email notifications of welcome bot.
A missed message email notification, where the message is the welcome message sent by the welcome bot on account creation, get sent when the user somehow not focuses the browser tab during account creation. No missed message email or push notifications should be sent for the messages generated by the welcome bot. 'internal_send_private_message' accepts a parameter 'disable_external_notifications' and is set to 'True' when the sender is 'welcome bot'. A check is introduced in `trivially_should_not_notify`, not to notify if `disable_external_notifications` is true. TestCases are updated to include the `disable_external_notifications` check in the early (False) return patterns of `is_push_notifiable` and `is_email_notifiable`. One query reduced for both `test_create_user_with_multiple_streams` and `test_register`. Reason: When welcome bot sends message after user creation `do_send_messages` calls `get_active_presence_idle_user_ids`, `user_ids` in `get_active_presence_idle_user_ids` remains empty if `disable_external_notifications` is true because `is_notifiable` returns false. `get_active_presence_idle_user_ids` calls `filter_presence_idle_user_ids` and since the `user_ids` is empty, the query inside the function doesn't get executed. MissedMessageHookTest updated. Fixes: #22884
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							b40bbd6ca8
						
					
				
				
					commit
					1a400b21e7
				
			@@ -113,6 +113,23 @@ class TestNotificationData(ZulipTestCase):
 | 
			
		||||
        )
 | 
			
		||||
        self.assertFalse(user_data.is_push_notifiable(acting_user_id=acting_user_id, idle=True))
 | 
			
		||||
 | 
			
		||||
        # 'disable_external_notifications' takes precedence over other flags.
 | 
			
		||||
        user_data = self.create_user_notifications_data_object(
 | 
			
		||||
            user_id=user_id,
 | 
			
		||||
            pm_push_notify=True,
 | 
			
		||||
            pm_email_notify=True,
 | 
			
		||||
            mention_push_notify=True,
 | 
			
		||||
            mention_email_notify=True,
 | 
			
		||||
            wildcard_mention_push_notify=True,
 | 
			
		||||
            wildcard_mention_email_notify=True,
 | 
			
		||||
            disable_external_notifications=True,
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            user_data.get_push_notification_trigger(acting_user_id=acting_user_id, idle=True),
 | 
			
		||||
            None,
 | 
			
		||||
        )
 | 
			
		||||
        self.assertFalse(user_data.is_push_notifiable(acting_user_id=acting_user_id, idle=True))
 | 
			
		||||
 | 
			
		||||
    def test_is_email_notifiable(self) -> None:
 | 
			
		||||
        user_id = self.example_user("hamlet").id
 | 
			
		||||
        acting_user_id = self.example_user("cordelia").id
 | 
			
		||||
@@ -209,6 +226,23 @@ class TestNotificationData(ZulipTestCase):
 | 
			
		||||
        )
 | 
			
		||||
        self.assertFalse(user_data.is_email_notifiable(acting_user_id=acting_user_id, idle=True))
 | 
			
		||||
 | 
			
		||||
        # Message sender is the welcome bot.
 | 
			
		||||
        user_data = self.create_user_notifications_data_object(
 | 
			
		||||
            user_id=user_id,
 | 
			
		||||
            pm_push_notify=True,
 | 
			
		||||
            pm_email_notify=True,
 | 
			
		||||
            mention_push_notify=True,
 | 
			
		||||
            mention_email_notify=True,
 | 
			
		||||
            wildcard_mention_push_notify=True,
 | 
			
		||||
            wildcard_mention_email_notify=True,
 | 
			
		||||
            disable_external_notifications=True,
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            user_data.get_email_notification_trigger(acting_user_id=acting_user_id, idle=True),
 | 
			
		||||
            None,
 | 
			
		||||
        )
 | 
			
		||||
        self.assertFalse(user_data.is_email_notifiable(acting_user_id=acting_user_id, idle=True))
 | 
			
		||||
 | 
			
		||||
    def test_is_notifiable(self) -> None:
 | 
			
		||||
        # This is just for coverage purposes. We've already tested all scenarios above,
 | 
			
		||||
        # and `is_notifiable` is a simple OR of the email and push functions.
 | 
			
		||||
@@ -224,6 +258,7 @@ class TestNotificationData(ZulipTestCase):
 | 
			
		||||
                user_id=user_id,
 | 
			
		||||
                flags=["mentioned"],
 | 
			
		||||
                private_message=True,
 | 
			
		||||
                disable_external_notifications=False,
 | 
			
		||||
                online_push_user_ids=set(),
 | 
			
		||||
                pm_mention_email_disabled_user_ids=set(),
 | 
			
		||||
                pm_mention_push_disabled_user_ids=set(),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user