diff --git a/public/src/client/header/notifications.js b/public/src/client/header/notifications.js index bff84bd849..fc402b8d96 100644 --- a/public/src/client/header/notifications.js +++ b/public/src/client/header/notifications.js @@ -6,14 +6,19 @@ define('forum/header/notifications', function () { notifications.prepareDOM = function () { const notifTrigger = $('[component="notifications"] [data-bs-toggle="dropdown"]'); - notifTrigger.on('show.bs.dropdown', (ev) => { - requireAndCall('loadNotifications', $(ev.target).parent().find('[component="notifications/list"]')); + notifTrigger.on('show.bs.dropdown', async (ev) => { + const notifications = await app.require('notifications'); + const triggerEl = $(ev.target); + notifications.loadNotifications(triggerEl, triggerEl.parent().find('[component="notifications/list"]')); }); notifTrigger.each((index, el) => { - const dropdownEl = $(el).parent().find('.dropdown-menu'); + const triggerEl = $(el); + const dropdownEl = triggerEl.parent().find('.dropdown-menu'); if (dropdownEl.hasClass('show')) { - requireAndCall('loadNotifications', dropdownEl.find('[component="notifications/list"]')); + app.require('notifications').then((notifications) => { + notifications.loadNotifications(triggerEl, dropdownEl.find('[component="notifications/list"]')); + }); } }); @@ -24,18 +29,14 @@ define('forum/header/notifications', function () { socket.on('event:notifications.updateCount', onUpdateCount); }; - function onNewNotification(data) { - requireAndCall('onNewNotification', data); + async function onNewNotification(data) { + const notifications = await app.require('notifications'); + notifications.onNewNotification(data); } - function onUpdateCount(data) { - requireAndCall('updateNotifCount', data); - } - - function requireAndCall(method, param) { - require(['notifications'], function (notifications) { - notifications[method](param); - }); + async function onUpdateCount(data) { + const notifications = await app.require('notifications'); + notifications.updateNotifCount(data); } return notifications; diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js index a983519183..0fef33f650 100644 --- a/public/src/modules/notifications.js +++ b/public/src/modules/notifications.js @@ -28,7 +28,7 @@ define('notifications', [ }); hooks.on('filter:notifications.load', _addTimeagoString); - Notifications.loadNotifications = function (notifList, callback) { + Notifications.loadNotifications = function (triggerEl, notifList, callback) { callback = callback || function () {}; socket.emit('notifications.get', null, function (err, data) { if (err) { @@ -47,7 +47,7 @@ define('notifications', [ if (scrollToPostIndexIfOnPage(notifEl)) { ev.stopPropagation(); ev.preventDefault(); - components.get('notifications/list').dropdown('toggle'); + triggerEl.dropdown('toggle'); } const unread = notifEl.hasClass('unread');