update_message: Use rendering_only flag for notifications logic.

When `update_message` events were updated to have a consistent
format for both normal message updates/edits and special
rendering preview updates, the logic used in the tornado event
queue processor to identify the special events for sending
notifications no longer applied.

Updates that logic to use the `rendering_only` flag (if present)
that was added to the `update_message` event format to identify
if the event processor should potentially send notifications to
users.

For upgrade compatibility, if `rendering_only` flag is not present,
uses previous event structure and checks for the absence of the
`user_id` property, which indicated the special rendering preview
updates.

Fixes #16022.
This commit is contained in:
Lauryn Menard
2022-04-18 13:35:18 +02:00
committed by Tim Abbott
parent 1db591de54
commit 2e9adad123

View File

@@ -1129,50 +1129,62 @@ def process_message_update_event(
stream_name = event_template.get("stream_name")
message_id = event_template["message_id"]
# TODO/compatibility: Modern `update_message` events contain the
# rendering_only key, which indicates whether the update is a link
# preview rendering update (not a human action). However, because
# events may be in the notify_tornado queue at the time we
# upgrade, we need the below logic to compute rendering_only based
# on the `user_id` key not being present in legacy events that
# would have had rendering_only set. Remove this check when one
# can no longer directly update from 4.x to main.
if "rendering_only" in event_template:
rendering_only_update = event_template["rendering_only"]
else:
rendering_only_update = "user_id" not in event_template
for user_data in users:
user_profile_id = user_data["id"]
if "user_id" in event_template:
# The user we'll get here will be the sender if the message's
# content was edited, and the editor for topic edits. That's
# the correct "acting_user" for both cases.
acting_user_id = event_template["user_id"]
else:
# Events without a `user_id` field come from the do_update_embedded_data
# code path, and represent just rendering previews; there should be no
# real content changes.
# It doesn't really matter what we set `acting_user_id` in this case,
# because we know this event isn't meant to send notifications.
acting_user_id = user_profile_id
user_event = dict(event_template) # shallow copy, but deep enough for our needs
for key in user_data.keys():
if key != "id":
user_event[key] = user_data[key]
flags: Collection[str] = user_event["flags"]
user_notifications_data = UserMessageNotificationsData.from_user_id_sets(
user_id=user_profile_id,
flags=flags,
private_message=(stream_name is None),
online_push_user_ids=online_push_user_ids,
pm_mention_push_disabled_user_ids=pm_mention_push_disabled_user_ids,
pm_mention_email_disabled_user_ids=pm_mention_email_disabled_user_ids,
stream_push_user_ids=stream_push_user_ids,
stream_email_user_ids=stream_email_user_ids,
wildcard_mention_user_ids=wildcard_mention_user_ids,
muted_sender_user_ids=muted_sender_user_ids,
all_bot_user_ids=all_bot_user_ids,
)
# Events where `rendering_only_update` is True come from the
# do_update_embedded_data code path, and represent rendering
# previews; there should be no real content changes.
# Therefore, we know only events where `rendering_only_update`
# is False possibly send notifications.
if not rendering_only_update:
maybe_enqueue_notifications_for_message_update(
user_notifications_data=user_notifications_data,
message_id=message_id,
acting_user_id=acting_user_id,
private_message=(stream_name is None),
presence_idle=(user_profile_id in presence_idle_user_ids),
prior_mentioned=(user_profile_id in prior_mention_user_ids),
)
# The user we'll get here will be the sender if the message's
# content was edited, and the editor for topic edits. That's
# the correct "acting_user" for both cases.
acting_user_id = event_template["user_id"]
flags: Collection[str] = user_event["flags"]
user_notifications_data = UserMessageNotificationsData.from_user_id_sets(
user_id=user_profile_id,
flags=flags,
private_message=(stream_name is None),
online_push_user_ids=online_push_user_ids,
pm_mention_push_disabled_user_ids=pm_mention_push_disabled_user_ids,
pm_mention_email_disabled_user_ids=pm_mention_email_disabled_user_ids,
stream_push_user_ids=stream_push_user_ids,
stream_email_user_ids=stream_email_user_ids,
wildcard_mention_user_ids=wildcard_mention_user_ids,
muted_sender_user_ids=muted_sender_user_ids,
all_bot_user_ids=all_bot_user_ids,
)
maybe_enqueue_notifications_for_message_update(
user_notifications_data=user_notifications_data,
message_id=message_id,
acting_user_id=acting_user_id,
private_message=(stream_name is None),
presence_idle=(user_profile_id in presence_idle_user_ids),
prior_mentioned=(user_profile_id in prior_mention_user_ids),
)
for client in get_client_descriptors_for_user(user_profile_id):
if client.accepts_event(user_event):