Pass global stream notification settings between frontend and backend.

(imported from commit 28ec021e8e5166d3b270c81c5a4ad543d2185aa5)
This commit is contained in:
Jessica McKellar
2014-02-05 15:41:01 -05:00
parent df39a7bde2
commit c673b3b0b1
4 changed files with 102 additions and 5 deletions

View File

@@ -1084,6 +1084,17 @@ $(function () {
var message = "Updated notification settings!";
var result = $.parseJSON(xhr.responseText);
// Stream notification settings.
if (result.enable_stream_desktop_notifications !== undefined) {
page_params.stream_desktop_notifications_enabled = result.enable_stream_desktop_notifications;
}
if (result.enable_stream_sounds !== undefined) {
page_params.stream_sounds_enabled = result.enable_stream_sounds;
}
// PM and @-mention notification settings.
if (result.enable_desktop_notifications !== undefined) {
page_params.desktop_notifications_enabled = result.enable_desktop_notifications;
}
@@ -1099,6 +1110,8 @@ $(function () {
page_params.enable_offline_push_notifications = result.enable_offline_push_notifications;
}
// Other notification settings.
if (result.enable_digest_emails !== undefined) {
page_params.enable_digest_emails = result.enable_digest_emails;
}

View File

@@ -94,6 +94,43 @@
<div class="settings-section-title"><i class="icon-vector-warning-sign settings-section-icon"></i>Notifications <i class="tiny icon-vector-question-sign" id="notification-docs"></i></div>
<div class="alert" id="notify-settings-status"></div>
<div class="notification-settings-form">
<h4>Stream messages</h4>
<p>Unless I say otherwise for a particular stream, I want:</p>
<div class="control-group">
<div class="controls">
<input type="checkbox" name="enable_stream_desktop_notifications"
id="enable_stream_desktop_notifications"
{% if user_profile.enable_stream_desktop_notifications %}
checked="yes"
{% endif %} />
</div>
<label for="enable_stream_desktop_notifications" class="control-label">
Desktop notifications
</label>
</div>
<div class="control-group">
<div class="controls">
<input type="checkbox" name="enable_stream_sounds" id="enable_stream_sounds"
{% if user_profile.enable_stream_sounds %}
checked="yes"
{% endif %} />
</div>
<label for="enable_stream_sounds" class="control-label">
Audible notifications
</label>
</div>
<p class="notification-settings-note">Change notification settings for
individual streams on your <a href="/#subscriptions">Streams
page</a>.</p>
<h4>Private messages and @-mentions</h4>
<p>I want:</p>
<div class="control-group">
<div class="controls">
<input type="checkbox" name="enable_desktop_notifications" id="enable_desktop_notifications"
@@ -142,6 +179,10 @@
</label>
</div>
<h4>Other notifications</h4>
<p>I want:</p>
<div class="control-group" id="digest_container">
<div class="controls">
<input type="checkbox" name="enable_digest_emails" id="enable_digest_emails"
@@ -154,8 +195,6 @@
</label>
</div>
<p class="notification-settings-note">Change notification settings for individual streams on your <a href="/#subscriptions">Streams page</a>.</p>
<div class="control-group">
<div class="controls notification-submission">
<input type="submit" name="change_settings" value="Save changes" class="btn btn-big btn-primary" />

View File

@@ -1373,6 +1373,24 @@ This is a message on stream `zulip` with the topic `welcome`. We'll use this str
"signups", domain, signup_message)
return (realm, created)
def do_change_enable_stream_desktop_notifications(user_profile,
enable_stream_desktop_notifications,
log=True):
user_profile.enable_stream_desktop_notifications = enable_stream_desktop_notifications
user_profile.save(update_fields=["enable_stream_desktop_notifications"])
if log:
log_event({'type': 'enable_stream_desktop_notifications_changed',
'user': user_profile.email,
'enable_stream_desktop_notifications': enable_stream_desktop_notifications})
def do_change_enable_stream_sounds(user_profile, enable_stream_sounds, log=True):
user_profile.enable_stream_sounds = enable_stream_sounds
user_profile.save(update_fields=["enable_stream_sounds"])
if log:
log_event({'type': 'enable_stream_sounds_changed',
'user': user_profile.email,
'enable_stream_sounds': enable_stream_sounds})
def do_change_enable_desktop_notifications(user_profile, enable_desktop_notifications, log=True):
user_profile.enable_desktop_notifications = enable_desktop_notifications
user_profile.save(update_fields=["enable_desktop_notifications"])

View File

@@ -38,6 +38,7 @@ from zerver.lib.actions import bulk_remove_subscriptions, do_change_password, \
notify_for_streams_by_default, do_change_enable_offline_push_notifications, \
do_deactivate_stream, do_change_autoscroll_forever, do_make_stream_public, \
do_make_stream_private, do_change_default_desktop_notifications, \
do_change_enable_stream_desktop_notifications, do_change_enable_stream_sounds, \
do_change_stream_description, do_update_pointer, do_add_default_stream, do_remove_default_stream
from zerver.lib.create_user import random_api_key
from zerver.lib.push_notifications import num_push_devices_for_user
@@ -879,14 +880,22 @@ def home(request):
needs_tutorial = needs_tutorial,
first_in_realm = first_in_realm,
prompt_for_invites = prompt_for_invites,
desktop_notifications_enabled = desktop_notifications_enabled,
notifications_stream = notifications_stream,
# Stream message notification settings:
stream_desktop_notifications_enabled =
user_profile.enable_stream_desktop_notifications,
stream_sounds_enabled = user_profile.enable_stream_sounds,
# Private message and @-mention notification settings:
desktop_notifications_enabled = desktop_notifications_enabled,
sounds_enabled =
user_profile.enable_sounds,
enable_offline_email_notifications =
user_profile.enable_offline_email_notifications,
enable_offline_push_notifications =
user_profile.enable_offline_push_notifications,
enable_digest_emails = user_profile.enable_digest_emails,
event_queue_id = register_ret['queue_id'],
last_event_id = register_ret['last_event_id'],
@@ -1466,8 +1475,13 @@ def json_change_settings(request, user_profile,
@authenticated_json_post_view
@has_request_variables
def json_change_notify_settings(request, user_profile,
# enable_desktop_notification needs to default to False
# because browsers POST nothing for an unchecked checkbox
# Notifications default to False because
# browsers POST nothing for an unchecked
# checkbox.
enable_stream_desktop_notifications=REQ(converter=lambda x: x == "on",
default=False),
enable_stream_sounds=REQ(converter=lambda x: x == "on",
default=False),
enable_desktop_notifications=REQ(converter=lambda x: x == "on",
default=False),
enable_sounds=REQ(converter=lambda x: x == "on",
@@ -1481,6 +1495,19 @@ def json_change_notify_settings(request, user_profile,
result = {}
# Stream notification settings.
if user_profile.enable_stream_desktop_notifications != enable_stream_desktop_notifications:
do_change_enable_stream_desktop_notifications(
user_profile, enable_stream_desktop_notifications)
result['enable_stream_desktop_notifications'] = enable_stream_desktop_notifications
if user_profile.enable_stream_sounds != enable_stream_sounds:
do_change_enable_stream_sounds(user_profile, enable_stream_sounds)
result['enable_stream_sounds'] = enable_stream_sounds
# PM and @-mention settings.
if user_profile.enable_desktop_notifications != enable_desktop_notifications:
do_change_enable_desktop_notifications(user_profile, enable_desktop_notifications)
result['enable_desktop_notifications'] = enable_desktop_notifications