Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typing events: Use TypingStart/Stop and TypingEditMessage* types.
Evy Kassirer7f2105331727
diff --git a/zerver/actions/typing.py b/zerver/actions/typing.pyindex 45fc14e6853..1556bdee701 100644--- a/zerver/actions/typing.py+++ b/zerver/actions/typing.py@@ -3,6 +3,16 @@ from typing import Literalfrom django.conf import settingsfrom django.utils.translation import gettext as _+from zerver.lib.event_types import (+ BaseEvent,+ RecipientFieldForTypingEditChannelMessage,+ RecipientFieldForTypingEditDirectMessage,+ TypingEditMessageStartEvent,+ TypingEditMessageStopEvent,+ TypingPerson,+ TypingStartEvent,+ TypingStopEvent,+)from zerver.lib.exceptions import JsonableErrorfrom zerver.lib.stream_subscription import get_active_subscriptions_for_stream_idfrom zerver.models import Realm, Stream, UserProfile@@ -11,21 +21,30 @@ from zerver.tornado.django_api import send_event_rollback_unsafedef do_send_typing_notification(- realm: Realm, sender: UserProfile, recipient_user_profiles: list[UserProfile], operator: str+ realm: Realm,+ sender: UserProfile,+ recipient_user_profiles: list[UserProfile],+ operator: Literal["start", "stop"],) -> None:- sender_dict = {"user_id": sender.id, "email": sender.email}+ sender_typing_person = TypingPerson(user_id=sender.id, email=sender.email)# Include a list of recipients in the event body to help identify where the typing is happening- recipient_dicts = [- {"user_id": profile.id, "email": profile.email} for profile in recipient_user_profiles+ recipient_typing_persons = [+ TypingPerson(user_id=profile.id, email=profile.email) for profile in recipient_user_profiles]- event = dict(- type="typing",- message_type="direct",- op=operator,- sender=sender_dict,- recipients=recipient_dicts,- )+ event: BaseEvent+ if operator == "start":+ event = TypingStartEvent(+ message_type="direct",+ sender=sender_typing_person,+ recipients=recipient_typing_persons,+ )+ else:+ event = TypingStopEvent(+ message_type="direct",+ sender=sender_typing_person,+ recipients=recipient_typing_persons,+ )# Only deliver the notification to active user recipientsuser_ids_to_notify = [@@ -39,7 +58,9 @@ def do_send_typing_notification(# check_send_typing_notification:# Checks the typing notification and sends it-def check_send_typing_notification(sender: UserProfile, user_ids: list[int], operator: str) -> None:+def check_send_typing_notification(+ sender: UserProfile, user_ids: list[int], operator: Literal["start", "stop"]+) -> None:realm = sender.realmif sender.id not in user_ids:@@ -70,18 +91,25 @@ def check_send_typing_notification(sender: UserProfile, user_ids: list[int], opedef do_send_stream_typing_notification(- sender: UserProfile, operator: str, stream: Stream, topic_name: str+ sender: UserProfile, operator: Literal["start", "stop"], stream: Stream, topic_name: str) -> None:- sender_dict = {"user_id": sender.id, "email": sender.email}-- event = dict(- type="typing",- message_type="stream",- op=operator,- sender=sender_dict,- stream_id=stream.id,- topic=topic_name,- )+ sender_typing_person = TypingPerson(user_id=sender.id, email=sender.email)++ event: BaseEvent+ if operator == "start":+ event = TypingStartEvent(+ message_type="stream",+ sender=sender_typing_person,+ stream_id=stream.id,+ topic=topic_name,+ )+ else:+ event = TypingStopEvent(+ message_type="stream",+ sender=sender_typing_person,+ stream_id=stream.id,+ topic=topic_name,+ )subscriptions_query = get_active_subscriptions_for_stream_id(stream.id, include_deactivated_users=False@@ -109,17 +137,22 @@ def do_send_stream_message_edit_typing_notification(operator: Literal["start", "stop"],topic_name: str,) -> None:- event = dict(- type="typing_edit_message",- op=operator,- sender_id=sender.id,- message_id=message_id,- recipient=dict(- type="channel",- channel_id=channel_id,- topic=topic_name,- ),+ recipient = RecipientFieldForTypingEditChannelMessage(+ type="channel", channel_id=channel_id, topic=topic_name)+ event: BaseEvent+ if operator == "start":+ event = TypingEditMessageStartEvent(+ sender_id=sender.id,+ message_id=message_id,+ recipient=recipient,+ )+ else:+ event = TypingEditMessageStopEvent(+ sender_id=sender.id,+ message_id=message_id,+ recipient=recipient,+ )subscriptions_query = get_active_subscriptions_for_stream_id(channel_id, include_deactivated_users=False@@ -159,15 +192,19 @@ def do_send_direct_message_edit_typing_notification(if user.is_active and user.receives_typing_notifications]- event = dict(- type="typing_edit_message",- op=operator,- sender_id=sender.id,- message_id=message_id,- recipient=dict(- type="direct",- user_ids=user_ids_to_notify,- ),- )+ recipient = RecipientFieldForTypingEditDirectMessage(type="direct", user_ids=user_ids_to_notify)+ event: BaseEvent+ if operator == "start":+ event = TypingEditMessageStartEvent(+ sender_id=sender.id,+ message_id=message_id,+ recipient=recipient,+ )+ else:+ event = TypingEditMessageStopEvent(+ sender_id=sender.id,+ message_id=message_id,+ recipient=recipient,+ )send_event_rollback_unsafe(sender.realm, event, user_ids_to_notify)diff --git a/zerver/lib/event_types.py b/zerver/lib/event_types.pyindex bc1e415b5a2..a54d2bf0b5d 100644--- a/zerver/lib/event_types.py+++ b/zerver/lib/event_types.py@@ -1045,8 +1045,8 @@ class TypingPerson(BaseModel):class TypingStartCoreEvent(BaseEvent):- type: Literal["typing"]- op: Literal["start"]+ type: Literal["typing"] = "typing"+ op: Literal["start"] = "start"message_type: Literal["direct", "stream"]sender: TypingPerson@@ -1059,8 +1059,8 @@ class TypingStartEvent(TypingStartCoreEvent):class TypingStopCoreEvent(BaseEvent):- type: Literal["typing"]- op: Literal["stop"]+ type: Literal["typing"] = "typing"+ op: Literal["stop"] = "stop"message_type: Literal["direct", "stream"]sender: TypingPerson@@ -1084,16 +1084,16 @@ class RecipientFieldForTypingEditDirectMessage(BaseModel):class TypingEditMessageStartEvent(BaseEvent):- type: Literal["typing_edit_message"]- op: Literal["start"]+ type: Literal["typing_edit_message"] = "typing_edit_message"+ op: Literal["start"] = "start"sender_id: intmessage_id: intrecipient: RecipientFieldForTypingEditChannelMessage | RecipientFieldForTypingEditDirectMessageclass TypingEditMessageStopEvent(BaseEvent):- type: Literal["typing_edit_message"]- op: Literal["stop"]+ type: Literal["typing_edit_message"] = "typing_edit_message"+ op: Literal["stop"] = "stop"sender_id: intmessage_id: intrecipient: RecipientFieldForTypingEditChannelMessage | RecipientFieldForTypingEditDirectMessage