2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Drupal, drupalSettings, storage) {
9 var currentUserID = parseInt(drupalSettings.user.uid, 10);
11 var secondsIn30Days = 2592000;
12 var thirtyDaysAgo = Math.round(new Date().getTime() / 1000) - secondsIn30Days;
14 var embeddedLastReadTimestamps = false;
15 if (drupalSettings.history && drupalSettings.history.lastReadTimestamps) {
16 embeddedLastReadTimestamps = drupalSettings.history.lastReadTimestamps;
20 fetchTimestamps: function fetchTimestamps(nodeIDs, callback) {
21 if (embeddedLastReadTimestamps) {
27 url: Drupal.url('history/get_node_read_timestamps'),
29 data: { 'node_ids[]': nodeIDs },
31 success: function success(results) {
32 Object.keys(results || {}).forEach(function (nodeID) {
33 storage.setItem('Drupal.history.' + currentUserID + '.' + nodeID, results[nodeID]);
39 getLastRead: function getLastRead(nodeID) {
40 if (embeddedLastReadTimestamps && embeddedLastReadTimestamps[nodeID]) {
41 return parseInt(embeddedLastReadTimestamps[nodeID], 10);
43 return parseInt(storage.getItem('Drupal.history.' + currentUserID + '.' + nodeID) || 0, 10);
45 markAsRead: function markAsRead(nodeID) {
47 url: Drupal.url('history/' + nodeID + '/read'),
50 success: function success(timestamp) {
51 if (embeddedLastReadTimestamps && embeddedLastReadTimestamps[nodeID]) {
55 storage.setItem('Drupal.history.' + currentUserID + '.' + nodeID, timestamp);
59 needsServerCheck: function needsServerCheck(nodeID, contentTimestamp) {
60 if (contentTimestamp < thirtyDaysAgo) {
64 if (embeddedLastReadTimestamps && embeddedLastReadTimestamps[nodeID]) {
65 return contentTimestamp > parseInt(embeddedLastReadTimestamps[nodeID], 10);
68 var minLastReadTimestamp = parseInt(storage.getItem('Drupal.history.' + currentUserID + '.' + nodeID) || 0, 10);
69 return contentTimestamp > minLastReadTimestamp;
72 })(jQuery, Drupal, drupalSettings, window.localStorage);