Skip to content
Snippets Groups Projects

Refactor inbox_block_script library.

@@ -4,8 +4,8 @@
*/
((Drupal, drupalSettings, window) => {
let refreshRate;
let checkingCountInProgress = false;
let updateTimeoutId = null;
/**
* Private message notification block.
@@ -87,6 +87,24 @@
pageTitle.textContent = pageTitle.textContent.replace(titlePattern, '');
}
},
/**
* Sets a timeout for count updates.
*/
scheduleCountUpdate() {
if (updateTimeoutId) {
window.clearTimeout(updateTimeoutId);
}
const refreshRate =
drupalSettings.privateMessageNotificationBlock.ajaxRefreshRate * 1000;
if (refreshRate) {
updateTimeoutId = window.setTimeout(
Drupal.privateMessageNotificationBlock.triggerCountCallback,
refreshRate,
);
}
},
};
/**
@@ -102,14 +120,8 @@
context,
).shift();
refreshRate =
drupalSettings.privateMessageNotificationBlock.ajaxRefreshRate * 1000;
if (notificationWrapper && refreshRate) {
window.setTimeout(
Drupal.privateMessageNotificationBlock.triggerCountCallback,
refreshRate,
);
if (notificationWrapper) {
Drupal.privateMessageNotificationBlock.scheduleCountUpdate();
}
},
};
@@ -131,11 +143,6 @@
);
checkingCountInProgress = false;
if (refreshRate) {
window.setTimeout(
Drupal.privateMessageNotificationBlock.triggerCountCallback,
refreshRate,
);
}
Drupal.privateMessageNotificationBlock.scheduleCountUpdate();
};
})(Drupal, drupalSettings, window);
Loading