Repository: zulip/zulip

Issue:
Add option for followed topics to unread count badge setting
<!-- Issue description -->

As [suggested in the Rust community](https://rust-lang.zulipchat.com/#narrow/stream/122653-zulip/topic/.22Follow.20Topic.22.20feature/near/400008533), we should add a new unread count badge option (in SETTINGS / NOTIFICATIONS > Desktop message notifications) for including followed topics but not others. Specifically, let's have the options be:

- All unread messages
- DMs and mentions
- DMs, mentions, and followed topics
- None

(Some existing options are relabeled for clarity/consisency.)



Discussion:
Hello @zulip/server-settings members, this issue was labeled with the "area: settings (user)" label, so you may want to check it out!

<!-- areaLabelAddition -->

@prakhar1144 Adding this to your 8.0 list. Please flag if it turns out to be tricky!
@prakhar1144 We noticed that you have not made any updates to this issue or linked PRs for 10 days. Please comment here if you are still actively working on it. Otherwise, we'd appreciate a quick `@zulipbot abandon` comment so that someone else can claim this issue and continue from where you left off.

If we don't hear back, you will be automatically unassigned in 4 days. Thanks!

<!-- inactiveWarning -->

In progress

Resolving patch:
diff --git a/version.py b/version.py
--- a/version.py
+++ b/version.py
@@ -33,7 +33,7 @@
 # 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 = 226
+API_FEATURE_LEVEL = 227
 
 # 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/0490_renumber_options_desktop_icon_count_display.py b/zerver/migrations/0490_renumber_options_desktop_icon_count_display.py
new file mode 100644
--- /dev/null
+++ b/zerver/migrations/0490_renumber_options_desktop_icon_count_display.py
@@ -0,0 +1,64 @@
+# Generated by Django 4.2.7 on 2023-11-17 04:55
+
+from django.db import migrations
+from django.db.backends.base.schema import BaseDatabaseSchemaEditor
+from django.db.migrations.state import StateApps
+
+OLD_DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION = 2
+NEW_DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION = 3
+OLD_DESKTOP_ICON_COUNT_DISPLAY_NONE = 3
+NEW_DESKTOP_ICON_COUNT_DISPLAY_NONE = 4
+
+
+def renumber_options(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
+    # We added a new option 'DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION_FOLLOWED_TOPIC'
+    # for 'desktop_icon_count_display' setting. It has the value 2.
+    # The following options are renumbered:
+    # * 'DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION' from 2 to 3
+    # * 'DESKTOP_ICON_COUNT_DISPLAY_NONE' from 3 to 4
+    # The migration is to update these values.
+    RealmUserDefault = apps.get_model("zerver", "RealmUserDefault")
+    UserProfile = apps.get_model("zerver", "UserProfile")
+
+    UserProfile.objects.filter(
+        desktop_icon_count_display=OLD_DESKTOP_ICON_COUNT_DISPLAY_NONE
+    ).update(desktop_icon_count_display=NEW_DESKTOP_ICON_COUNT_DISPLAY_NONE)
+    RealmUserDefault.objects.filter(
+        desktop_icon_count_display=OLD_DESKTOP_ICON_COUNT_DISPLAY_NONE
+    ).update(desktop_icon_count_display=NEW_DESKTOP_ICON_COUNT_DISPLAY_NONE)
+
+    UserProfile.objects.filter(
+        desktop_icon_count_display=OLD_DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION
+    ).update(desktop_icon_count_display=NEW_DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION)
+    RealmUserDefault.objects.filter(
+        desktop_icon_count_display=OLD_DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION
+    ).update(desktop_icon_count_display=NEW_DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION)
+
+
+def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
+    RealmUserDefault = apps.get_model("zerver", "RealmUserDefault")
+    UserProfile = apps.get_model("zerver", "UserProfile")
+
+    UserProfile.objects.filter(
+        desktop_icon_count_display=NEW_DESKTOP_ICON_COUNT_DISPLAY_NONE
+    ).update(desktop_icon_count_display=OLD_DESKTOP_ICON_COUNT_DISPLAY_NONE)
+    RealmUserDefault.objects.filter(
+        desktop_icon_count_display=NEW_DESKTOP_ICON_COUNT_DISPLAY_NONE
+    ).update(desktop_icon_count_display=OLD_DESKTOP_ICON_COUNT_DISPLAY_NONE)
+
+    UserProfile.objects.filter(
+        desktop_icon_count_display=NEW_DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION
+    ).update(desktop_icon_count_display=OLD_DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION)
+    RealmUserDefault.objects.filter(
+        desktop_icon_count_display=NEW_DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION
+    ).update(desktop_icon_count_display=OLD_DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION)
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ("zerver", "0489_alter_realm_can_access_all_users_group"),
+    ]
+
+    operations = [
+        migrations.RunPython(renumber_options, reverse_code=reverse_code, elidable=True),
+    ]
diff --git a/zerver/models.py b/zerver/models.py
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -1680,11 +1680,13 @@ class UserBaseSettings(models.Model):
     enable_online_push_notifications = models.BooleanField(default=True)
 
     DESKTOP_ICON_COUNT_DISPLAY_MESSAGES = 1
-    DESKTOP_ICON_COUNT_DISPLAY_NOTIFIABLE = 2
-    DESKTOP_ICON_COUNT_DISPLAY_NONE = 3
+    DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION_FOLLOWED_TOPIC = 2
+    DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION = 3
+    DESKTOP_ICON_COUNT_DISPLAY_NONE = 4
     DESKTOP_ICON_COUNT_DISPLAY_CHOICES = [
         DESKTOP_ICON_COUNT_DISPLAY_MESSAGES,
-        DESKTOP_ICON_COUNT_DISPLAY_NOTIFIABLE,
+        DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION,
+        DESKTOP_ICON_COUNT_DISPLAY_DM_MENTION_FOLLOWED_TOPIC,
         DESKTOP_ICON_COUNT_DISPLAY_NONE,
     ]
     desktop_icon_count_display = models.PositiveSmallIntegerField(


Test patch:
diff --git a/web/tests/unread.test.js b/web/tests/unread.test.js
--- a/web/tests/unread.test.js
+++ b/web/tests/unread.test.js
@@ -59,6 +59,9 @@ function test_notifiable_count(home_unread_messages, expected_notifiable_count)
     assert.deepEqual(notifiable_counts, expected_notifiable_count);
     user_settings.desktop_icon_count_display = 3;
     notifiable_counts = unread.get_notifiable_count();
+    assert.deepEqual(notifiable_counts, expected_notifiable_count);
+    user_settings.desktop_icon_count_display = 4;
+    notifiable_counts = unread.get_notifiable_count();
     assert.deepEqual(notifiable_counts, 0);
 }