mirror of https://github.com/zulip/zulip.git
Add per-stream desktop notifications
(imported from commit b4a0576847b3aec1495f017ca9805febe80c9275)
This commit is contained in:
parent
e754479e9c
commit
f6a6a6b220
|
@ -737,7 +737,8 @@ def gather_subscriptions(user_profile):
|
|||
result.append({'name': stream_name,
|
||||
'in_home_view': sub.in_home_view,
|
||||
'invite_only': invite_only,
|
||||
'color': sub.color})
|
||||
'color': sub.color,
|
||||
'notifications': sub.notifications})
|
||||
|
||||
return sorted(result)
|
||||
|
||||
|
|
|
@ -191,6 +191,15 @@ exports.speaking_at_me = function (message) {
|
|||
return found_match;
|
||||
};
|
||||
|
||||
function should_show_notification(message) {
|
||||
return page_params.desktop_notifications_enabled &&
|
||||
browser_desktop_notifications_on() &&
|
||||
(message.type === "private" ||
|
||||
exports.speaking_at_me(message) ||
|
||||
(message.type === "stream" &&
|
||||
subs.receives_notifications(message.display_recipient)));
|
||||
}
|
||||
|
||||
exports.received_messages = function (messages) {
|
||||
var i, title_needs_update = false;
|
||||
if (window_has_focus) {
|
||||
|
@ -201,10 +210,7 @@ exports.received_messages = function (messages) {
|
|||
if (message.sender_email !== page_params.email && narrow.message_in_home(message)) {
|
||||
title_needs_update = true;
|
||||
|
||||
if (page_params.desktop_notifications_enabled &&
|
||||
browser_desktop_notifications_on() &&
|
||||
(message.type === "private" ||
|
||||
exports.speaking_at_me(message))) {
|
||||
if (should_show_notification(message)) {
|
||||
process_desktop_notification(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,6 +182,15 @@ function stream_home_view_clicked(e) {
|
|||
set_stream_property(stream, 'in_home_view', sub.in_home_view);
|
||||
}
|
||||
|
||||
function stream_notifications_clicked(e) {
|
||||
var sub_row = $(e.target).closest('.subscription_row');
|
||||
var stream = sub_row.find('.subscription_name').text();
|
||||
|
||||
var sub = get_sub(stream);
|
||||
sub.notifications = ! sub.notifications;
|
||||
set_stream_property(stream, 'notifications', sub.notifications);
|
||||
}
|
||||
|
||||
function set_color(stream_name, color) {
|
||||
update_stream_color(stream_name, color, {update_historical: true});
|
||||
set_stream_property(stream_name, 'color', color);
|
||||
|
@ -214,7 +223,8 @@ function create_sub(stream_name, attrs) {
|
|||
|
||||
sub = $.extend({}, {name: stream_name, color: pick_color(), id: next_sub_id++,
|
||||
render_subscribers: should_render_subscribers(),
|
||||
subscribed: true, in_home_view: true, invite_only: false}, attrs);
|
||||
subscribed: true, in_home_view: true, invite_only: false,
|
||||
notifications: false}, attrs);
|
||||
|
||||
add_sub(stream_name, sub);
|
||||
if (sub.subscribed) {
|
||||
|
@ -417,6 +427,14 @@ exports.get_invite_only = function (stream_name) {
|
|||
return sub.invite_only;
|
||||
};
|
||||
|
||||
exports.receives_notifications = function (stream_name) {
|
||||
var sub = get_sub(stream_name);
|
||||
if (sub === undefined) {
|
||||
return false;
|
||||
}
|
||||
return sub.notifications;
|
||||
};
|
||||
|
||||
function populate_subscriptions(subs) {
|
||||
var sub_rows = [];
|
||||
subs.sort(function (a, b) {
|
||||
|
@ -425,7 +443,8 @@ function populate_subscriptions(subs) {
|
|||
subs.forEach(function (elem) {
|
||||
var stream_name = elem.name;
|
||||
var sub = create_sub(stream_name, {color: elem.color, in_home_view: elem.in_home_view,
|
||||
invite_only: elem.invite_only, subscribed: true});
|
||||
invite_only: elem.invite_only,
|
||||
notifications: elem.notifications, subscribed: true});
|
||||
add_sub(stream_name, sub);
|
||||
sub_rows.push(sub);
|
||||
});
|
||||
|
@ -734,6 +753,7 @@ $(function () {
|
|||
}
|
||||
});
|
||||
$("#subscriptions_table").on("click", "#sub_setting_in_home_view", stream_home_view_clicked);
|
||||
$("#subscriptions_table").on("click", "#sub_setting_notifications", stream_notifications_clicked);
|
||||
|
||||
if (! should_render_subscribers()) {
|
||||
return;
|
||||
|
|
|
@ -30,6 +30,10 @@
|
|||
<input class="sub_setting_control" type="checkbox" {{#if in_home_view}}checked{{/if}} />
|
||||
Include in home view</div>
|
||||
</li>
|
||||
<li><div id="sub_setting_notifications" class="sub_setting_checkbox">
|
||||
<input class="sub_setting_control" type="checkbox" {{#if notifications}}checked{{/if}} />
|
||||
Show desktop notifications for traffic on this stream
|
||||
</li>
|
||||
<li><span class="sub_setting_control"><input class="colorpicker" type="text" value="{{color}}" /></span>
|
||||
Stream color
|
||||
</li>
|
||||
|
|
|
@ -652,7 +652,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
|||
|
||||
new_subs = gather_subscriptions(self.get_user_profile(test_email))
|
||||
sub = {'name': stream_name, 'in_home_view': True, 'color': new_color,
|
||||
'invite_only': invite_only}
|
||||
'invite_only': invite_only, 'notifications': False}
|
||||
self.assertIn(sub, new_subs)
|
||||
|
||||
new_subs.remove(sub)
|
||||
|
|
|
@ -1150,7 +1150,8 @@ def json_subscription_property(request, user_profile, stream_name=REQ,
|
|||
properties.
|
||||
"""
|
||||
property_converters = dict(color=lambda x: x,
|
||||
in_home_view=json_to_bool)
|
||||
in_home_view=json_to_bool,
|
||||
notifications=json_to_bool)
|
||||
if property not in property_converters:
|
||||
return json_error("Unknown subscription property: %s" % (property,))
|
||||
|
||||
|
|
Loading…
Reference in New Issue