mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 23:13:25 +00:00
Add per-stream desktop notifications
(imported from commit b4a0576847b3aec1495f017ca9805febe80c9275)
This commit is contained in:
@@ -737,7 +737,8 @@ def gather_subscriptions(user_profile):
|
|||||||
result.append({'name': stream_name,
|
result.append({'name': stream_name,
|
||||||
'in_home_view': sub.in_home_view,
|
'in_home_view': sub.in_home_view,
|
||||||
'invite_only': invite_only,
|
'invite_only': invite_only,
|
||||||
'color': sub.color})
|
'color': sub.color,
|
||||||
|
'notifications': sub.notifications})
|
||||||
|
|
||||||
return sorted(result)
|
return sorted(result)
|
||||||
|
|
||||||
|
|||||||
@@ -191,6 +191,15 @@ exports.speaking_at_me = function (message) {
|
|||||||
return found_match;
|
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) {
|
exports.received_messages = function (messages) {
|
||||||
var i, title_needs_update = false;
|
var i, title_needs_update = false;
|
||||||
if (window_has_focus) {
|
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)) {
|
if (message.sender_email !== page_params.email && narrow.message_in_home(message)) {
|
||||||
title_needs_update = true;
|
title_needs_update = true;
|
||||||
|
|
||||||
if (page_params.desktop_notifications_enabled &&
|
if (should_show_notification(message)) {
|
||||||
browser_desktop_notifications_on() &&
|
|
||||||
(message.type === "private" ||
|
|
||||||
exports.speaking_at_me(message))) {
|
|
||||||
process_desktop_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);
|
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) {
|
function set_color(stream_name, color) {
|
||||||
update_stream_color(stream_name, color, {update_historical: true});
|
update_stream_color(stream_name, color, {update_historical: true});
|
||||||
set_stream_property(stream_name, 'color', color);
|
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++,
|
sub = $.extend({}, {name: stream_name, color: pick_color(), id: next_sub_id++,
|
||||||
render_subscribers: should_render_subscribers(),
|
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);
|
add_sub(stream_name, sub);
|
||||||
if (sub.subscribed) {
|
if (sub.subscribed) {
|
||||||
@@ -417,6 +427,14 @@ exports.get_invite_only = function (stream_name) {
|
|||||||
return sub.invite_only;
|
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) {
|
function populate_subscriptions(subs) {
|
||||||
var sub_rows = [];
|
var sub_rows = [];
|
||||||
subs.sort(function (a, b) {
|
subs.sort(function (a, b) {
|
||||||
@@ -425,7 +443,8 @@ function populate_subscriptions(subs) {
|
|||||||
subs.forEach(function (elem) {
|
subs.forEach(function (elem) {
|
||||||
var stream_name = elem.name;
|
var stream_name = elem.name;
|
||||||
var sub = create_sub(stream_name, {color: elem.color, in_home_view: elem.in_home_view,
|
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);
|
add_sub(stream_name, sub);
|
||||||
sub_rows.push(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_in_home_view", stream_home_view_clicked);
|
||||||
|
$("#subscriptions_table").on("click", "#sub_setting_notifications", stream_notifications_clicked);
|
||||||
|
|
||||||
if (! should_render_subscribers()) {
|
if (! should_render_subscribers()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -30,6 +30,10 @@
|
|||||||
<input class="sub_setting_control" type="checkbox" {{#if in_home_view}}checked{{/if}} />
|
<input class="sub_setting_control" type="checkbox" {{#if in_home_view}}checked{{/if}} />
|
||||||
Include in home view</div>
|
Include in home view</div>
|
||||||
</li>
|
</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>
|
<li><span class="sub_setting_control"><input class="colorpicker" type="text" value="{{color}}" /></span>
|
||||||
Stream color
|
Stream color
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -652,7 +652,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
|||||||
|
|
||||||
new_subs = gather_subscriptions(self.get_user_profile(test_email))
|
new_subs = gather_subscriptions(self.get_user_profile(test_email))
|
||||||
sub = {'name': stream_name, 'in_home_view': True, 'color': new_color,
|
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)
|
self.assertIn(sub, new_subs)
|
||||||
|
|
||||||
new_subs.remove(sub)
|
new_subs.remove(sub)
|
||||||
|
|||||||
@@ -1150,7 +1150,8 @@ def json_subscription_property(request, user_profile, stream_name=REQ,
|
|||||||
properties.
|
properties.
|
||||||
"""
|
"""
|
||||||
property_converters = dict(color=lambda x: x,
|
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:
|
if property not in property_converters:
|
||||||
return json_error("Unknown subscription property: %s" % (property,))
|
return json_error("Unknown subscription property: %s" % (property,))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user