Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/notificationHelper.js

Issue 29327244: Issue 3024 - Added opt-out to Chrome notifications (Closed)
Patch Set: Created Sept. 10, 2015, 6:46 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « _locales/en_US/messages.json ('k') | options.html » ('j') | options.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/notificationHelper.js
===================================================================
--- a/lib/notificationHelper.js
+++ b/lib/notificationHelper.js
@@ -63,13 +63,8 @@
{
if (activeNotification.links)
{
- activeNotification.links.forEach(function(link)
Sebastian Noack 2015/09/11 10:58:26 I wonder why we did it that complicated in the fir
Thomas Greiner 2015/09/11 12:51:48 From what I've seen `ext.pages.open` wasn't availa
- {
- ext.windows.getLastFocused(function(win)
- {
- win.openTab(Utils.getDocLink(link));
- });
- });
+ for (let link of activeNotification.links)
+ ext.pages.open(Utils.getDocLink(link));
}
}
@@ -81,12 +76,24 @@
NotificationStorage.markAsShown(activeNotification.id);
activeNotification.onClicked();
}
- else if (activeNotification.links && activeNotification.links[buttonIndex])
+ else
{
- ext.windows.getLastFocused(function(win)
+ let links = activeNotification.links || [];
+ if (buttonIndex == 1 || links.length == 0)
{
- win.openTab(Utils.getDocLink(activeNotification.links[buttonIndex]));
- });
+ Prefs.notifications_showui = true;
+ ext.showOptions(function(page)
+ {
+ page.sendMessage({
+ type: "focus-section",
+ section: "notifications"
+ });
+ });
+ }
+ else if (links.length == 1)
+ ext.pages.open(Utils.getDocLink(activeNotification.links[0]));
+ else
+ openNotificationLinks();
}
}
@@ -147,7 +154,7 @@
let title = texts.title || "";
let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : "";
let iconUrl = ext.getURL("icons/detailed/abp-128.png");
- let hasLinks = activeNotification.links && activeNotification.links.length > 0;
+ let linkCount = (activeNotification.links || []).length;
if (canUseChromeNotifications)
{
@@ -165,11 +172,15 @@
}
else
{
- let regex = /<a>(.*?)<\/a>/g;
- let plainMessage = texts.message || "";
- let match;
- while (match = regex.exec(plainMessage))
- opts.buttons.push({title: match[1]});
+ if (linkCount == 1)
+ {
+ let match = /<a>(.*?)<\/a>/.exec(texts.message || "");
Sebastian Noack 2015/09/11 10:58:26 Nit: .exec() simply returns null if you pass null
Thomas Greiner 2015/09/11 12:51:48 Done.
+ if (match)
+ opts.buttons.push({title: match[1]});
+ }
+ else if (linkCount > 1)
+ opts.buttons.push({title: ext.i18n.getMessage("notification_open_all")});
+ opts.buttons.push({title: ext.i18n.getMessage("notification_configure")});
}
imgToBase64(iconUrl, function(iconData)
@@ -180,7 +191,7 @@
}
else if ("Notification" in window && activeNotification.type != "question")
{
- if (hasLinks)
+ if (linkCount == 0)
message += " " + ext.i18n.getMessage("notification_without_buttons");
imgToBase64(iconUrl, function(iconData)
@@ -202,7 +213,7 @@
else
{
let message = title + "\n" + message;
- if (hasLinks)
+ if (linkCount == 0)
message += "\n\n" + ext.i18n.getMessage("notification_with_buttons");
let approved = confirm(message);
« no previous file with comments | « _locales/en_US/messages.json ('k') | options.html » ('j') | options.js » ('J')

Powered by Google App Engine
This is Rietveld