Skip to content
Permalink
Browse files

notifs: Allow only notifiable in unread count

This commit adds a new setting to the user's notification settings that
will change the behaviour of the unread count in the title bar and
desktop application.

When enabled, the title bar will show the count of unread private messages
and mentions. When disabled, the title bar will act as before, showing
the total number of unread messages.
  • Loading branch information...
davidtwco committed Jun 29, 2019
1 parent a1cf77c commit 791b0f70bd9bcfc7c4f33a206acb6fc88c1f16a9
@@ -99,6 +99,7 @@ function setup_settings_label() {
enable_online_push_notifications: i18n.t("Send mobile notifications even if I'm online (useful for testing)"),
enable_sounds: i18n.t("Audible desktop notifications"),
pm_content_in_desktop_notifications: i18n.t("Include content of private messages in desktop notifications"),
desktop_icon_count_display: i18n.t("Only include private messages and @-mentions in unread count"),

// other_notification_settings
enable_digest_emails: i18n.t("Send digest emails when I'm away"),
@@ -18,6 +18,7 @@ var pm_mention_notification_settings = [

var desktop_notification_settings = [
"pm_content_in_desktop_notifications",
"desktop_icon_count_display",
];

var mobile_notification_settings = [
@@ -69,6 +70,17 @@ function change_notification_setting(setting, setting_data, status_element) {
settings_ui.do_settings_change(channel.patch, '/json/settings/notifications', data, status_element);
}

function update_desktop_icon_count_display() {
var only_show_notifiable = page_params.desktop_icon_count_display === 2;
$("#desktop_icon_count_display").prop('checked', only_show_notifiable);
var res = unread.get_counts();
if (only_show_notifiable) { // DESKTOP_ICON_COUNT_DISPLAY_NOTIFIABLE
notifications.update_title_count(res.mentioned_message_count + res.private_message_count);
} else { // DESKTOP_ICON_COUNT_DISPLAY_MESSAGES
notifications.update_title_count(res.home_unread_messages);
}
}

exports.set_enable_digest_emails_visibility = function () {
if (page_params.realm_digest_emails_enabled) {
$('#enable_digest_emails_label').parent().show();
@@ -83,9 +95,11 @@ exports.set_up = function () {
$("#" + sub_setting).change(function () {
var value;

// `notification_sound` and `desktop_icon_count_display` are not booleans.
if (sub_setting === "notification_sound") {
// `notification_sound` is not a boolean.
value = $(this).val();
} else if (sub_setting === "desktop_icon_count_display") {
value = $(this).prop('checked') ? 2 : 1;
} else {
value = $(this).prop('checked');
}
@@ -95,6 +109,8 @@ exports.set_up = function () {
});
});

update_desktop_icon_count_display();

$("#play_notification_sound").click(function () {
$("#notifications-area").find("audio")[0].play();
});
@@ -121,7 +137,11 @@ exports.update_page = function () {
// If push notifications are disabled at the realm level,
// we should just leave the checkbox always off.
return;
} else if (setting === 'desktop_icon_count_display') {
update_desktop_icon_count_display();
return;
}

$("#" + setting).prop('checked', page_params[setting]);
});
};
@@ -53,9 +53,14 @@ exports.update_unread_counts = function () {
top_left_corner.update_dom_with_unread_counts(res);
stream_list.update_dom_with_unread_counts(res);
pm_list.update_dom_with_unread_counts(res);
notifications.update_title_count(res.home_unread_messages);
notifications.update_pm_count(res.private_message_count);

if (page_params.desktop_icon_count_display === 2) { // DESKTOP_ICON_COUNT_DISPLAY_NOTIFIABLE
notifications.update_title_count(res.mentioned_message_count + res.private_message_count);
} else { // DESKTOP_ICON_COUNT_DISPLAY_MESSAGES
notifications.update_title_count(res.home_unread_messages);
}

exports.set_count_toggle_button($("#streamlist-toggle-unreadcount"),
res.home_unread_messages);

@@ -3668,8 +3668,8 @@ def do_create_realm(string_id: str, name: str,
"signups", realm.display_subdomain, signup_message)
return realm

def do_change_notification_settings(user_profile: UserProfile, name: str, value: Union[bool, str],
log: bool=True) -> None:
def do_change_notification_settings(user_profile: UserProfile, name: str,
value: Union[bool, int, str], log: bool=True) -> None:
"""Takes in a UserProfile object, the name of a global notification
preference to update, and the value to update to
"""
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-06-29 18:22
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('zerver', '0231_add_archive_transaction_model'),
]

operations = [
migrations.AddField(
model_name='userprofile',
name='desktop_icon_count_display',
field=models.PositiveSmallIntegerField(default=1),
),
]
@@ -850,6 +850,11 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
enable_offline_push_notifications = models.BooleanField(default=True) # type: bool
enable_online_push_notifications = models.BooleanField(default=False) # type: bool

DESKTOP_ICON_COUNT_DISPLAY_MESSAGES = 1
DESKTOP_ICON_COUNT_DISPLAY_NOTIFIABLE = 2
desktop_icon_count_display = models.PositiveSmallIntegerField(
default=DESKTOP_ICON_COUNT_DISPLAY_MESSAGES) # type: int

enable_digest_emails = models.BooleanField(default=True) # type: bool
enable_login_emails = models.BooleanField(default=True) # type: bool
realm_name_in_notifications = models.BooleanField(default=False) # type: bool
@@ -980,6 +985,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
message_content_in_email_notifications=bool,
notification_sound=str,
pm_content_in_desktop_notifications=bool,
desktop_icon_count_display=int,
realm_name_in_notifications=bool,
)

@@ -1871,8 +1871,8 @@ def test_set_user_display_settings(self) -> None:
@slow("Actually runs several full-stack fetching tests")
def test_change_notification_settings(self) -> None:
for notification_setting, v in self.user_profile.notification_setting_types.items():
if notification_setting == "notification_sound":
# notification_sound is tested in its own test
if notification_setting in ["notification_sound", "desktop_icon_count_display"]:
# These settings are tested in their own tests.
continue

schema_checker = self.check_events_dict([
@@ -1912,6 +1912,32 @@ def test_change_notification_sound(self) -> None:
error = schema_checker('events[0]', events[0])
self.assert_on_error(error)

def test_change_desktop_icon_count_display(self) -> None:
notification_setting = "desktop_icon_count_display"
schema_checker = self.check_events_dict([
('type', equals('update_global_notifications')),
('notification_name', equals(notification_setting)),
('user', check_string),
('setting', equals(2)),
])

events = self.do_test(lambda: do_change_notification_settings(
self.user_profile, notification_setting, 2, log=False))
error = schema_checker('events[0]', events[0])
self.assert_on_error(error)

schema_checker = self.check_events_dict([
('type', equals('update_global_notifications')),
('notification_name', equals(notification_setting)),
('user', check_string),
('setting', equals(1)),
])

events = self.do_test(lambda: do_change_notification_settings(
self.user_profile, notification_setting, 1, log=False))
error = schema_checker('events[0]', events[0])
self.assert_on_error(error)

def test_realm_update_plan_type(self) -> None:
realm = self.user_profile.realm

@@ -62,6 +62,7 @@ def test_home(self) -> None:
"delivery_email",
"demote_inactive_streams",
"dense_mode",
"desktop_icon_count_display",
"development_environment",
"email",
"emojiset",
@@ -172,6 +172,7 @@ def json_change_notify_settings(
enable_login_emails: Optional[bool]=REQ(validator=check_bool, default=None),
message_content_in_email_notifications: Optional[bool]=REQ(validator=check_bool, default=None),
pm_content_in_desktop_notifications: Optional[bool]=REQ(validator=check_bool, default=None),
desktop_icon_count_display: Optional[int]=REQ(validator=check_int, default=None),
realm_name_in_notifications: Optional[bool]=REQ(validator=check_bool, default=None)
) -> HttpResponse:
result = {}

0 comments on commit 791b0f7

Please sign in to comment.
You can’t perform that action at this time.