Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
settings: Add setting for marking resolved-topic notices as read.
Saubhagya Patel70e45f45c022
diff --git a/api_docs/changelog.md b/api_docs/changelog.mdindex f33ae7f2f2b..0bffb2dbd6d 100644--- a/api_docs/changelog.md+++ b/api_docs/changelog.md@@ -20,6 +20,13 @@ format used by the Zulip server that they are interacting with.## Changes in Zulip 11.0+**Feature level 385**++* [`POST /register`](/api/register-queue), [`PATCH/settings`](/api/update-settings),+ [`PATCH/realm/user_settings_defaults`](/api/update-realm-user-settings-defaults):+ Added new `resolved_topic_notice_auto_read_policy` setting, which controls+ how resolved-topic notices are marked as read for a user.+**Feature level 384*** [`GET /users`](/api/get-users): Added `user_ids` query parameter todiff --git a/version.py b/version.pyindex 174e51f2bcd..88e34c24036 100644--- a/version.py+++ b/version.py@@ -34,7 +34,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"# new level means in api_docs/changelog.md, as well as "**Changes**"# entries in the endpoint's documentation in `zulip.yaml`.-API_FEATURE_LEVEL = 384+API_FEATURE_LEVEL = 385# Bump the minor PROVISION_VERSION to indicate that folks should provision# only when going from an old version of the code to a newer version. Bumpdiff --git a/web/src/admin.ts b/web/src/admin.tsindex 4977f2055e8..73a4fea55be 100644--- a/web/src/admin.ts+++ b/web/src/admin.ts@@ -217,6 +217,8 @@ export function build_page(): void {web_stream_unreads_count_display_policy_values:settings_config.web_stream_unreads_count_display_policy_values,web_animate_image_previews_values: settings_config.web_animate_image_previews_values,+ resolved_topic_notice_auto_read_policy_values:+ settings_config.resolved_topic_notice_auto_read_policy_values,color_scheme_values: settings_config.color_scheme_values,web_home_view_values: settings_config.web_home_view_values,settings_object: realm_user_settings_defaults,diff --git a/web/src/realm_user_settings_defaults.ts b/web/src/realm_user_settings_defaults.tsindex 3b7dfd04dc2..0d53643f3fe 100644--- a/web/src/realm_user_settings_defaults.ts+++ b/web/src/realm_user_settings_defaults.ts@@ -46,6 +46,7 @@ export const realm_default_settings_schema = z.object({presence_enabled: z.boolean(),realm_name_in_email_notifications_policy: z.number(),receives_typing_notifications: z.boolean(),+ resolved_topic_notice_auto_read_policy: z.enum(["always", "except_followed", "never"]),send_private_typing_notifications: z.boolean(),send_read_receipts: z.boolean(),send_stream_typing_notifications: z.boolean(),diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.jsindex fd594aa779e..e601419253f 100644--- a/web/src/server_events_dispatch.js+++ b/web/src/server_events_dispatch.js@@ -845,6 +845,7 @@ export function dispatch_normal_event(event) {"hide_ai_features","high_contrast_mode","receives_typing_notifications",+ "resolved_topic_notice_auto_read_policy","starred_message_counts","timezone","translate_emoticons",diff --git a/web/src/settings.ts b/web/src/settings.tsindex 6c6e8378771..a40d54a58a9 100644--- a/web/src/settings.ts+++ b/web/src/settings.ts@@ -108,6 +108,8 @@ export function build_page(): void {web_channel_default_view_values: settings_config.web_channel_default_view_values,user_list_style_values: settings_config.user_list_style_values,web_animate_image_previews_values: settings_config.web_animate_image_previews_values,+ resolved_topic_notice_auto_read_policy_values:+ settings_config.resolved_topic_notice_auto_read_policy_values,web_stream_unreads_count_display_policy_values:settings_config.web_stream_unreads_count_display_policy_values,color_scheme_values: settings_config.color_scheme_values,diff --git a/web/src/settings_config.ts b/web/src/settings_config.tsindex 16ddc3b53a2..04355217156 100644--- a/web/src/settings_config.ts+++ b/web/src/settings_config.ts@@ -119,6 +119,21 @@ export const web_animate_image_previews_values = {},};+export const resolved_topic_notice_auto_read_policy_values = {+ always: {+ code: "always",+ description: $t({defaultMessage: "Always"}),+ },+ except_followed: {+ code: "except_followed",+ description: $t({defaultMessage: "Except in topics I'm following"}),+ },+ never: {+ code: "never",+ description: $t({defaultMessage: "Never"}),+ },+};+export const web_stream_unreads_count_display_policy_values = {all_streams: {code: 1,diff --git a/web/src/settings_notifications.ts b/web/src/settings_notifications.tsindex 9215d10a414..216ae19401f 100644--- a/web/src/settings_notifications.ts+++ b/web/src/settings_notifications.ts@@ -252,6 +252,10 @@ export function set_up(settings_panel: SettingsPanel): void {settings_object.automatically_follow_topics_policy,);+ $container+ .find(".setting_resolved_topic_notice_auto_read_policy")+ .val(settings_object.resolved_topic_notice_auto_read_policy);+const $automatically_unmute_topics_in_muted_streams_policy_dropdown = $container.find(".setting_automatically_unmute_topics_in_muted_streams_policy",);diff --git a/web/src/user_settings.ts b/web/src/user_settings.tsindex c2d10cde524..27ccabe1ce9 100644--- a/web/src/user_settings.ts+++ b/web/src/user_settings.ts@@ -64,6 +64,7 @@ export const user_settings_schema = stream_notification_settings_schemapresence_enabled: z.boolean(),realm_name_in_email_notifications_policy: z.number(),receives_typing_notifications: z.boolean(),+ resolved_topic_notice_auto_read_policy: z.enum(["always", "except_followed", "never"]),send_private_typing_notifications: z.boolean(),send_read_receipts: z.boolean(),send_stream_typing_notifications: z.boolean(),diff --git a/web/templates/settings/notification_settings.hbs b/web/templates/settings/notification_settings.hbsindex 07f018ae729..2a713f23ea7 100644--- a/web/templates/settings/notification_settings.hbs+++ b/web/templates/settings/notification_settings.hbs@@ -96,6 +96,13 @@{{> dropdown_options_widget option_values=automatically_unmute_topics_in_muted_streams_policy_values}}</select></div>++ <div class="input-group">+ <label for="{{prefix}}resolved_topic_notice_auto_read_policy" class="settings-field-label">{{t "Automatically mark resolved topic notices as read" }}</label>+ <select name="resolved_topic_notice_auto_read_policy" class="setting_resolved_topic_notice_auto_read_policy prop-element settings_select bootstrap-focus-style" id="{{prefix}}resolved_topic_notice_auto_read_policy" data-setting-widget-type="string">+ {{> dropdown_options_widget option_values=resolved_topic_notice_auto_read_policy_values}}+ </select>+ </div></div><div class="desktop_notifications m-10 {{#if for_realm_settings}}settings-subsection-parent{{else}}subsection-parent{{/if}}">diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.pyindex 2743a9e3952..231592f41a1 100644--- a/zerver/actions/message_edit.py+++ b/zerver/actions/message_edit.py@@ -83,7 +83,6 @@ from zerver.models import (ArchivedMessage,Attachment,Message,- Reaction,Recipient,Stream,Subscription,@@ -92,7 +91,7 @@ from zerver.models import (UserTopic,)from zerver.models.streams import get_stream_by_id_in_realm-from zerver.models.users import get_system_bot+from zerver.models.users import ResolvedTopicNoticeAutoReadPolicyEnum, get_system_botfrom zerver.tornado.django_api import send_event_on_commit@@ -176,11 +175,53 @@ def validate_user_can_edit_message(raise JsonableError(_("The time limit for editing this message has passed"))+def get_unread_user_ids_for_resolved_topic_notifications(+ stream: Stream,+ topic_name: str,+ users_following_topic: set[UserProfile] | None,+) -> set[int]:+ unread_user_ids: set[int] = set()++ all_stream_user_profiles = UserProfile.objects.filter(+ id__in=get_active_subscriptions_for_stream_id(+ stream.id, include_deactivated_users=False+ ).values_list("user_profile_id", flat=True),+ is_bot=False,+ )++ user_ids_following_topic: set[int] = set()+ if users_following_topic is not None:+ user_ids_following_topic = {user.id for user in users_following_topic}+ else:+ user_ids_following_topic = set(+ UserTopic.objects.filter(+ stream=stream,+ topic_name__iexact=topic_name,+ visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED,+ ).values_list("user_profile_id", flat=True)+ )++ for user_profile in all_stream_user_profiles:+ if (+ user_profile.resolved_topic_notice_auto_read_policy+ == ResolvedTopicNoticeAutoReadPolicyEnum.never.value+ ):+ unread_user_ids.add(user_profile.id)+ elif (+ user_profile.resolved_topic_notice_auto_read_policy+ == ResolvedTopicNoticeAutoReadPolicyEnum.except_followed.value+ and user_profile.id in user_ids_following_topic+ ):+ unread_user_ids.add(user_profile.id)++ return unread_user_ids++def maybe_send_resolve_topic_notifications(*,user_profile: UserProfile,message_edit_request: StreamMessageEditRequest,- changed_messages: QuerySet[Message],+ users_following_topic: set[UserProfile] | None,) -> tuple[int | None, bool]:"""Returns resolved_topic_message_id if resolve topic notifications were in fact sent."""# Note that topics will have already been stripped in check_update_message.@@ -214,16 +255,15 @@ def maybe_send_resolve_topic_notifications():return None, True- # Compute the users who either sent or reacted to messages that- # were moved via the "resolve topic' action. Only those users- # should be eligible for this message being managed as unread.- affected_participant_ids = set(- changed_messages.values_list("sender_id", flat=True).union(- Reaction.objects.filter(message__in=changed_messages).values_list(- "user_profile_id", flat=True- )- )+ # Compute the users for whom this message should be marked as unread+ # based on the `resolved_topic_notice_auto_read_policy` user setting.+ topic_name = message_edit_request.target_topic_name+ unread_user_ids = get_unread_user_ids_for_resolved_topic_notifications(+ stream=stream,+ topic_name=topic_name,+ users_following_topic=users_following_topic,)+sender = get_system_bot(settings.NOTIFICATION_BOT, user_profile.realm_id)user_mention = silent_mention_syntax_for_user(user_profile)with override_language(stream.realm.default_language):@@ -235,12 +275,12 @@ def maybe_send_resolve_topic_notifications(resolved_topic_message_id = internal_send_stream_message(sender,stream,- message_edit_request.target_topic_name,+ topic_name,notification_string.format(user=user_mention,),message_type=Message.MessageType.RESOLVE_TOPIC_NOTIFICATION,- limit_unread_user_ids=affected_participant_ids,+ limit_unread_user_ids=unread_user_ids,acting_user=user_profile,)@@ -1114,6 +1154,17 @@ def do_update_message(resolved_topic_message_id = Noneresolved_topic_message_deleted = False+ # We calculate the users for which the resolved-topic notification+ # should be marked as unread using the topic visibility policy and+ # the `resolved_topic_notice_auto_read_policy` user setting.+ users_following_original_topic = None+ if moved_all_visible_messages:+ users_following_original_topic = {+ user+ for user, visibility_policy in orig_topic_user_profile_to_visibility_policy.items()+ if visibility_policy == UserTopic.VisibilityPolicy.FOLLOWED+ }+if (message_edit_request.is_topic_editedand not message_edit_request.is_content_edited@@ -1123,7 +1174,7 @@ def do_update_message(maybe_send_resolve_topic_notifications(user_profile=user_profile,message_edit_request=message_edit_request,- changed_messages=changed_messages,+ users_following_topic=users_following_original_topic,))diff --git a/zerver/actions/realm_settings.py b/zerver/actions/realm_settings.pyindex b4a69f8f705..96d4e94545d 100644--- a/zerver/actions/realm_settings.py+++ b/zerver/actions/realm_settings.py@@ -489,7 +489,7 @@ def do_set_realm_zulip_update_announcements_stream(def do_set_realm_user_default_setting(realm_user_default: RealmUserDefault,name: str,- value: Any,+ raw_value: Any,*,acting_user: UserProfile | None,) -> None:@@ -497,6 +497,13 @@ def do_set_realm_user_default_setting(realm = realm_user_default.realmevent_time = timezone_now()+ if isinstance(raw_value, Enum):+ value = raw_value.value+ event_value = raw_value.name+ else:+ value = raw_value+ event_value = raw_value+setattr(realm_user_default, name, value)realm_user_default.save(update_fields=[name])@@ -516,7 +523,7 @@ def do_set_realm_user_default_setting(type="realm_user_settings_defaults",op="update",property=name,- value=value,+ value=event_value,)send_event_on_commit(realm, event, active_user_ids(realm.id))diff --git a/zerver/actions/user_settings.py b/zerver/actions/user_settings.pyindex 6417a223bd5..03ae72e358b 100644--- a/zerver/actions/user_settings.py+++ b/zerver/actions/user_settings.py@@ -1,5 +1,6 @@from collections.abc import Iterablefrom datetime import timedelta+from enum import Enumfrom django.conf import settingsfrom django.db import transaction@@ -433,20 +434,33 @@ def update_scheduled_email_notifications_time(def do_change_user_setting(user_profile: UserProfile,setting_name: str,- setting_value: bool | str | int,+ setting_value: bool | str | int | Enum,*,acting_user: UserProfile | None,) -> None:old_value = getattr(user_profile, setting_name)event_time = timezone_now()+ if isinstance(setting_value, Enum):+ db_setting_value = setting_value.value+ event_value = setting_value.name+ else:+ db_setting_value = setting_value+ event_value = db_setting_value+if setting_name == "timezone":- assert isinstance(setting_value, str)- setting_value = canonicalize_timezone(setting_value)+ assert isinstance(db_setting_value, str)+ assert isinstance(event_value, str)+ db_setting_value = canonicalize_timezone(db_setting_value)else:property_type = UserProfile.property_types[setting_name]- assert isinstance(setting_value, property_type)- setattr(user_profile, setting_name, setting_value)+ if isinstance(setting_value, Enum):+ assert isinstance(setting_value, property_type)+ assert isinstance(event_value, str)+ else:+ assert isinstance(db_setting_value, property_type)+ assert isinstance(event_value, property_type)+ setattr(user_profile, setting_name, db_setting_value)# TODO: Move these database actions into a transaction.atomic block.user_profile.save(update_fields=[setting_name])@@ -459,29 +473,30 @@ def do_change_user_setting(modified_user=user_profile,extra_data={RealmAuditLog.OLD_VALUE: old_value,- RealmAuditLog.NEW_VALUE: setting_value,+ RealmAuditLog.NEW_VALUE: db_setting_value,"property": setting_name,},)# Disabling digest emails should clear a user's email queue- if setting_name == "enable_digest_emails" and not setting_value:+ if setting_name == "enable_digest_emails" and not db_setting_value:clear_scheduled_emails(user_profile.id, ScheduledEmail.DIGEST)if setting_name == "email_notifications_batching_period_seconds":assert isinstance(old_value, int)- assert isinstance(setting_value, int)- update_scheduled_email_notifications_time(user_profile, old_value, setting_value)+ assert isinstance(db_setting_value, int)+ update_scheduled_email_notifications_time(user_profile, old_value, db_setting_value)event = {"type": "user_settings","op": "update","property": setting_name,- "value": setting_value,+ "value": event_value,}+if setting_name == "default_language":- assert isinstance(setting_value, str)- event["language_name"] = get_language_name(setting_value)+ assert isinstance(db_setting_value, str)+ event["language_name"] = get_language_name(db_setting_value)transaction.on_commit(lambda: flush_user_profile(sender=UserProfile, instance=user_profile))@@ -495,7 +510,7 @@ def do_change_user_setting("type": "update_global_notifications","user": user_profile.email,"notification_name": setting_name,- "setting": setting_value,+ "setting": event_value,}send_event_on_commit(user_profile.realm, legacy_event, [user_profile.id])@@ -507,23 +522,23 @@ def do_change_user_setting("type": "update_display_settings","user": user_profile.email,"setting_name": setting_name,- "setting": setting_value,+ "setting": event_value,}if setting_name == "default_language":- assert isinstance(setting_value, str)- legacy_event["language_name"] = get_language_name(setting_value)+ assert isinstance(db_setting_value, str)+ legacy_event["language_name"] = get_language_name(db_setting_value)send_event_on_commit(user_profile.realm, legacy_event, [user_profile.id])if setting_name == "allow_private_data_export":- event = {+ realm_export_event = {"type": "realm_export_consent","user_id": user_profile.id,- "consented": setting_value,+ "consented": event_value,}send_event_on_commit(user_profile.realm,- event,+ realm_export_event,list(user_profile.realm.get_human_admin_users().values_list("id", flat=True)),)@@ -546,7 +561,7 @@ def do_change_user_setting(user_profile, old_value, user_profile.email_address_visibility)- if UserProfile.EMAIL_ADDRESS_VISIBILITY_EVERYONE not in [old_value, setting_value]:+ if UserProfile.EMAIL_ADDRESS_VISIBILITY_EVERYONE not in [old_value, db_setting_value]:# We use real email addresses on UserProfile.email only if# EMAIL_ADDRESS_VISIBILITY_EVERYONE is configured, so# changes between values that will not require changing@@ -559,7 +574,7 @@ def do_change_user_setting(send_user_email_update_event(user_profile)notify_avatar_url_change(user_profile)- if setting_name == "enable_drafts_synchronization" and setting_value is False:+ if setting_name == "enable_drafts_synchronization" and db_setting_value is False:# Delete all of the drafts from the backend but don't send delete events# for them since all that's happened is that we stopped syncing changes,# not deleted every previously synced draft - to do that use the DELETE@@ -575,7 +590,7 @@ def do_change_user_setting(# user's current presence state as consistent with the new# setting; not doing so can make it look like the settings# change didn't have any effect.- if setting_value:+ if db_setting_value:status = UserPresence.LEGACY_STATUS_ACTIVE_INTpresence_time = timezone_now()else:diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.pyindex 950c168834a..cb727f593da 100644--- a/zerver/lib/event_schema.py+++ b/zerver/lib/event_schema.py@@ -460,7 +460,11 @@ def check_realm_default_update(assert prop in RealmUserDefault.property_typesprop_type = RealmUserDefault.property_types[prop]- assert isinstance(event["value"], prop_type)+ value = event["value"]+ if inspect.isclass(prop_type) and issubclass(prop_type, Enum):+ assert isinstance(value, str)+ else:+ assert isinstance(value, prop_type)def check_realm_update_dict(@@ -620,7 +624,10 @@ def check_user_settings_update(assert isinstance(value, str)else:setting_type = UserProfile.property_types[setting_name]- assert isinstance(value, setting_type)+ if inspect.isclass(setting_type) and issubclass(setting_type, Enum):+ assert isinstance(value, str)+ else:+ assert isinstance(value, setting_type)if setting_name == "default_language":assert "language_name" in eventdiff --git a/zerver/lib/events.py b/zerver/lib/events.pyindex 85f44a0829f..bb760d2ad00 100644--- a/zerver/lib/events.py+++ b/zerver/lib/events.py@@ -105,6 +105,7 @@ from zerver.models.realms import (get_realm_domains,)from zerver.models.streams import get_default_stream_groups+from zerver.models.users import ResolvedTopicNoticeAutoReadPolicyEnumfrom zerver.tornado.django_api import get_user_events, request_event_queuefrom zproject.backends import email_auth_enabled, password_auth_enabled@@ -595,6 +596,11 @@ def fetch_initial_state_data(state["realm_user_settings_defaults"]["available_notification_sounds"] = (get_available_notification_sounds())+ state["realm_user_settings_defaults"]["resolved_topic_notice_auto_read_policy"] = (+ ResolvedTopicNoticeAutoReadPolicyEnum(+ realm_user_default.resolved_topic_notice_auto_read_policy+ ).name+ )if want("realm_domains"):state["realm_domains"] = get_realm_domains(realm)@@ -839,6 +845,11 @@ def fetch_initial_state_data(state["user_settings"]["available_notification_sounds"] = (get_available_notification_sounds())+ state["user_settings"]["resolved_topic_notice_auto_read_policy"] = (+ ResolvedTopicNoticeAutoReadPolicyEnum(+ settings_user.resolved_topic_notice_auto_read_policy+ ).name+ )if want("user_status"):# We require creating an account to access statuses.diff --git a/zerver/migrations/0703_realmuserdefault_resolved_topic_notice_auto_read_policy_and_more.py b/zerver/migrations/0703_realmuserdefault_resolved_topic_notice_auto_read_policy_and_more.pynew file mode 100644index 00000000000..a7874d5d9a4--- /dev/null+++ b/zerver/migrations/0703_realmuserdefault_resolved_topic_notice_auto_read_policy_and_more.py@@ -0,0 +1,29 @@+# Generated by Django 5.1.8 on 2025-04-25 10:20++from django.db import migrations, models+++class Migration(migrations.Migration):+ except_followed = 2+ dependencies = [+ ("zerver", "0702_rename_populate_db_client_to_zulip_data_import"),+ ]++ operations = [+ migrations.AddField(+ model_name="realmuserdefault",+ name="resolved_topic_notice_auto_read_policy",+ field=models.PositiveSmallIntegerField(+ default=except_followed,+ db_default=except_followed,+ ),+ ),+ migrations.AddField(+ model_name="userprofile",+ name="resolved_topic_notice_auto_read_policy",+ field=models.PositiveSmallIntegerField(+ default=except_followed,+ db_default=except_followed,+ ),+ ),+ ]diff --git a/zerver/models/users.py b/zerver/models/users.pyindex 0e3dcba598d..a8e82dd0e3f 100644--- a/zerver/models/users.py+++ b/zerver/models/users.py@@ -1,4 +1,5 @@from email.headerregistry import Address+from enum import Enumfrom typing import TYPE_CHECKING, Any, Optionalfrom uuid import uuid4@@ -35,6 +36,13 @@ if TYPE_CHECKING:from zerver.models import Realm+class ResolvedTopicNoticeAutoReadPolicyEnum(Enum):+ # The case is used by Pydantic in the API+ always = 1+ except_followed = 2+ never = 3++class UserBaseSettings(models.Model):"""This abstract class is the container for all preferences/personalsettings for users that control the behavior of the application.@@ -263,6 +271,12 @@ class UserBaseSettings(models.Model):)automatically_follow_topics_where_mentioned = models.BooleanField(default=True)+ resolved_topic_notice_auto_read_policy = models.PositiveSmallIntegerField(+ default=ResolvedTopicNoticeAutoReadPolicyEnum.except_followed.value,+ db_default=ResolvedTopicNoticeAutoReadPolicyEnum.except_followed.value,+ )+ RESOLVED_TOPIC_NOTICE_AUTO_READ_POLICY_TYPES = list(ResolvedTopicNoticeAutoReadPolicyEnum)+# Whether or not the user wants to sync their drafts.enable_drafts_synchronization = models.BooleanField(default=True)@@ -364,6 +378,7 @@ class UserBaseSettings(models.Model):web_navigate_to_sent_message=bool,web_suggest_update_timezone=bool,hide_ai_features=bool,+ resolved_topic_notice_auto_read_policy=ResolvedTopicNoticeAutoReadPolicyEnum,)modern_notification_settings = dict(diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 130a85c9c57..03d3573390d 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -13020,6 +13020,21 @@ paths:**Changes**: New in Zulip 8.0 (feature level 235).type: booleanexample: true+ resolved_topic_notice_auto_read_policy:+ description: |+ Controls whether the resolved-topic notices are marked as read.++ - "always" - Always mark resolved-topic notices as read.+ - "except_followed" - Mark resolved-topic notices as read in topics not followed by the user.+ - "never" - Never mark resolved-topic notices as read.++ **Changes**: New in Zulip 11.0 (feature level 385).+ type: string+ enum:+ - always+ - except_followed+ - never+ example: except_followedpresence_enabled:description: |Display the presence status to other users when online.@@ -16401,6 +16416,16 @@ paths:topics where the user is mentioned.**Changes**: New in Zulip 8.0 (feature level 235).+ resolved_topic_notice_auto_read_policy:+ type: string+ description: |+ Controls whether the resolved-topic notices are marked as read.++ - "always" - Always mark resolved-topic notices as read.+ - "except_followed" - Mark resolved-topic notices as read in topics not followed by the user.+ - "never" - Never mark resolved-topic notices as read.++ **Changes**: New in Zulip 11.0 (feature level 385).presence_enabled:type: booleandescription: |@@ -19129,6 +19154,16 @@ paths:topics where the user is mentioned.**Changes**: New in Zulip 8.0 (feature level 235).+ resolved_topic_notice_auto_read_policy:+ type: string+ description: |+ Controls whether the resolved-topic notices are marked as read.++ - "always" - Always mark resolved-topic notices as read.+ - "except_followed" - Mark resolved-topic notices as read in topics not followed by the user.+ - "never" - Never mark resolved-topic notices as read.++ **Changes**: New in Zulip 11.0 (feature level 385).presence_enabled:type: booleandescription: |@@ -20491,6 +20526,21 @@ paths:**Changes**: New in Zulip 8.0 (feature level 235).type: booleanexample: true+ resolved_topic_notice_auto_read_policy:+ description: |+ Controls whether the resolved-topic notices are marked as read.++ - "always" - Always mark resolved-topic notices as read.+ - "except_followed" - Mark resolved-topic notices as read in topics not followed by the user.+ - "never" - Never mark resolved-topic notices as read.++ **Changes**: New in Zulip 11.0 (feature level 385).+ type: string+ enum:+ - always+ - except_followed+ - never+ example: except_followedpresence_enabled:description: |Display the presence status to other users when online.diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.pyindex 12a90c3c94f..abe3be90d1b 100644--- a/zerver/tests/test_audit_log.py+++ b/zerver/tests/test_audit_log.py@@ -1,4 +1,5 @@from datetime import timedelta+from enum import Enumfrom typing import Anyfrom django.contrib.auth.password_validation import validate_password@@ -94,6 +95,7 @@ from zerver.models.realm_emoji import EmojiInfo, get_all_custom_emoji_for_realmfrom zerver.models.realm_playgrounds import get_realm_playgroundsfrom zerver.models.realms import RealmDomainDict, get_realm, get_realm_domainsfrom zerver.models.streams import get_stream+from zerver.models.users import ResolvedTopicNoticeAutoReadPolicyEnumclass TestRealmAuditLog(ZulipTestCase):@@ -817,13 +819,14 @@ class TestRealmAuditLog(ZulipTestCase):def test_change_user_settings(self) -> None:user = self.example_user("hamlet")- value: bool | int | str- test_values = dict(+ value: bool | int | str | Enum+ test_values: dict[str, Any] = dict(default_language="de",web_animate_image_previews="on_hover",web_home_view="all_messages",emojiset="twitter",notification_sound="ding",+ resolved_topic_notice_auto_read_policy=ResolvedTopicNoticeAutoReadPolicyEnum.always,)for setting, setting_type in user.property_types.items():@@ -837,9 +840,13 @@ class TestRealmAuditLog(ZulipTestCase):old_value = getattr(user, setting)do_change_user_setting(user, setting, value, acting_user=user)+ if isinstance(value, Enum):+ new_value = value.value+ else:+ new_value = valueexpected_extra_data = {RealmAuditLog.OLD_VALUE: old_value,- RealmAuditLog.NEW_VALUE: value,+ RealmAuditLog.NEW_VALUE: new_value,"property": setting,}self.assertEqual(@@ -853,7 +860,7 @@ class TestRealmAuditLog(ZulipTestCase):).count(),1,)- self.assertEqual(getattr(user, setting), value)+ self.assertEqual(getattr(user, setting), new_value)def test_realm_domain_entries(self) -> None:user = self.example_user("iago")diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex ea3354fe3be..c76330f4dab 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -4538,6 +4538,7 @@ class RealmPropertyActionTest(BaseAction):realm_name_in_email_notifications_policy=UserProfile.REALM_NAME_IN_EMAIL_NOTIFICATIONS_POLICY_CHOICES,automatically_follow_topics_policy=UserProfile.AUTOMATICALLY_CHANGE_VISIBILITY_POLICY_CHOICES,automatically_unmute_topics_in_muted_streams_policy=UserProfile.AUTOMATICALLY_CHANGE_VISIBILITY_POLICY_CHOICES,+ resolved_topic_notice_auto_read_policy=UserProfile.RESOLVED_TOPIC_NOTICE_AUTO_READ_POLICY_TYPES,)vals = test_values.get(name)@@ -4574,7 +4575,12 @@ class RealmPropertyActionTest(BaseAction):acting_user=self.user_profile,)- old_value = vals[count]+ if isinstance(val, Enum):+ old_value = vals[count].value+ new_value = val.value+ else:+ old_value = vals[count]+ new_value = valself.assertEqual(RealmAuditLog.objects.filter(realm=self.user_profile.realm,@@ -4583,7 +4589,7 @@ class RealmPropertyActionTest(BaseAction):acting_user=self.user_profile,extra_data={RealmAuditLog.OLD_VALUE: old_value,- RealmAuditLog.NEW_VALUE: val,+ RealmAuditLog.NEW_VALUE: new_value,"property": name,},).count(),@@ -4665,6 +4671,7 @@ class UserDisplayActionTest(BaseAction):web_line_height_percent=[105, 120, 160],color_scheme=[2, 3, 1],email_address_visibility=[5, 4, 1, 2, 3],+ resolved_topic_notice_auto_read_policy=UserProfile.RESOLVED_TOPIC_NOTICE_AUTO_READ_POLICY_TYPES,)user_settings_object = Truediff --git a/zerver/tests/test_message_move_topic.py b/zerver/tests/test_message_move_topic.pyindex bec0072ba7d..0342ea32214 100644--- a/zerver/tests/test_message_move_topic.py+++ b/zerver/tests/test_message_move_topic.py@@ -20,11 +20,12 @@ from zerver.actions.realm_settings import (do_set_realm_property,)from zerver.actions.user_groups import check_add_user_group+from zerver.actions.user_settings import do_change_user_settingfrom zerver.actions.user_topics import do_set_user_topic_visibility_policyfrom zerver.lib.message import truncate_topicfrom zerver.lib.test_classes import ZulipTestCase, get_topic_messagesfrom zerver.lib.timestamp import datetime_to_timestamp-from zerver.lib.topic import RESOLVED_TOPIC_PREFIX, messages_for_topic+from zerver.lib.topic import RESOLVED_TOPIC_PREFIXfrom zerver.lib.types import StreamMessageEditRequestfrom zerver.lib.user_topics import (get_users_with_user_topic_visibility_policy,@@ -36,6 +37,7 @@ from zerver.models import Message, UserMessage, UserProfile, UserTopicfrom zerver.models.constants import MAX_TOPIC_NAME_LENGTHfrom zerver.models.groups import NamedUserGroup, SystemGroupsfrom zerver.models.streams import Stream+from zerver.models.users import ResolvedTopicNoticeAutoReadPolicyEnumclass MessageMoveTopicTest(ZulipTestCase):@@ -1665,13 +1667,6 @@ class MessageMoveTopicTest(ZulipTestCase):f"@_**Iago|{admin_user.id}** has marked this topic as resolved.",)- # Check topic resolved notification message is only unread for participants.- unread_user_ids = self.get_user_ids_for_whom_message_unread(messages[2].id)- self.assertEqual(unread_user_ids, {admin_user.id, hamlet.id, aaron.id})-- read_user_ids = self.get_user_ids_for_whom_message_read(messages[2].id)- self.assertEqual(read_user_ids, {cordelia.id})-# Now move to a weird state and confirm we get the normal topic moved message.weird_topic_name = "✔ ✔✔" + original_topic_nameresult = self.client_patch(@@ -1728,12 +1723,154 @@ class MessageMoveTopicTest(ZulipTestCase):f"@_**Iago|{admin_user.id}** has marked this topic as unresolved.",)- # Check topic unresolved notification message is only unread for participants.- unread_user_ids = self.get_user_ids_for_whom_message_unread(messages[4].id)- self.assertEqual(unread_user_ids, {admin_user.id, hamlet.id, aaron.id})+ def test_resolved_topic_notice_auto_read_policy(self) -> None:+ # Test that resolved and unresolved-topic notices are marked as+ # read/unread based on the 'resolved_topic_notice_auto_read_policy'+ # setting for followed and unfollowed topics.+ self.login("iago")+ admin_user = self.example_user("iago")+ aaron = self.example_user("aaron")+ cordelia = self.example_user("cordelia")+ hamlet = self.example_user("hamlet")++ do_change_user_setting(+ aaron,+ "resolved_topic_notice_auto_read_policy",+ ResolvedTopicNoticeAutoReadPolicyEnum.always,+ acting_user=None,+ )+ do_change_user_setting(+ cordelia,+ "resolved_topic_notice_auto_read_policy",+ ResolvedTopicNoticeAutoReadPolicyEnum.except_followed,+ acting_user=None,+ )+ do_change_user_setting(+ hamlet,+ "resolved_topic_notice_auto_read_policy",+ ResolvedTopicNoticeAutoReadPolicyEnum.never,+ acting_user=None,+ )++ stream = self.make_stream("stream")+ self.subscribe(admin_user, stream.name)+ self.subscribe(aaron, stream.name)+ self.subscribe(cordelia, stream.name)+ self.subscribe(hamlet, stream.name)++ followed_topic_name = "followed"+ msg_id_1 = self.send_stream_message(admin_user, "stream", topic_name=followed_topic_name)++ do_set_user_topic_visibility_policy(+ aaron,+ stream,+ followed_topic_name,+ visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED,+ )+ do_set_user_topic_visibility_policy(+ cordelia,+ stream,+ followed_topic_name,+ visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED,+ )+ do_set_user_topic_visibility_policy(+ hamlet,+ stream,+ followed_topic_name,+ visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED,+ )++ resolved_followed_topic_name = RESOLVED_TOPIC_PREFIX + followed_topic_name+ result_1 = self.resolve_topic_containing_message(+ admin_user,+ msg_id_1,+ )+ self.assert_json_success(result_1)+ msg_1 = Message.objects.get(id=msg_id_1)+ self.assertEqual(resolved_followed_topic_name, msg_1.topic_name())++ messages = get_topic_messages(admin_user, stream, resolved_followed_topic_name)+ self.assert_length(messages, 2)++ unread_user_ids = self.get_user_ids_for_whom_message_unread(messages[1].id)+ read_user_ids = self.get_user_ids_for_whom_message_read(messages[1].id)++ # For the resolved-topic notice in a "followed" topic:+ # - aaron: policy 'always' -> notice is marked as read.+ # - cordelia: policy 'except_followed' and is following -> notice remains unread.+ # - hamlet: policy 'never' -> notice is remains unread.+ # - admin_user: is the one who resolved the topic -> notice is marked as read.+ self.assertEqual(unread_user_ids, {hamlet.id, cordelia.id})+ self.assertEqual(read_user_ids, {aaron.id, admin_user.id})++ unfollowed_topic_name = "unfollowed"+ msg_id_2 = self.send_stream_message(admin_user, "stream", topic_name=unfollowed_topic_name)+ resolved_unfollowed_topic_name = RESOLVED_TOPIC_PREFIX + unfollowed_topic_name+ result_2 = self.resolve_topic_containing_message(+ admin_user,+ msg_id_2,+ )+ self.assert_json_success(result_2)+ msg_2 = Message.objects.get(id=msg_id_2)+ self.assertEqual(resolved_unfollowed_topic_name, msg_2.topic_name())++ messages = get_topic_messages(admin_user, stream, resolved_unfollowed_topic_name)+ self.assert_length(messages, 2)++ unread_user_ids = self.get_user_ids_for_whom_message_unread(messages[1].id)+ read_user_ids = self.get_user_ids_for_whom_message_read(messages[1].id)++ # For the resolved-topic notice in an "unfollowed" topic:+ # - aaron: policy 'always' -> notice is marked as read.+ # - cordelia: policy 'except_followed' but not following -> notice is marked as read.+ # - hamlet: policy 'never' -> notice remains unread.+ # - admin_user: is the one who resolved the topic -> notice is marked as read.+ self.assertEqual(unread_user_ids, {hamlet.id})+ self.assertEqual(read_user_ids, {aaron.id, cordelia.id, admin_user.id})++ result_3 = self.client_patch(+ "/json/messages/" + str(msg_id_1),+ {+ "topic": followed_topic_name,+ "propagate_mode": "change_all",+ },+ )+ self.assert_json_success(result_3)+ msg_3 = Message.objects.get(id=msg_id_1)+ self.assertEqual(followed_topic_name, msg_3.topic_name())++ messages = get_topic_messages(admin_user, stream, followed_topic_name)+ self.assert_length(messages, 3)++ unread_user_ids = self.get_user_ids_for_whom_message_unread(messages[2].id)+ read_user_ids = self.get_user_ids_for_whom_message_read(messages[2].id)++ # Unresolved-topic notices in a "followed" topic+ # behave similar to resolved-topic notices.+ self.assertEqual(unread_user_ids, {hamlet.id, cordelia.id})+ self.assertEqual(read_user_ids, {aaron.id, admin_user.id})++ result_4 = self.client_patch(+ "/json/messages/" + str(msg_id_2),+ {+ "topic": unfollowed_topic_name,+ "propagate_mode": "change_all",+ },+ )+ self.assert_json_success(result_4)+ msg_4 = Message.objects.get(id=msg_id_2)+ self.assertEqual(unfollowed_topic_name, msg_4.topic_name())++ messages = get_topic_messages(admin_user, stream, unfollowed_topic_name)+ self.assert_length(messages, 3)++ unread_user_ids = self.get_user_ids_for_whom_message_unread(messages[2].id)+ read_user_ids = self.get_user_ids_for_whom_message_read(messages[2].id)- read_user_ids = self.get_user_ids_for_whom_message_read(messages[4].id)- self.assertEqual(read_user_ids, {cordelia.id})+ # Unresolved-topic notices in an "unfollowed" topic+ # behave similar to resolved-topic notices.+ self.assertEqual(unread_user_ids, {hamlet.id})+ self.assertEqual(read_user_ids, {aaron.id, cordelia.id, admin_user.id})@override_settings(RESOLVE_TOPIC_UNDO_GRACE_PERIOD_SECONDS=60)def test_mark_topic_as_resolved_within_grace_period(self) -> None:@@ -1847,7 +1984,6 @@ class MessageMoveTopicTest(ZulipTestCase):do_delete_messages(admin_user.realm, [message], acting_user=None)assert stream.recipient_id is not None- changed_messages = messages_for_topic(stream.realm_id, stream.recipient_id, original_topic)resolve_topic = RESOLVED_TOPIC_PREFIX + original_topicmessage_edit_request = build_message_edit_request(message=message,@@ -1861,7 +1997,7 @@ class MessageMoveTopicTest(ZulipTestCase):maybe_send_resolve_topic_notifications(user_profile=admin_user,message_edit_request=message_edit_request,- changed_messages=changed_messages,+ users_following_topic=None,)topic_messages = get_topic_messages(admin_user, stream, resolve_topic)diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.pyindex 4679b2b071f..23681b4ae0c 100644--- a/zerver/tests/test_realm.py+++ b/zerver/tests/test_realm.py@@ -1909,6 +1909,15 @@ class RealmAPITest(ZulipTestCase):super().setUp()self.login("desdemona")+ def process_value_for_enum_settings(self, raw_value: Any) -> tuple[Any, Any]:+ if isinstance(raw_value, Enum):+ api_value = raw_value.name+ value = raw_value.value+ else:+ api_value = raw_value+ value = raw_value+ return (api_value, value)+def update_with_api(self, name: str, value: int | str) -> Realm:if not isinstance(value, str):value = orjson.dumps(value).decode()@@ -1967,22 +1976,14 @@ class RealmAPITest(ZulipTestCase):do_set_realm_property(get_realm("zulip"), name, vals[0], acting_user=None)- if isinstance(vals[0], Enum):- for val in vals[1:]:- raw_value = val.name- value = val.value- realm = self.update_with_api(name, raw_value)- self.assertEqual(getattr(realm, name), value)- realm = self.update_with_api(name, vals[0].name)- self.assertEqual(getattr(realm, name), vals[0].value)- return-for val in vals[1:]:- realm = self.update_with_api(name, val)- self.assertEqual(getattr(realm, name), val)+ api_value, value = self.process_value_for_enum_settings(val)+ realm = self.update_with_api(name, api_value)+ self.assertEqual(getattr(realm, name), value)- realm = self.update_with_api(name, vals[0])- self.assertEqual(getattr(realm, name), vals[0])+ api_value, value = self.process_value_for_enum_settings(vals[0])+ realm = self.update_with_api(name, api_value)+ self.assertEqual(getattr(realm, name), value)def do_test_realm_permission_group_setting_update_api(self, setting_name: str) -> None:realm = get_realm("zulip")@@ -2367,6 +2368,7 @@ class RealmAPITest(ZulipTestCase):automatically_follow_topics_policy=UserProfile.AUTOMATICALLY_CHANGE_VISIBILITY_POLICY_CHOICES,automatically_unmute_topics_in_muted_streams_policy=UserProfile.AUTOMATICALLY_CHANGE_VISIBILITY_POLICY_CHOICES,automatically_follow_topics_where_mentioned=[True, False],+ resolved_topic_notice_auto_read_policy=UserProfile.RESOLVED_TOPIC_NOTICE_AUTO_READ_POLICY_TYPES,)vals = test_values.get(name)@@ -2383,13 +2385,15 @@ class RealmAPITest(ZulipTestCase):do_set_realm_user_default_setting(realm_user_default, name, vals[0], acting_user=None)for val in vals[1:]:- self.update_with_realm_default_api(name, val)+ api_value, value = self.process_value_for_enum_settings(val)+ self.update_with_realm_default_api(name, api_value)realm_user_default = RealmUserDefault.objects.get(realm=realm)- self.assertEqual(getattr(realm_user_default, name), val)+ self.assertEqual(getattr(realm_user_default, name), value)- self.update_with_realm_default_api(name, vals[0])+ api_value, value = self.process_value_for_enum_settings(vals[0])+ self.update_with_realm_default_api(name, api_value)realm_user_default = RealmUserDefault.objects.get(realm=realm)- self.assertEqual(getattr(realm_user_default, name), vals[0])+ self.assertEqual(getattr(realm_user_default, name), value)def test_update_default_realm_settings(self) -> None:for prop in RealmUserDefault.property_types:@@ -2486,6 +2490,13 @@ class RealmAPITest(ZulipTestCase):result, "Invalid emojiset: Value error, Not in the list of possible values")+ def test_invalid_resolved_topic_notice_auto_read_policy(self) -> None:+ result = self.client_patch(+ "/json/realm/user_settings_defaults",+ {"resolved_topic_notice_auto_read_policy": "invalid"},+ )+ self.assert_json_error(result, "Invalid resolved_topic_notice_auto_read_policy")+def test_ignored_parameters_in_realm_default_endpoint(self) -> None:params = {"starred_message_counts": orjson.dumps(False).decode(), "emoji_set": "twitter"}result = self.client_patch("/json/realm/user_settings_defaults", params)diff --git a/zerver/tests/test_settings.py b/zerver/tests/test_settings.pyindex 52e39942275..d4f86219b8f 100644--- a/zerver/tests/test_settings.py+++ b/zerver/tests/test_settings.py@@ -12,7 +12,7 @@ from zerver.lib.test_classes import ZulipTestCasefrom zerver.lib.test_helpers import get_test_image_file, ratelimit_rulefrom zerver.models import Draft, ScheduledMessageNotificationEmail, UserProfilefrom zerver.models.scheduled_jobs import NotificationTriggers-from zerver.models.users import get_user_profile_by_api_key+from zerver.models.users import ResolvedTopicNoticeAutoReadPolicyEnum, get_user_profile_by_api_keyif TYPE_CHECKING:from django.test.client import _MonkeyPatchedWSGIResponse as TestHttpResponse@@ -374,6 +374,7 @@ class ChangeSettingsTest(ZulipTestCase):realm_name_in_email_notifications_policy=2,automatically_follow_topics_policy=1,automatically_unmute_topics_in_muted_streams_policy=1,+ resolved_topic_notice_auto_read_policy=ResolvedTopicNoticeAutoReadPolicyEnum.always.name,)self.login("hamlet")@@ -397,6 +398,8 @@ class ChangeSettingsTest(ZulipTestCase):result = self.client_patch("/json/settings", data)self.assert_json_success(result)user_profile = self.example_user("hamlet")+ if setting_name == "resolved_topic_notice_auto_read_policy":+ test_value = ResolvedTopicNoticeAutoReadPolicyEnum.always.valueself.assertEqual(getattr(user_profile, setting_name), test_value)def test_change_user_setting(self) -> None:@@ -475,6 +478,11 @@ class ChangeSettingsTest(ZulipTestCase):"value": 10,"error_msg": "Invalid desktop_icon_count_display: Value error, Not in the list of possible values",},+ {+ "setting_name": "resolved_topic_notice_auto_read_policy",+ "value": "invalid",+ "error_msg": "Invalid resolved_topic_notice_auto_read_policy",+ },]self.login("hamlet")for invalid_value in invalid_values:diff --git a/zerver/views/realm.py b/zerver/views/realm.pyindex 9aec990855a..406038ac7a9 100644--- a/zerver/views/realm.py+++ b/zerver/views/realm.py@@ -57,6 +57,7 @@ from zerver.models.realms import (MessageEditHistoryVisibilityPolicyEnum,OrgTypeEnum,)+from zerver.models.users import ResolvedTopicNoticeAutoReadPolicyEnumfrom zerver.views.user_settings import check_settings_values@@ -696,6 +697,16 @@ def update_realm_user_settings_defaults(web_navigate_to_sent_message: Json[bool] | None = None,web_suggest_update_timezone: Json[bool] | None = None,hide_ai_features: Json[bool] | None = None,+ resolved_topic_notice_auto_read_policy: Annotated[+ str | None,+ AfterValidator(+ lambda val: parse_enum_from_string_value(+ val,+ "resolved_topic_notice_auto_read_policy",+ ResolvedTopicNoticeAutoReadPolicyEnum,+ )+ ),+ ] = None,) -> HttpResponse:if notification_sound is not None or email_notifications_batching_period_seconds is not None:check_settings_values(notification_sound, email_notifications_batching_period_seconds)diff --git a/zerver/views/user_settings.py b/zerver/views/user_settings.pyindex 481e8a6c4a5..3fd8d66a454 100644--- a/zerver/views/user_settings.py+++ b/zerver/views/user_settings.py@@ -14,6 +14,7 @@ from django.utils.safestring import SafeStringfrom django.utils.translation import gettext as _from django.utils.translation import gettext_lazyfrom pydantic import Json+from pydantic.functional_validators import AfterValidatorfrom confirmation.models import (Confirmation,@@ -48,11 +49,13 @@ from zerver.lib.typed_endpoint import typed_endpoint, typed_endpoint_without_parfrom zerver.lib.typed_endpoint_validators import (check_int_in_validator,check_string_in_validator,+ parse_enum_from_string_value,timezone_validator,)from zerver.lib.upload import upload_avatar_imagefrom zerver.models import EmailChangeStatus, UserProfilefrom zerver.models.realms import avatar_changes_disabled, name_changes_disabled+from zerver.models.users import ResolvedTopicNoticeAutoReadPolicyEnumfrom zerver.views.auth import redirect_to_deactivation_noticefrom zproject.backends import check_password_strength, email_belongs_to_ldap@@ -307,6 +310,16 @@ def json_change_settings(web_navigate_to_sent_message: Json[bool] | None = None,web_suggest_update_timezone: Json[bool] | None = None,hide_ai_features: Json[bool] | None = None,+ resolved_topic_notice_auto_read_policy: Annotated[+ str | None,+ AfterValidator(+ lambda val: parse_enum_from_string_value(+ val,+ "resolved_topic_notice_auto_read_policy",+ ResolvedTopicNoticeAutoReadPolicyEnum,+ )+ ),+ ] = None,) -> HttpResponse:# UserProfile object is being refetched here to make sure that we# do not use stale object from cache which can happen when a