mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
Notify the user when someone is speaking at them
(imported from commit 662ea67b2cf210bfd327ae2db6f924e4424d6d50)
This commit is contained in:
@@ -66,6 +66,7 @@ var initial_pointer = {{ user_profile.pointer }};
|
|||||||
|
|
||||||
var poll_timeout = {{ poll_timeout }};
|
var poll_timeout = {{ poll_timeout }};
|
||||||
|
|
||||||
|
var fullname = "{{ user_profile.full_name|escapejs }}";
|
||||||
var email = "{{ user_profile.user.email|escapejs }}";
|
var email = "{{ user_profile.user.email|escapejs }}";
|
||||||
var domain = "{{ user_profile.realm.domain|escapejs }}";
|
var domain = "{{ user_profile.realm.domain|escapejs }}";
|
||||||
var have_initial_messages = {{ have_initial_messages|escapejs }};
|
var have_initial_messages = {{ have_initial_messages|escapejs }};
|
||||||
|
|||||||
@@ -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 domain poll_timeout'
|
+ ' fullname desktop_notifications_enabled domain poll_timeout'
|
||||||
|
|
||||||
// common.js
|
// common.js
|
||||||
+ ' status_classes'
|
+ ' status_classes'
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ var notice_memory = {};
|
|||||||
var window_has_focus = true;
|
var window_has_focus = true;
|
||||||
var new_message_count = 0;
|
var new_message_count = 0;
|
||||||
var asked_permission_already = false;
|
var asked_permission_already = false;
|
||||||
|
var names;
|
||||||
|
|
||||||
function browser_desktop_notifications_on () {
|
function browser_desktop_notifications_on () {
|
||||||
return (window.webkitNotifications &&
|
return (window.webkitNotifications &&
|
||||||
@@ -14,6 +15,8 @@ function browser_desktop_notifications_on () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.initialize = function () {
|
exports.initialize = function () {
|
||||||
|
names = fullname.split(" ");
|
||||||
|
|
||||||
$(window).focus(function () {
|
$(window).focus(function () {
|
||||||
window_has_focus = true;
|
window_has_focus = true;
|
||||||
new_message_count = 0;
|
new_message_count = 0;
|
||||||
@@ -47,16 +50,22 @@ function gravatar_url(message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function process_desktop_notification(message) {
|
function process_desktop_notification(message) {
|
||||||
var i, notification_object;
|
var i, notification_object, key;
|
||||||
var key = message.display_reply_to;
|
|
||||||
var title = message.sender_full_name;
|
var title = message.sender_full_name;
|
||||||
var content = $('<div/>').html(message.content).text();
|
var content = $('<div/>').html(message.content).text();
|
||||||
var other_recipients = message.display_reply_to;
|
var other_recipients;
|
||||||
var msg_count = 1;
|
var msg_count = 1;
|
||||||
|
|
||||||
|
if (message.type === "private") {
|
||||||
|
key = message.display_reply_to;
|
||||||
|
other_recipients = message.display_reply_to;
|
||||||
// Remove the sender from the list of other recipients
|
// Remove the sender from the list of other recipients
|
||||||
other_recipients = other_recipients.replace(", " + message.sender_full_name, "");
|
other_recipients = other_recipients.replace(", " + message.sender_full_name, "");
|
||||||
other_recipients = other_recipients.replace(message.sender_full_name + ", ", "");
|
other_recipients = other_recipients.replace(message.sender_full_name + ", ", "");
|
||||||
|
} else {
|
||||||
|
key = message.sender_full_name + " to " +
|
||||||
|
message.display_recipient + " | " + message.subject;
|
||||||
|
}
|
||||||
|
|
||||||
if (content.length > 150) {
|
if (content.length > 150) {
|
||||||
// Truncate content at a word boundary
|
// Truncate content at a word boundary
|
||||||
@@ -89,6 +98,9 @@ function process_desktop_notification(message) {
|
|||||||
}
|
}
|
||||||
title += " (to you and " + other_recipients + ")";
|
title += " (to you and " + other_recipients + ")";
|
||||||
}
|
}
|
||||||
|
if (message.type === "stream") {
|
||||||
|
title += " (to " + message.display_recipient + " | " + message.subject + ")";
|
||||||
|
}
|
||||||
|
|
||||||
notice_memory[key] = {
|
notice_memory[key] = {
|
||||||
obj: window.webkitNotifications.createNotification(
|
obj: window.webkitNotifications.createNotification(
|
||||||
@@ -106,6 +118,32 @@ function process_desktop_notification(message) {
|
|||||||
notification_object.show();
|
notification_object.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function speaking_at_me(message) {
|
||||||
|
var content_lc = $('<div/>').html(message.content).text().toLowerCase();
|
||||||
|
var match_so_far = false;
|
||||||
|
var indexof, after_name, after_atname;
|
||||||
|
|
||||||
|
$.each(names, function (index, name) {
|
||||||
|
indexof = content_lc.indexOf(name.toLowerCase());
|
||||||
|
after_name = content_lc.charAt(name.length);
|
||||||
|
after_atname = content_lc.charAt(name.length+1);
|
||||||
|
if ((indexof === 0 &&
|
||||||
|
(after_name === " " || after_name === ":")) ||
|
||||||
|
(indexof === 1 && content_lc.charAt(0) === "@" &&
|
||||||
|
(after_atname === " " || after_atname === ":"))) {
|
||||||
|
if (match_so_far) {
|
||||||
|
match_so_far = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
match_so_far = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return match_so_far;
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@@ -119,7 +157,8 @@ exports.received_messages = function (messages) {
|
|||||||
|
|
||||||
if (desktop_notifications_enabled &&
|
if (desktop_notifications_enabled &&
|
||||||
browser_desktop_notifications_on() &&
|
browser_desktop_notifications_on() &&
|
||||||
message.type === "private") {
|
(message.type === "private" ||
|
||||||
|
speaking_at_me(message))) {
|
||||||
process_desktop_notification(message);
|
process_desktop_notification(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user