email_notification: Include prior message context only when mentioned.

Earlier, email message notifications included prior messages sent
to the same topic for context. This is more confusing than helpful
for messages that the user is likely to have received notifications
for all the prior messages in the conversation already (or read them
in the Zulip UI).

Now, we include prior context only when the user is mentioned via
personal, group, stream or topic wildcard mention.

Fixes #27479.
This commit is contained in:
Prakhar Pratyush
2023-11-04 18:35:38 +05:30
committed by Tim Abbott
parent c0f445294c
commit 94679d590f
3 changed files with 91 additions and 21 deletions

View File

@@ -3662,6 +3662,20 @@ class UserMessage(AbstractUserMessage):
"""
return UserMessage.objects.select_for_update().order_by("message_id")
@staticmethod
def has_any_mentions(user_profile_id: int, message_id: int) -> bool:
# The query uses the 'zerver_usermessage_any_mentioned_message_id' index.
return UserMessage.objects.filter(
Q(
flags__andnz=UserMessage.flags.mentioned.mask
| UserMessage.flags.wildcard_mentioned.mask
| UserMessage.flags.topic_wildcard_mentioned.mask
| UserMessage.flags.group_mentioned.mask
),
user_profile_id=user_profile_id,
message_id=message_id,
).exists()
def get_usermessage_by_message_id(
user_profile: UserProfile, message_id: int