mirror of https://github.com/zulip/zulip.git
message_edit: Filter UserMessage better, now that mentions are unneeded.
The previous commit removed the need for `render_incoming_message` to take a list of mentioned users; simplify the callsites accordingly.
This commit is contained in:
parent
cd9c69cd12
commit
21e80e47bd
|
@ -3,6 +3,7 @@ from typing import Any, Dict, Iterable, List, Optional, Set, TypedDict
|
|||
|
||||
from django.conf import settings
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
from django.utils.timezone import now as timezone_now
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy
|
||||
|
@ -135,11 +136,6 @@ def can_edit_content_or_topic(
|
|||
return False
|
||||
|
||||
|
||||
class MessageUpdateUserInfoResult(TypedDict):
|
||||
message_user_ids: Set[int]
|
||||
mention_user_ids: Set[int]
|
||||
|
||||
|
||||
def maybe_send_resolve_topic_notifications(
|
||||
*,
|
||||
user_profile: UserProfile,
|
||||
|
@ -255,29 +251,23 @@ def send_message_moved_breadcrumbs(
|
|||
)
|
||||
|
||||
|
||||
def get_user_info_for_message_updates(message_id: int) -> MessageUpdateUserInfoResult:
|
||||
|
||||
def get_mentions_for_message_updates(message_id: int) -> Set[int]:
|
||||
# We exclude UserMessage.flags.historical rows since those
|
||||
# users did not receive the message originally, and thus
|
||||
# probably are not relevant for reprocessed alert_words,
|
||||
# mentions and similar rendering features. This may be a
|
||||
# decision we change in the future.
|
||||
query = UserMessage.objects.filter(
|
||||
message=message_id,
|
||||
flags=~UserMessage.flags.historical,
|
||||
).values("user_profile_id", "flags")
|
||||
rows = list(query)
|
||||
|
||||
message_user_ids = {row["user_profile_id"] for row in rows}
|
||||
|
||||
mask = UserMessage.flags.mentioned | UserMessage.flags.wildcard_mentioned
|
||||
|
||||
mention_user_ids = {row["user_profile_id"] for row in rows if int(row["flags"]) & mask}
|
||||
|
||||
return dict(
|
||||
message_user_ids=message_user_ids,
|
||||
mention_user_ids=mention_user_ids,
|
||||
mentioned_user_ids = (
|
||||
UserMessage.objects.filter(
|
||||
message=message_id,
|
||||
flags=~UserMessage.flags.historical,
|
||||
)
|
||||
.filter(
|
||||
Q(flags__andnz=(UserMessage.flags.mentioned | UserMessage.flags.wildcard_mentioned))
|
||||
)
|
||||
.values_list("user_profile_id", flat=True)
|
||||
)
|
||||
return {user_profile_id for user_profile_id in mentioned_user_ids}
|
||||
|
||||
|
||||
def update_user_message_flags(
|
||||
|
@ -973,8 +963,7 @@ def check_update_message(
|
|||
mention_backend=mention_backend,
|
||||
content=content,
|
||||
)
|
||||
user_info = get_user_info_for_message_updates(message.id)
|
||||
prior_mention_user_ids = user_info["mention_user_ids"]
|
||||
prior_mention_user_ids = get_mentions_for_message_updates(message.id)
|
||||
|
||||
# We render the message using the current user's realm; since
|
||||
# the cross-realm bots never edit messages, this should be
|
||||
|
|
|
@ -12,7 +12,7 @@ from zerver.actions.message_edit import (
|
|||
check_update_message,
|
||||
do_delete_messages,
|
||||
do_update_message,
|
||||
get_user_info_for_message_updates,
|
||||
get_mentions_for_message_updates,
|
||||
)
|
||||
from zerver.actions.reactions import do_add_reaction
|
||||
from zerver.actions.realm_settings import do_change_realm_plan_type, do_set_realm_property
|
||||
|
@ -730,7 +730,7 @@ class EditMessageTest(EditMessageTestCase):
|
|||
message_history = result.json()["message_history"]
|
||||
self.assert_length(message_history, 1)
|
||||
|
||||
def test_user_info_for_updates(self) -> None:
|
||||
def test_mentions_for_message_updates(self) -> None:
|
||||
hamlet = self.example_user("hamlet")
|
||||
cordelia = self.example_user("cordelia")
|
||||
|
||||
|
@ -742,12 +742,7 @@ class EditMessageTest(EditMessageTestCase):
|
|||
hamlet, "Denmark", content="@**Cordelia, Lear's daughter**"
|
||||
)
|
||||
|
||||
user_info = get_user_info_for_message_updates(msg_id)
|
||||
message_user_ids = user_info["message_user_ids"]
|
||||
self.assertIn(hamlet.id, message_user_ids)
|
||||
self.assertIn(cordelia.id, message_user_ids)
|
||||
|
||||
mention_user_ids = user_info["mention_user_ids"]
|
||||
mention_user_ids = get_mentions_for_message_updates(msg_id)
|
||||
self.assertEqual(mention_user_ids, {cordelia.id})
|
||||
|
||||
def test_edit_cases(self) -> None:
|
||||
|
|
Loading…
Reference in New Issue