Chris@0: /** Chris@0: * DO NOT EDIT THIS FILE. Chris@0: * See the following change record for more information, Chris@0: * https://www.drupal.org/node/2815083 Chris@0: * @preserve Chris@0: **/ Chris@0: Chris@0: (function ($, Drupal, drupalSettings, storage) { Chris@0: var currentUserID = parseInt(drupalSettings.user.uid, 10); Chris@0: Chris@14: var secondsIn30Days = 2592000; Chris@14: var thirtyDaysAgo = Math.round(new Date().getTime() / 1000) - secondsIn30Days; Chris@0: Chris@0: var embeddedLastReadTimestamps = false; Chris@0: if (drupalSettings.history && drupalSettings.history.lastReadTimestamps) { Chris@0: embeddedLastReadTimestamps = drupalSettings.history.lastReadTimestamps; Chris@0: } Chris@0: Chris@0: Drupal.history = { Chris@0: fetchTimestamps: function fetchTimestamps(nodeIDs, callback) { Chris@0: if (embeddedLastReadTimestamps) { Chris@0: callback(); Chris@0: return; Chris@0: } Chris@0: Chris@0: $.ajax({ Chris@0: url: Drupal.url('history/get_node_read_timestamps'), Chris@0: type: 'POST', Chris@0: data: { 'node_ids[]': nodeIDs }, Chris@0: dataType: 'json', Chris@0: success: function success(results) { Chris@14: Object.keys(results || {}).forEach(function (nodeID) { Chris@14: storage.setItem('Drupal.history.' + currentUserID + '.' + nodeID, results[nodeID]); Chris@14: }); Chris@0: callback(); Chris@0: } Chris@0: }); Chris@0: }, Chris@0: getLastRead: function getLastRead(nodeID) { Chris@0: if (embeddedLastReadTimestamps && embeddedLastReadTimestamps[nodeID]) { Chris@0: return parseInt(embeddedLastReadTimestamps[nodeID], 10); Chris@0: } Chris@0: return parseInt(storage.getItem('Drupal.history.' + currentUserID + '.' + nodeID) || 0, 10); Chris@0: }, Chris@0: markAsRead: function markAsRead(nodeID) { Chris@0: $.ajax({ Chris@0: url: Drupal.url('history/' + nodeID + '/read'), Chris@0: type: 'POST', Chris@0: dataType: 'json', Chris@0: success: function success(timestamp) { Chris@0: if (embeddedLastReadTimestamps && embeddedLastReadTimestamps[nodeID]) { Chris@0: return; Chris@0: } Chris@0: Chris@0: storage.setItem('Drupal.history.' + currentUserID + '.' + nodeID, timestamp); Chris@0: } Chris@0: }); Chris@0: }, Chris@0: needsServerCheck: function needsServerCheck(nodeID, contentTimestamp) { Chris@0: if (contentTimestamp < thirtyDaysAgo) { Chris@0: return false; Chris@0: } Chris@0: Chris@0: if (embeddedLastReadTimestamps && embeddedLastReadTimestamps[nodeID]) { Chris@0: return contentTimestamp > parseInt(embeddedLastReadTimestamps[nodeID], 10); Chris@0: } Chris@0: Chris@0: var minLastReadTimestamp = parseInt(storage.getItem('Drupal.history.' + currentUserID + '.' + nodeID) || 0, 10); Chris@0: return contentTimestamp > minLastReadTimestamp; Chris@0: } Chris@0: }; Chris@0: })(jQuery, Drupal, drupalSettings, window.localStorage);