mirror of https://github.com/zulip/zulip.git
Show "how many messages have arrived while away" in the document title
(imported from commit 6e2a18be9953694048d107a56a03a67f8bc2bd5a)
This commit is contained in:
parent
60789abd7f
commit
2f882b505a
|
@ -6,9 +6,9 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
{% if user_profile.realm.domain %}
|
{% if user_profile.realm.domain %}
|
||||||
<title>Humbug for {{user_profile.realm.domain}}</title>
|
<title>Humbug - {{user_profile.realm.domain}}</title>
|
||||||
{% else %}
|
{% else %}
|
||||||
<title>Humbug, from Humbug Inc.</title>
|
<title>Humbug</title>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
|
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||||
<!--[if lt IE 9]>
|
<!--[if lt IE 9]>
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
var initial_pointer = {{ user_profile.pointer }};
|
var initial_pointer = {{ user_profile.pointer }};
|
||||||
|
|
||||||
var email = "{{ user_profile.user.email|escapejs }}";
|
var email = "{{ user_profile.user.email|escapejs }}";
|
||||||
|
var domain = "{{ user_profile.realm.domain|escapejs }}";
|
||||||
var have_initial_messages = {{ have_initial_messages|escapejs }};
|
var have_initial_messages = {{ have_initial_messages|escapejs }};
|
||||||
var desktop_notifications_enabled = "{{ user_profile.enable_desktop_notifications|escapejs }}" === "True";
|
var desktop_notifications_enabled = "{{ user_profile.enable_desktop_notifications|escapejs }}" === "True";
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ var globals =
|
||||||
|
|
||||||
// index.html
|
// index.html
|
||||||
+ ' initial_pointer email stream_list people_list have_initial_messages'
|
+ ' initial_pointer email stream_list people_list have_initial_messages'
|
||||||
+ ' desktop_notifications_enabled'
|
+ ' desktop_notifications_enabled domain'
|
||||||
|
|
||||||
// common.js
|
// common.js
|
||||||
+ ' status_classes'
|
+ ' status_classes'
|
||||||
|
|
|
@ -2,19 +2,29 @@ var notifications = (function () {
|
||||||
|
|
||||||
var exports = {};
|
var exports = {};
|
||||||
|
|
||||||
|
var notice_memory = {};
|
||||||
var window_has_focus = true;
|
var window_has_focus = true;
|
||||||
|
var new_message_count = 0;
|
||||||
|
|
||||||
exports.initialize = function () {
|
function browser_desktop_notifications_on () {
|
||||||
if (!window.webkitNotifications) {
|
return (window.webkitNotifications &&
|
||||||
return;
|
// 0 is PERMISSION_ALLOWED
|
||||||
|
window.webkitNotifications.checkPermission() === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.initialize = function () {
|
||||||
$(window).focus(function () {
|
$(window).focus(function () {
|
||||||
window_has_focus = true;
|
window_has_focus = true;
|
||||||
|
new_message_count = 0;
|
||||||
|
document.title = "Humbug - " + domain;
|
||||||
}).blur(function () {
|
}).blur(function () {
|
||||||
window_has_focus = false;
|
window_has_focus = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!window.webkitNotifications) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$(document).click(function () {
|
$(document).click(function () {
|
||||||
if (!desktop_notifications_enabled) {
|
if (!desktop_notifications_enabled) {
|
||||||
return;
|
return;
|
||||||
|
@ -30,9 +40,7 @@ function gravatar_url(message) {
|
||||||
"?d=identicon&s=30?stamp=" + ui.get_gravatar_stamp();
|
"?d=identicon&s=30?stamp=" + ui.get_gravatar_stamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
var notice_memory = {};
|
function process_desktop_notification(message) {
|
||||||
|
|
||||||
function process_message(message) {
|
|
||||||
var i, notification_object;
|
var i, notification_object;
|
||||||
var key = message.display_reply_to;
|
var key = message.display_reply_to;
|
||||||
var title = message.sender_full_name;
|
var title = message.sender_full_name;
|
||||||
|
@ -93,19 +101,27 @@ function process_message(message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.received_messages = function (messages) {
|
exports.received_messages = function (messages) {
|
||||||
var i;
|
var i, title_needs_update = false;
|
||||||
if (!window.webkitNotifications ||
|
if (window_has_focus) {
|
||||||
!desktop_notifications_enabled ||
|
|
||||||
window_has_focus) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.each(messages, function (index, message) {
|
$.each(messages, function (index, message) {
|
||||||
if (message.sender_email !== email &&
|
if (message.sender_email !== email) {
|
||||||
|
new_message_count++;
|
||||||
|
title_needs_update = true;
|
||||||
|
|
||||||
|
if (desktop_notifications_enabled &&
|
||||||
|
browser_desktop_notifications_on() &&
|
||||||
(message.type === "personal" || message.type === "huddle")) {
|
(message.type === "personal" || message.type === "huddle")) {
|
||||||
process_message(message);
|
process_desktop_notification(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (title_needs_update) {
|
||||||
|
document.title = "(" + new_message_count + ") Humbug - " + domain;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return exports;
|
return exports;
|
||||||
|
|
Loading…
Reference in New Issue