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

Side by Side Diff: lib/notification.js

Issue 29370562: [adblockpluscore] Issue 4762 - Added "relentless" notification that shows up in intervals (Closed)
Patch Set: Added tests for relentless notification Created Jan. 16, 2017, 1:49 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/notification.js » ('j') | test/notification.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 15 matching lines...) Expand all
26 var {Utils} = require("utils"); 26 var {Utils} = require("utils");
27 var {Matcher, defaultMatcher} = require("matcher"); 27 var {Matcher, defaultMatcher} = require("matcher");
28 var {Filter, RegExpFilter, WhitelistFilter} = require("filterClasses"); 28 var {Filter, RegExpFilter, WhitelistFilter} = require("filterClasses");
29 29
30 var INITIAL_DELAY = 1 * MILLIS_IN_MINUTE; 30 var INITIAL_DELAY = 1 * MILLIS_IN_MINUTE;
31 var CHECK_INTERVAL = 1 * MILLIS_IN_HOUR; 31 var CHECK_INTERVAL = 1 * MILLIS_IN_HOUR;
32 var EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY; 32 var EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY;
33 var TYPE = { 33 var TYPE = {
34 information: 0, 34 information: 0,
35 question: 1, 35 question: 1,
36 critical: 2 36 relentless: 2,
37 critical: 3
37 }; 38 };
38 39
39 var showListeners = []; 40 var showListeners = [];
40 var questionListeners = {}; 41 var questionListeners = {};
41 42
42 function getNumericalSeverity(notification) 43 function getNumericalSeverity(notification)
43 { 44 {
44 return (notification.type in TYPE ? TYPE[notification.type] : TYPE.information ); 45 return (notification.type in TYPE ? TYPE[notification.type] : TYPE.information );
45 } 46 }
46 47
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 let notifications = localData.concat(remoteData); 202 let notifications = localData.concat(remoteData);
202 if (notifications.length === 0) 203 if (notifications.length === 0)
203 return null; 204 return null;
204 205
205 let {addonName, addonVersion, application, applicationVersion, platform, pla tformVersion} = require("info"); 206 let {addonName, addonVersion, application, applicationVersion, platform, pla tformVersion} = require("info");
206 let notificationToShow = null; 207 let notificationToShow = null;
207 for (let notification of notifications) 208 for (let notification of notifications)
208 { 209 {
209 if (typeof notification.type === "undefined" || notification.type !== "cri tical") 210 if (typeof notification.type === "undefined" || notification.type !== "cri tical")
210 { 211 {
211 let shown = Prefs.notificationdata.shown; 212 let shown;
212 if (shown instanceof Array && shown.indexOf(notification.id) != -1) 213 if (typeof Prefs.notificationdata.shown == "object")
213 continue; 214 shown = Prefs.notificationdata.shown[notification.id];
214 if (Prefs.notifications_ignoredcategories.indexOf("*") != -1) 215
216 if (typeof shown != "undefined")
217 {
218 if (typeof notification.interval == "number")
219 {
220 if (shown + notification.interval > Date.now())
221 continue;
222 }
223 else if (shown)
224 continue;
225 }
226
227 if (notification.type !== "relentless" && Prefs.notifications_ignoredcat egories.indexOf("*") != -1)
Felix Dahlke 2017/01/19 17:16:14 :)
wspee 2017/01/20 09:21:40 ;)
215 continue; 228 continue;
216 } 229 }
217 230
218 if (typeof url === "string" || notification.urlFilters instanceof Array) 231 if (typeof url === "string" || notification.urlFilters instanceof Array)
219 { 232 {
220 if (Prefs.enabled && typeof url === "string" && notification.urlFilters instanceof Array) 233 if (Prefs.enabled && typeof url === "string" && notification.urlFilters instanceof Array)
221 { 234 {
222 let host; 235 let host;
223 try 236 try
224 { 237 {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 for (let showListener of showListeners) 293 for (let showListener of showListeners)
281 showListener(notification); 294 showListener(notification);
282 }, 295 },
283 296
284 /** 297 /**
285 * Marks a notification as shown. 298 * Marks a notification as shown.
286 * @param {String} id ID of the notification to be marked as shown 299 * @param {String} id ID of the notification to be marked as shown
287 */ 300 */
288 markAsShown: function(id) 301 markAsShown: function(id)
289 { 302 {
290 var data = Prefs.notificationdata; 303 let now = Date.now();
304 let data = Prefs.notificationdata;
291 305
292 if (!(data.shown instanceof Array)) 306 if (data.shown instanceof Array)
293 data.shown = []; 307 {
294 if (data.shown.indexOf(id) != -1) 308 let newShown = {};
295 return; 309 for (let oldId of data.shown)
310 newShown[oldId] = now;
311 data.shown = newShown;
312 }
296 313
297 data.shown.push(id); 314 if (typeof data.shown != "object")
315 data.shown = {};
316
317 data.shown[id] = now;
318
298 saveNotificationData(); 319 saveNotificationData();
299 }, 320 },
300 321
301 /** 322 /**
302 * Localizes the texts of the supplied notification. 323 * Localizes the texts of the supplied notification.
303 * @param {Object} notification notification to translate 324 * @param {Object} notification notification to translate
304 * @param {String} locale the target locale (optional, defaults to the 325 * @param {String} locale the target locale (optional, defaults to the
305 * application locale) 326 * application locale)
306 * @return {Object} the translated texts 327 * @return {Object} the translated texts
307 */ 328 */
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 Prefs.notifications_showui = true; 419 Prefs.notifications_showui = true;
399 } 420 }
400 else if (index != -1 && forceValue !== true) 421 else if (index != -1 && forceValue !== true)
401 categories.splice(index, 1); 422 categories.splice(index, 1);
402 423
403 // HACK: JSON values aren't saved unless they are assigned a different objec t. 424 // HACK: JSON values aren't saved unless they are assigned a different objec t.
404 Prefs.notifications_ignoredcategories = JSON.parse(JSON.stringify(categories )); 425 Prefs.notifications_ignoredcategories = JSON.parse(JSON.stringify(categories ));
405 } 426 }
406 }; 427 };
407 Notification.init(); 428 Notification.init();
OLDNEW
« no previous file with comments | « no previous file | test/notification.js » ('j') | test/notification.js » ('J')

Powered by Google App Engine
This is Rietveld