push notifications: Fix exception when handling deleted messages.

If a user deletes message between when it triggered a potential push
notification for another user, and when that notification was actually
sent, we'd end up with a situation where the `Message` table didn't
have an entry for the requested message ID.

The clean fix for this is to still throw an exception in the event
that the message doesn't exist at all, but if it exists in
ArchivedMessage, don't throw a user-facing exception.
This commit is contained in:
Tim Abbott
2018-12-05 10:36:58 -08:00
parent d723dbfef7
commit b47535d8bb
3 changed files with 62 additions and 2 deletions

View File

@@ -400,6 +400,9 @@ def handle_missedmessage_emails(user_profile_id: int,
if not receives_offline_email_notifications(user_profile):
return
# Note: This query structure automatically filters out any
# messages that were permanently deleted, since those would now be
# in the ArchivedMessage table, not the Message table.
messages = Message.objects.filter(usermessage__user_profile_id=user_profile,
id__in=message_ids,
usermessage__flags=~UserMessage.flags.read)