Skip to content
Snippets Groups Projects
Commit fa6afe03 authored by Adrian Lorenc's avatar Adrian Lorenc
Browse files

Limit potential duplicate calls.

parent 98b0723c
No related branches found
No related tags found
1 merge request!166Refactor inbox_block_script library.
This commit is part of merge request !166. Comments created here will be created in the context of that merge request.
......@@ -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);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment