diff --git a/zerver/lib/notifications.py b/zerver/lib/notifications.py index d11654f2a3..5cd5433d5a 100644 --- a/zerver/lib/notifications.py +++ b/zerver/lib/notifications.py @@ -367,7 +367,11 @@ 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: - messages_by_recipient_subject[(msg.recipient_id, msg.topic_name())].append(msg) + 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 = { recipient_subject: len(msgs) diff --git a/zerver/tests/test_notifications.py b/zerver/tests/test_notifications.py index c180483dec..fe18684680 100644 --- a/zerver/tests/test_notifications.py +++ b/zerver/tests/test_notifications.py @@ -352,3 +352,29 @@ class TestMissedMessages(ZulipTestCase): body = '#Verona 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)