From afbd0a9b43496f5b1494f4a0fb7ecdcd46aa73da Mon Sep 17 00:00:00 2001 From: Joelute Date: Wed, 5 Apr 2023 15:35:47 -0400 Subject: [PATCH] user_settings: Add web_mark_read_on_scroll_policy field. This is a backend change that will help support the new `Mark messages as read on scroll` user setting. --- api_docs/changelog.md | 7 +++ version.py | 2 +- ..._web_mark_read_on_scroll_policy_setting.py | 22 +++++++ zerver/models.py | 16 +++++ zerver/openapi/zulip.yaml | 62 +++++++++++++++++++ zerver/tests/test_events.py | 2 + zerver/tests/test_realm.py | 1 + zerver/tests/test_settings.py | 9 ++- zerver/views/realm.py | 4 ++ zerver/views/user_settings.py | 4 ++ 10 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 zerver/migrations/0438_add_web_mark_read_on_scroll_policy_setting.py diff --git a/api_docs/changelog.md b/api_docs/changelog.md index 0ab9db84df..ee96913fac 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 7.0 +**Feature level 175** + +* [`POST /register`](/api/register-queue), [`PATCH /settings`](/api/update-settings), + [`PATCH /realm/user_settings_defaults`](/api/update-realm-user-settings-defaults): + Added new user setting `web_mark_read_on_scroll_policy` . This determines whether to mark + messages as read or not as the client scrolls through their feed. + **Feature level 174**: * [`POST /typing`](/api/set-typing-status), [`POST /messages`](/api/send-message): diff --git a/version.py b/version.py index c6ffa74973..5a5698ede3 100644 --- a/version.py +++ b/version.py @@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.4.3" # Changes should be accompanied by documentation explaining what the # new level means in api_docs/changelog.md, as well as "**Changes**" # entries in the endpoint's documentation in `zulip.yaml`. -API_FEATURE_LEVEL = 174 +API_FEATURE_LEVEL = 175 # 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. Bump diff --git a/zerver/migrations/0438_add_web_mark_read_on_scroll_policy_setting.py b/zerver/migrations/0438_add_web_mark_read_on_scroll_policy_setting.py new file mode 100644 index 0000000000..d216d1d698 --- /dev/null +++ b/zerver/migrations/0438_add_web_mark_read_on_scroll_policy_setting.py @@ -0,0 +1,22 @@ +# Generated by Django 4.1.7 on 2023-04-05 01:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("zerver", "0437_remove_realm_authentication_methods"), + ] + + operations = [ + migrations.AddField( + model_name="realmuserdefault", + name="web_mark_read_on_scroll_policy", + field=models.SmallIntegerField(default=1), + ), + migrations.AddField( + model_name="userprofile", + name="web_mark_read_on_scroll_policy", + field=models.SmallIntegerField(default=1), + ), + ] diff --git a/zerver/models.py b/zerver/models.py index 1a89e9288a..f0e25ba51c 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -1574,6 +1574,21 @@ class UserBaseSettings(models.Model): ] demote_inactive_streams = models.PositiveSmallIntegerField(default=DEMOTE_STREAMS_AUTOMATIC) + # UI setting controlling whether or not the Zulip web app will + # mark messages as read as it scrolls through the feed. + + MARK_READ_ON_SCROLL_ALWAYS = 1 + MARK_READ_ON_SCROLL_CONVERSATION_ONLY = 2 + MARK_READ_ON_SCROLL_NEVER = 3 + + WEB_MARK_READ_ON_SCROLL_POLICY_CHOICES = [ + MARK_READ_ON_SCROLL_ALWAYS, + MARK_READ_ON_SCROLL_CONVERSATION_ONLY, + MARK_READ_ON_SCROLL_NEVER, + ] + + web_mark_read_on_scroll_policy = models.SmallIntegerField(default=MARK_READ_ON_SCROLL_ALWAYS) + # Emoji sets GOOGLE_EMOJISET = "google" GOOGLE_BLOB_EMOJISET = "google-blob" @@ -1731,6 +1746,7 @@ class UserBaseSettings(models.Model): send_private_typing_notifications=bool, send_read_receipts=bool, send_stream_typing_notifications=bool, + web_mark_read_on_scroll_policy=int, user_list_style=int, ) diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index 631aa56276..0ca7c28d48 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -9089,6 +9089,25 @@ paths: schema: type: boolean example: true + - name: web_mark_read_on_scroll_policy + in: query + description: | + Whether or not to mark messages as read when the client scrolls through their + feed. + + - 1 - Always + - 2 - Only in conversation views + - 3 - Never + + **Changes**: New in Zulip 7.0 (feature level 175). Previously, the app behaved + like the "Always" setting, without any way to configure this. + schema: + type: integer + enum: + - 1 + - 2 + - 3 + example: 1 - name: color_scheme in: query description: | @@ -11132,6 +11151,18 @@ paths: description: | This setting has no effect at present. It is reserved for use in controlling the default font size in Zulip. + web_mark_read_on_scroll_policy: + type: integer + description: | + Whether or not to mark messages as read when the client scrolls through their + feed. + + - 1 - Always + - 2 - Only in conversation views + - 3 - Never + + **Changes**: New in Zulip 7.0 (feature level 175). Previously, the app behaved + like the "Always" setting, without any way to configure this. starred_message_counts: type: boolean description: | @@ -13085,6 +13116,18 @@ paths: description: | This setting has no effect at present. It is reserved for use in controlling the default font size in Zulip. + web_mark_read_on_scroll_policy: + type: integer + description: | + Whether or not to mark messages as read when the client scrolls through their + feed. + + - 1 - Always + - 2 - Only in conversation views + - 3 - Never + + **Changes**: New in Zulip 7.0 (feature level 175). Previously, the app behaved + like the "Always" setting, without any way to configure this. starred_message_counts: type: boolean description: | @@ -14030,6 +14073,25 @@ paths: schema: type: boolean example: true + - name: web_mark_read_on_scroll_policy + in: query + description: | + Whether or not to mark messages as read when the client scrolls through their + feed. + + - 1 - Always + - 2 - Only in conversation views + - 3 - Never + + **Changes**: New in Zulip 7.0 (feature level 175). Previously, the app behaved + like the "Always" setting, without any way to configure this. + schema: + type: integer + enum: + - 1 + - 2 + - 3 + example: 1 - name: starred_message_counts in: query description: | diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index b7aef969a8..9ec81db229 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -2715,6 +2715,7 @@ class RealmPropertyActionTest(BaseAction): default_view=["recent_topics", "all_messages"], emojiset=[emojiset["key"] for emojiset in RealmUserDefault.emojiset_choices()], demote_inactive_streams=UserProfile.DEMOTE_STREAMS_CHOICES, + web_mark_read_on_scroll_policy=UserProfile.WEB_MARK_READ_ON_SCROLL_POLICY_CHOICES, user_list_style=UserProfile.USER_LIST_STYLE_CHOICES, desktop_icon_count_display=[1, 2, 3], notification_sound=["zulip", "ding"], @@ -2791,6 +2792,7 @@ class UserDisplayActionTest(BaseAction): default_language=["es", "de", "en"], default_view=["all_messages", "recent_topics"], demote_inactive_streams=[2, 3, 1], + web_mark_read_on_scroll_policy=[2, 3, 1], user_list_style=[1, 2, 3], color_scheme=[2, 3, 1], email_address_visibility=[5, 4, 1, 2, 3], diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py index b06b1b2901..8d4a876ea3 100644 --- a/zerver/tests/test_realm.py +++ b/zerver/tests/test_realm.py @@ -1237,6 +1237,7 @@ class RealmAPITest(ZulipTestCase): default_view=["recent_topics", "all_messages"], emojiset=[emojiset["key"] for emojiset in RealmUserDefault.emojiset_choices()], demote_inactive_streams=UserProfile.DEMOTE_STREAMS_CHOICES, + web_mark_read_on_scroll_policy=UserProfile.WEB_MARK_READ_ON_SCROLL_POLICY_CHOICES, user_list_style=UserProfile.USER_LIST_STYLE_CHOICES, desktop_icon_count_display=[1, 2, 3], notification_sound=["zulip", "ding"], diff --git a/zerver/tests/test_settings.py b/zerver/tests/test_settings.py index addecd6eed..5bb56b8c35 100644 --- a/zerver/tests/test_settings.py +++ b/zerver/tests/test_settings.py @@ -356,6 +356,7 @@ class ChangeSettingsTest(ZulipTestCase): emojiset="google", timezone="America/Denver", demote_inactive_streams=2, + web_mark_read_on_scroll_policy=2, user_list_style=2, color_scheme=2, email_notifications_batching_period_seconds=100, @@ -371,7 +372,12 @@ class ChangeSettingsTest(ZulipTestCase): if test_value is None: raise AssertionError(f"No test created for {setting_name}") - if setting_name not in ["demote_inactive_streams", "user_list_style", "color_scheme"]: + if setting_name not in [ + "demote_inactive_streams", + "user_list_style", + "color_scheme", + "web_mark_read_on_scroll_policy", + ]: data = {setting_name: test_value} else: data = {setting_name: orjson.dumps(test_value).decode()} @@ -397,6 +403,7 @@ class ChangeSettingsTest(ZulipTestCase): emojiset="apple", timezone="invalid_US/Mountain", demote_inactive_streams=10, + web_mark_read_on_scroll_policy=10, user_list_style=10, color_scheme=10, notification_sound="invalid_sound", diff --git a/zerver/views/realm.py b/zerver/views/realm.py index 281f85eecc..d9f7668824 100644 --- a/zerver/views/realm.py +++ b/zerver/views/realm.py @@ -398,6 +398,10 @@ def update_realm_user_settings_defaults( request: HttpRequest, user_profile: UserProfile, dense_mode: Optional[bool] = REQ(json_validator=check_bool, default=None), + web_mark_read_on_scroll_policy: Optional[int] = REQ( + json_validator=check_int_in(UserProfile.WEB_MARK_READ_ON_SCROLL_POLICY_CHOICES), + default=None, + ), starred_message_counts: Optional[bool] = REQ(json_validator=check_bool, default=None), fluid_layout_width: Optional[bool] = REQ(json_validator=check_bool, default=None), high_contrast_mode: Optional[bool] = REQ(json_validator=check_bool, default=None), diff --git a/zerver/views/user_settings.py b/zerver/views/user_settings.py index 674ba15110..371b33b193 100644 --- a/zerver/views/user_settings.py +++ b/zerver/views/user_settings.py @@ -155,6 +155,10 @@ def json_change_settings( new_password: Optional[str] = REQ(default=None), twenty_four_hour_time: Optional[bool] = REQ(json_validator=check_bool, default=None), dense_mode: Optional[bool] = REQ(json_validator=check_bool, default=None), + web_mark_read_on_scroll_policy: Optional[int] = REQ( + json_validator=check_int_in(UserProfile.WEB_MARK_READ_ON_SCROLL_POLICY_CHOICES), + default=None, + ), starred_message_counts: Optional[bool] = REQ(json_validator=check_bool, default=None), fluid_layout_width: Optional[bool] = REQ(json_validator=check_bool, default=None), high_contrast_mode: Optional[bool] = REQ(json_validator=check_bool, default=None),