mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	register: Handle "Pronouns" type fields for older mobile clients.
Mobile clients older than v27.192 do not support PRONOUNS type custom profile fields, so we instead change the type of it to SHORT_TEXT in the data sent with register response and also in the events sent to those clients.
This commit is contained in:
		@@ -44,6 +44,7 @@ from zerver.lib.notification_data import UserMessageNotificationsData
 | 
			
		||||
from zerver.lib.queue import queue_json_publish, retry_event
 | 
			
		||||
from zerver.lib.utils import statsd
 | 
			
		||||
from zerver.middleware import async_request_timer_restart
 | 
			
		||||
from zerver.models import CustomProfileField
 | 
			
		||||
from zerver.tornado.descriptors import clear_descriptor_by_handler_id, set_descriptor_by_handler_id
 | 
			
		||||
from zerver.tornado.exceptions import BadEventQueueIdError
 | 
			
		||||
from zerver.tornado.handlers import (
 | 
			
		||||
@@ -94,6 +95,7 @@ class ClientDescriptor:
 | 
			
		||||
        bulk_message_deletion: bool = False,
 | 
			
		||||
        stream_typing_notifications: bool = False,
 | 
			
		||||
        user_settings_object: bool = False,
 | 
			
		||||
        pronouns_field_type_supported: bool = True,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        # These objects are serialized on shutdown and restored on restart.
 | 
			
		||||
        # If fields are added or semantics are changed, temporary code must be
 | 
			
		||||
@@ -117,6 +119,7 @@ class ClientDescriptor:
 | 
			
		||||
        self.bulk_message_deletion = bulk_message_deletion
 | 
			
		||||
        self.stream_typing_notifications = stream_typing_notifications
 | 
			
		||||
        self.user_settings_object = user_settings_object
 | 
			
		||||
        self.pronouns_field_type_supported = pronouns_field_type_supported
 | 
			
		||||
 | 
			
		||||
        # Default for lifespan_secs is DEFAULT_EVENT_QUEUE_TIMEOUT_SECS;
 | 
			
		||||
        # but users can set it as high as MAX_QUEUE_TIMEOUT_SECS.
 | 
			
		||||
@@ -144,6 +147,7 @@ class ClientDescriptor:
 | 
			
		||||
            bulk_message_deletion=self.bulk_message_deletion,
 | 
			
		||||
            stream_typing_notifications=self.stream_typing_notifications,
 | 
			
		||||
            user_settings_object=self.user_settings_object,
 | 
			
		||||
            pronouns_field_type_supported=self.pronouns_field_type_supported,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def __repr__(self) -> str:
 | 
			
		||||
@@ -176,6 +180,7 @@ class ClientDescriptor:
 | 
			
		||||
            d.get("bulk_message_deletion", False),
 | 
			
		||||
            d.get("stream_typing_notifications", False),
 | 
			
		||||
            d.get("user_settings_object", False),
 | 
			
		||||
            d.get("pronouns_field_type_supported", True),
 | 
			
		||||
        )
 | 
			
		||||
        ret.last_connection_time = d["last_connection_time"]
 | 
			
		||||
        return ret
 | 
			
		||||
@@ -1182,6 +1187,25 @@ def process_message_update_event(
 | 
			
		||||
                client.add_event(user_event)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def process_custom_profile_fields_event(event: Mapping[str, Any], users: Iterable[int]) -> None:
 | 
			
		||||
    pronouns_type_unsupported_fields = copy.deepcopy(event["fields"])
 | 
			
		||||
    for field in pronouns_type_unsupported_fields:
 | 
			
		||||
        if field["type"] == CustomProfileField.PRONOUNS:
 | 
			
		||||
            field["type"] = CustomProfileField.SHORT_TEXT
 | 
			
		||||
 | 
			
		||||
    pronouns_type_unsupported_event = dict(
 | 
			
		||||
        type="custom_profile_fields", fields=pronouns_type_unsupported_fields
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    for user_profile_id in users:
 | 
			
		||||
        for client in get_client_descriptors_for_user(user_profile_id):
 | 
			
		||||
            if client.accepts_event(event):
 | 
			
		||||
                if not client.pronouns_field_type_supported:
 | 
			
		||||
                    client.add_event(pronouns_type_unsupported_event)
 | 
			
		||||
                    continue
 | 
			
		||||
                client.add_event(event)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def maybe_enqueue_notifications_for_message_update(
 | 
			
		||||
    user_notifications_data: UserMessageNotificationsData,
 | 
			
		||||
    message_id: int,
 | 
			
		||||
@@ -1314,6 +1338,8 @@ def process_notification(notice: Mapping[str, Any]) -> None:
 | 
			
		||||
        process_deletion_event(event, user_ids)
 | 
			
		||||
    elif event["type"] == "presence":
 | 
			
		||||
        process_presence_event(event, cast(List[int], users))
 | 
			
		||||
    elif event["type"] == "custom_profile_fields":
 | 
			
		||||
        process_custom_profile_fields_event(event, cast(List[int], users))
 | 
			
		||||
    else:
 | 
			
		||||
        process_event(event, cast(List[int], users))
 | 
			
		||||
    logging.debug(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user