Clean up the notification code

(imported from commit 5bd811ba40b3f535d474ac53e22fd16816f9bac6)
This commit is contained in:
Jeff Arnold
2013-02-12 00:15:42 -05:00
parent b30e277f5a
commit e2f3a85dbd

View File

@@ -18,14 +18,7 @@ function browser_desktop_notifications_on () {
exports.initialize = function () { exports.initialize = function () {
names = fullname.toLowerCase().split(" "); names = fullname.toLowerCase().split(" ");
var username = email.split("@")[0].toLowerCase(); names.push(email.split("@")[0].toLowerCase());
// If the username is part of the user's full name, then don't add it
// to names because we don't send notifications to ambiguous names
// that could refer to multiple people in the domain.
// (We later add to names all of the names from the domain)
if (names.indexOf(username) === -1) {
names.push(username);
}
$(window).focus(function () { $(window).focus(function () {
window_has_focus = true; window_has_focus = true;
@@ -133,8 +126,7 @@ function process_desktop_notification(message) {
function speaking_at_me(message) { function speaking_at_me(message) {
var content_lc = $('<div/>').html(message.content).text().toLowerCase(); var content_lc = $('<div/>').html(message.content).text().toLowerCase();
var match_so_far = false; var found_match = false, indexof, after_name, after_atname;
var indexof, after_name, after_atname;
var punctuation = /[\.,-\/#!$%\^&\*;:{}=\-_`~()\+\?\[\]\s]/; var punctuation = /[\.,-\/#!$%\^&\*;:{}=\-_`~()\+\?\[\]\s]/;
if (domain === "mit.edu") { if (domain === "mit.edu") {
@@ -158,17 +150,12 @@ function speaking_at_me(message) {
after_name.match(punctuation) !== null) || after_name.match(punctuation) !== null) ||
(indexof > 0 && content_lc.charAt(indexof-1) === "@" && (indexof > 0 && content_lc.charAt(indexof-1) === "@" &&
after_name.match(punctuation) !== null)) { after_name.match(punctuation) !== null)) {
if (match_so_far) { found_match = true;
match_so_far = false;
return false; return false;
} }
else {
match_so_far = true;
}
}
}); });
return match_so_far; return found_match;
} }
exports.received_messages = function (messages) { exports.received_messages = function (messages) {