notifications: Group messages by (recipient, sender) for PM's.

This fixes a issue with multiple PM's being clubbed into a single
missed message email.

Fixes #6224.
This commit is contained in:
Aditya Bansal
2017-08-25 07:45:05 +05:30
committed by Tim Abbott
parent 0693656b89
commit 6a2c83f051
2 changed files with 31 additions and 1 deletions

View File

@@ -367,6 +367,10 @@ def handle_missedmessage_emails(user_profile_id, missed_email_events):
messages_by_recipient_subject = defaultdict(list) # type: Dict[Tuple[int, Text], List[Message]]
for msg in messages:
if msg.recipient.type == Recipient.PERSONAL:
# For PM's group using (recipient, sender).
messages_by_recipient_subject[(msg.recipient_id, msg.sender_id)].append(msg)
else:
messages_by_recipient_subject[(msg.recipient_id, msg.topic_name())].append(msg)
message_count_by_recipient_subject = {

View File

@@ -352,3 +352,29 @@ class TestMissedMessages(ZulipTestCase):
body = '<a class="stream" data-stream-id="5" href="http://testserver/#narrow/stream/Verona">#Verona</a'
subject = 'Othello, the Moor of Venice sent you a message'
self._test_cases(tokens, msg_id, body, subject, send_as_user=False, verify_html_body=True)
@patch('zerver.lib.email_mirror.generate_random_token')
def test_multiple_missed_personal_messages(self, mock_random_token):
# type: (MagicMock) -> None
tokens = self._get_tokens()
mock_random_token.side_effect = tokens
hamlet = self.example_user('hamlet')
msg_id_1 = self.send_message(self.example_email('othello'),
hamlet.email,
Recipient.PERSONAL,
'Personal Message 1')
msg_id_2 = self.send_message(self.example_email('iago'),
hamlet.email,
Recipient.PERSONAL,
'Personal Message 2')
handle_missedmessage_emails(hamlet.id, [
{'message_id': msg_id_1},
{'message_id': msg_id_2},
])
self.assertEqual(len(mail.outbox), 2)
subject = 'Iago sent you a message'
self.assertEqual(mail.outbox[0].subject, subject)
subject = 'Othello, the Moor of Venice sent you a message'
self.assertEqual(mail.outbox[1].subject, subject)