submessage: Fix recipients of "submessage" event.

Earlier, submessage was not live-updated for users who joined
the stream after the message was sent.

This commit fixes that bug.

Also, now we use 'event_recipient_ids_for_action_on_messages'.
It helps to add hardening such that if the invariant "no usermessage
row corresponding to a message exists if the user loses access to the
message" is violated due to some bug, it has minimal user impact.
This commit is contained in:
Prakhar Pratyush 2024-09-27 13:26:08 +05:30 committed by Tim Abbott
parent d6c48b7185
commit c3f2615e20
1 changed files with 3 additions and 3 deletions

View File

@ -3,12 +3,13 @@ from django.utils.translation import gettext as _
from zerver.actions.user_topics import do_set_user_topic_visibility_policy from zerver.actions.user_topics import do_set_user_topic_visibility_policy
from zerver.lib.exceptions import JsonableError from zerver.lib.exceptions import JsonableError
from zerver.lib.message import ( from zerver.lib.message import (
event_recipient_ids_for_action_on_messages,
set_visibility_policy_possible, set_visibility_policy_possible,
should_change_visibility_policy, should_change_visibility_policy,
visibility_policy_for_participation, visibility_policy_for_participation,
) )
from zerver.lib.streams import access_stream_by_id from zerver.lib.streams import access_stream_by_id
from zerver.models import Realm, SubMessage, UserMessage, UserProfile from zerver.models import Realm, SubMessage, UserProfile
from zerver.tornado.django_api import send_event_on_commit from zerver.tornado.django_api import send_event_on_commit
@ -90,7 +91,6 @@ def do_add_submessage(
sender_id=sender_id, sender_id=sender_id,
content=content, content=content,
) )
ums = UserMessage.objects.filter(message_id=message_id) target_user_ids = event_recipient_ids_for_action_on_messages([submessage.message])
target_user_ids = [um.user_profile_id for um in ums]
send_event_on_commit(realm, event, target_user_ids) send_event_on_commit(realm, event, target_user_ids)