Commit 856618ba authored by Dave Barker's avatar Dave Barker 🐈

Refs #68 - Hard code local notification links

parent 24284e28
Pipeline #79805866 passed with stages
in 7 minutes and 44 seconds
......@@ -38,6 +38,12 @@ const displayMethods = new Map([
]);
const defaultDisplayMethods = ["popup"];
// We must hard code any "abp:" prefixed notification links here, otherwise
// notifications linking to them will not be displayed at all.
const localNotificationPages = new Map([
["abp:day1", "/day1.html"]
]);
// The active notification is (if any) the most recent currently displayed
// notification. Once a notification is clicked or is superceeded by another
// notification we no longer consider it active.
......@@ -143,16 +149,18 @@ function getNotificationButtons({type: notificationType, links}, message)
function openNotificationLink(link)
{
// Previously all links were considered doc links, so while arbritrary URLs
// are now supported we must assume they will contain at least one "/".
let url = link.includes("/") ? link : Utils.getDocLink(link);
let url;
if (link.startsWith("abp:"))
url = localNotificationPages.get(link);
else
url = Utils.getDocLink(link);
browser.tabs.create({url});
}
function openNotificationLinks(notificationId)
function getButtonLinks(buttons)
{
let buttons = buttonsByNotificationId.get(notificationId) || [];
let links = [];
for (let button of buttons)
......@@ -162,8 +170,13 @@ function openNotificationLinks(notificationId)
else if (button.type == "open-all" && button.links)
links = links.concat(button.links);
}
return links;
}
for (let link of links)
function openNotificationLinks(notificationId)
{
let buttons = buttonsByNotificationId.get(notificationId) || [];
for (let link of getButtonLinks(buttons))
openNotificationLink(link);
}
......@@ -237,20 +250,29 @@ function showNotification(notification)
if (notification.type == "question" && !browserNotificationButtonsSupported)
return;
let texts = NotificationStorage.getLocalizedTexts(notification);
let buttons = getNotificationButtons(notification, texts.message);
// Don't display notifications at all if they contain a link to a local
// notification page which we don't have.
for (let link of getButtonLinks(buttons))
{
if (link.startsWith("abp:") && !localNotificationPages.has(link))
return;
}
// We take a note of the notification's buttons even if notification buttons
// are not supported by this browser. That way, if the user clicks the
// (buttonless) notification we can still open all the links.
buttonsByNotificationId.set(notification.id, buttons);
activeNotification = notification;
if (shouldDisplay("notification", notification.type))
{
let texts = NotificationStorage.getLocalizedTexts(notification);
let notificationTitle = texts.title || "";
let message = (texts.message || "").replace(/<\/?(a|strong)>/g, "");
let iconUrl = browser.extension.getURL("icons/detailed/abp-128.png");
// We take a note of the notification's buttons even if notification buttons
// are not supported by this browser. That way, if the user clicks the
// (buttonless) notification we can still open all the links.
let buttons = getNotificationButtons(notification, texts.message);
buttonsByNotificationId.set(notification.id, buttons);
if (browserNotificationsSupported)
{
let notificationOptions = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment