notifications: Remove unused fields in queue events.

* `stream_name`: This field is actually redundant. The email/push
  notifications handlers don't use that field from the dict, and they
  anyways query for the message, so we're safe in deleting this field,
  even if in the future we end up needing the stream name.

* `timestamp`: This is totally unused by the email/push notification
  handlers, and aren't sent to push clients either.

* `type` is used only for the push notifications handler, since only
  push notifications can be revoked, so we move them to only run there.
This commit is contained in:
Abhijeet Prasad Bodas
2021-07-08 11:00:40 +05:30
committed by Tim Abbott
parent 76dc504f7e
commit bf15c0235a
4 changed files with 1 additions and 37 deletions

View File

@@ -1363,7 +1363,6 @@ Output:
message_id=message_id,
acting_user_id=acting_user_id,
private_message=kwargs.get("private_message", False),
stream_name=kwargs.get("stream_name", None),
mentioned_user_group_id=kwargs.get("mentioned_user_group_id", None),
idle=kwargs.get("idle", True),
already_notified=kwargs.get(

View File

@@ -63,7 +63,6 @@ class MissedMessageNotificationsTest(ZulipTestCase):
acting_user_id=2,
user_id=3,
private_message=False,
stream_name="Denmark",
flags=["mentioned"],
mentioned=True,
mentioned_user_group_id=33,
@@ -72,11 +71,9 @@ class MissedMessageNotificationsTest(ZulipTestCase):
self.assertTrue(mock_queue_json_publish.call_count, 2)
push_notice = mock_queue_json_publish.call_args_list[0][0][1]
self.assertEqual(push_notice["stream_name"], "Denmark")
self.assertEqual(push_notice["mentioned_user_group_id"], 33)
email_notice = mock_queue_json_publish.call_args_list[1][0][1]
self.assertEqual(email_notice["stream_name"], "Denmark")
self.assertEqual(email_notice["mentioned_user_group_id"], 33)
def tornado_call(
@@ -212,7 +209,6 @@ class MissedMessageNotificationsTest(ZulipTestCase):
assert_maybe_enqueue_notifications_call_args(
args_dict=args_dict,
message_id=msg_id,
stream_name="Denmark",
already_notified={"email_notified": False, "push_notified": False},
)
destroy_event_queue(client_descriptor.event_queue.id)
@@ -250,7 +246,6 @@ class MissedMessageNotificationsTest(ZulipTestCase):
message_id=msg_id,
flags=["mentioned"],
mentioned=True,
stream_name="Denmark",
already_notified={"email_notified": True, "push_notified": True},
)
destroy_event_queue(client_descriptor.event_queue.id)
@@ -269,7 +264,6 @@ class MissedMessageNotificationsTest(ZulipTestCase):
message_id=msg_id,
flags=["wildcard_mentioned"],
wildcard_mention_notify=True,
stream_name="Denmark",
already_notified={"email_notified": True, "push_notified": True},
)
destroy_event_queue(client_descriptor.event_queue.id)
@@ -288,7 +282,6 @@ class MissedMessageNotificationsTest(ZulipTestCase):
args_dict=args_dict,
flags=["wildcard_mentioned"],
message_id=msg_id,
stream_name="Denmark",
already_notified={"email_notified": False, "push_notified": False},
)
destroy_event_queue(client_descriptor.event_queue.id)
@@ -309,7 +302,6 @@ class MissedMessageNotificationsTest(ZulipTestCase):
args_dict=args_dict,
message_id=msg_id,
flags=["wildcard_mentioned"],
stream_name="Denmark",
already_notified={"email_notified": False, "push_notified": False},
)
destroy_event_queue(client_descriptor.event_queue.id)
@@ -335,7 +327,6 @@ class MissedMessageNotificationsTest(ZulipTestCase):
message_id=msg_id,
flags=["wildcard_mentioned"],
wildcard_mention_notify=True,
stream_name="Denmark",
already_notified={"email_notified": True, "push_notified": True},
)
destroy_event_queue(client_descriptor.event_queue.id)
@@ -363,7 +354,6 @@ class MissedMessageNotificationsTest(ZulipTestCase):
message_id=msg_id,
flags=["mentioned"],
mentioned=True,
stream_name="Denmark",
mentioned_user_group_id=hamlet_and_cordelia.id,
already_notified={"email_notified": True, "push_notified": True},
)
@@ -386,7 +376,6 @@ class MissedMessageNotificationsTest(ZulipTestCase):
message_id=msg_id,
stream_push_notify=True,
stream_email_notify=False,
stream_name="Denmark",
already_notified={"email_notified": False, "push_notified": True},
)
destroy_event_queue(client_descriptor.event_queue.id)
@@ -408,7 +397,6 @@ class MissedMessageNotificationsTest(ZulipTestCase):
message_id=msg_id,
stream_push_notify=False,
stream_email_notify=True,
stream_name="Denmark",
already_notified={"email_notified": True, "push_notified": False},
)
destroy_event_queue(client_descriptor.event_queue.id)
@@ -436,7 +424,6 @@ class MissedMessageNotificationsTest(ZulipTestCase):
assert_maybe_enqueue_notifications_call_args(
args_dict=args_dict,
message_id=msg_id,
stream_name="Denmark",
already_notified={"email_notified": False, "push_notified": False},
)
destroy_event_queue(client_descriptor.event_queue.id)
@@ -459,7 +446,6 @@ class MissedMessageNotificationsTest(ZulipTestCase):
assert_maybe_enqueue_notifications_call_args(
args_dict=args_dict,
message_id=msg_id,
stream_name="Denmark",
already_notified={"email_notified": False, "push_notified": False},
)
destroy_event_queue(client_descriptor.event_queue.id)

View File

@@ -191,7 +191,6 @@ class EditMessageSideEffectsTest(ZulipTestCase):
message_id=message_id,
mentioned=True,
flags=["mentioned"],
stream_name="Scotland",
already_notified={},
)
@@ -320,7 +319,6 @@ class EditMessageSideEffectsTest(ZulipTestCase):
acting_user_id=hamlet.id,
message_id=message_id,
mentioned=True,
stream_name="Scotland",
flags=["mentioned"],
online_push_enabled=True,
idle=False,
@@ -356,7 +354,6 @@ class EditMessageSideEffectsTest(ZulipTestCase):
user_id=cordelia.id,
acting_user_id=hamlet.id,
message_id=message_id,
stream_name="Scotland",
online_push_enabled=True,
idle=False,
already_notified={},
@@ -394,7 +391,6 @@ class EditMessageSideEffectsTest(ZulipTestCase):
acting_user_id=self.example_user("hamlet").id,
mentioned=True,
flags=["mentioned"],
stream_name="Scotland",
already_notified={},
)
self.assertEqual(info["enqueue_kwargs"], expected_enqueue_kwargs)
@@ -427,7 +423,6 @@ class EditMessageSideEffectsTest(ZulipTestCase):
message_id=message_id,
wildcard_mention_notify=True,
flags=["wildcard_mentioned"],
stream_name="Scotland",
already_notified={},
)
self.assertEqual(info["enqueue_kwargs"], expected_enqueue_kwargs)
@@ -485,7 +480,6 @@ class EditMessageSideEffectsTest(ZulipTestCase):
message_id=message_id,
mentioned=True,
flags=["mentioned"],
stream_name="Scotland",
idle=False,
already_notified={},
)

View File

@@ -705,8 +705,6 @@ def build_offline_notification(user_profile_id: int, message_id: int) -> Dict[st
return {
"user_profile_id": user_profile_id,
"message_id": message_id,
"type": "add",
"timestamp": time.time(),
}
@@ -759,10 +757,6 @@ def missedmessage_hook(
private_message = event["message"]["type"] == "private"
mentioned_user_group_id = internal_data.get("mentioned_user_group_id")
stream_name = None
if not private_message:
stream_name = event["message"]["display_recipient"]
# Since we just GC'd the last event queue, the user is definitely idle.
idle = True
@@ -777,7 +771,6 @@ def missedmessage_hook(
acting_user_id=sender_id,
message_id=message_id,
private_message=private_message,
stream_name=stream_name,
mentioned_user_group_id=mentioned_user_group_id,
idle=idle,
already_notified=already_notified,
@@ -801,7 +794,6 @@ def maybe_enqueue_notifications(
acting_user_id: int,
message_id: int,
private_message: bool,
stream_name: Optional[str],
mentioned_user_group_id: Optional[int],
idle: bool,
already_notified: Dict[str, bool],
@@ -820,7 +812,7 @@ def maybe_enqueue_notifications(
notice["trigger"] = user_notifications_data.get_push_notification_trigger(
private_message, acting_user_id, idle
)
notice["stream_name"] = stream_name
notice["type"] = "add"
notice["mentioned_user_group_id"] = mentioned_user_group_id
if not already_notified.get("push_notified"):
queue_json_publish("missedmessage_mobile_notifications", notice)
@@ -835,7 +827,6 @@ def maybe_enqueue_notifications(
notice["trigger"] = user_notifications_data.get_email_notification_trigger(
private_message, acting_user_id, idle
)
notice["stream_name"] = stream_name
notice["mentioned_user_group_id"] = mentioned_user_group_id
if not already_notified.get("email_notified"):
queue_json_publish("missedmessage_emails", notice, lambda notice: None)
@@ -971,15 +962,12 @@ def process_message_event(
idle = receiver_is_off_zulip(user_profile_id) or (user_profile_id in presence_idle_user_ids)
stream_name = event_template.get("stream_name")
extra_user_data[user_profile_id]["internal_data"].update(
maybe_enqueue_notifications(
user_notifications_data=user_notifications_data,
acting_user_id=sender_id,
message_id=message_id,
private_message=private_message,
stream_name=stream_name,
mentioned_user_group_id=mentioned_user_group_id,
idle=idle,
already_notified={},
@@ -1148,7 +1136,6 @@ def process_message_update_event(
message_id=message_id,
acting_user_id=acting_user_id,
private_message=(stream_name is None),
stream_name=stream_name,
presence_idle=(user_profile_id in presence_idle_user_ids),
prior_mentioned=(user_profile_id in prior_mention_user_ids),
)
@@ -1165,7 +1152,6 @@ def maybe_enqueue_notifications_for_message_update(
message_id: int,
acting_user_id: int,
private_message: bool,
stream_name: Optional[str],
presence_idle: bool,
prior_mentioned: bool,
) -> None:
@@ -1214,7 +1200,6 @@ def maybe_enqueue_notifications_for_message_update(
message_id=message_id,
acting_user_id=acting_user_id,
private_message=private_message,
stream_name=stream_name,
mentioned_user_group_id=mentioned_user_group_id,
idle=idle,
already_notified={},