X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fhistory%2Fjs%2Fhistory.es6.js;h=2cc5d663677ac654bf41ff17753b3be7fc25becb;hb=9424afc6c1f518c301bf87a23c047d1873435d05;hp=53a1d05f25e7e11ecb995a9755c62e46d3d50b7d;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website diff --git a/web/core/modules/history/js/history.es6.js b/web/core/modules/history/js/history.es6.js index 53a1d05f2..2cc5d6636 100644 --- a/web/core/modules/history/js/history.es6.js +++ b/web/core/modules/history/js/history.es6.js @@ -5,12 +5,14 @@ * May only be loaded for authenticated users, with the History module enabled. */ -(function ($, Drupal, drupalSettings, storage) { +(function($, Drupal, drupalSettings, storage) { const currentUserID = parseInt(drupalSettings.user.uid, 10); // Any comment that is older than 30 days is automatically considered read, // so for these we don't need to perform a request at all! - const thirtyDaysAgo = Math.round(new Date().getTime() / 1000) - 30 * 24 * 60 * 60; + const secondsIn30Days = 2592000; + const thirtyDaysAgo = + Math.round(new Date().getTime() / 1000) - secondsIn30Days; // Use the data embedded in the page, if available. let embeddedLastReadTimestamps = false; @@ -22,7 +24,6 @@ * @namespace */ Drupal.history = { - /** * Fetch "last read" timestamps for the given nodes. * @@ -44,11 +45,12 @@ data: { 'node_ids[]': nodeIDs }, dataType: 'json', success(results) { - for (const nodeID in results) { - if (results.hasOwnProperty(nodeID)) { - storage.setItem(`Drupal.history.${currentUserID}.${nodeID}`, results[nodeID]); - } - } + Object.keys(results || {}).forEach(nodeID => { + storage.setItem( + `Drupal.history.${currentUserID}.${nodeID}`, + results[nodeID], + ); + }); callback(); }, }); @@ -68,7 +70,10 @@ if (embeddedLastReadTimestamps && embeddedLastReadTimestamps[nodeID]) { return parseInt(embeddedLastReadTimestamps[nodeID], 10); } - return parseInt(storage.getItem(`Drupal.history.${currentUserID}.${nodeID}`) || 0, 10); + return parseInt( + storage.getItem(`Drupal.history.${currentUserID}.${nodeID}`) || 0, + 10, + ); }, /** @@ -85,11 +90,17 @@ success(timestamp) { // If the data is embedded in the page, don't store on the client // side. - if (embeddedLastReadTimestamps && embeddedLastReadTimestamps[nodeID]) { + if ( + embeddedLastReadTimestamps && + embeddedLastReadTimestamps[nodeID] + ) { return; } - storage.setItem(`Drupal.history.${currentUserID}.${nodeID}`, timestamp); + storage.setItem( + `Drupal.history.${currentUserID}.${nodeID}`, + timestamp, + ); }, }); }, @@ -120,11 +131,16 @@ // Use the data embedded in the page, if available. if (embeddedLastReadTimestamps && embeddedLastReadTimestamps[nodeID]) { - return contentTimestamp > parseInt(embeddedLastReadTimestamps[nodeID], 10); + return ( + contentTimestamp > parseInt(embeddedLastReadTimestamps[nodeID], 10) + ); } - const minLastReadTimestamp = parseInt(storage.getItem(`Drupal.history.${currentUserID}.${nodeID}`) || 0, 10); + const minLastReadTimestamp = parseInt( + storage.getItem(`Drupal.history.${currentUserID}.${nodeID}`) || 0, + 10, + ); return contentTimestamp > minLastReadTimestamp; }, }; -}(jQuery, Drupal, drupalSettings, window.localStorage)); +})(jQuery, Drupal, drupalSettings, window.localStorage);