From aee8c38cfc9a9a96d491407c02a3324ed0777fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 29 Nov 2022 10:45:12 -0500 Subject: [PATCH] refactor: add timeago short/long versions so themes can pick one toggle hidden on unread/read icons as well --- public/src/modules/notifications.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js index 314502914b..b8a52c3fcf 100644 --- a/public/src/modules/notifications.js +++ b/public/src/modules/notifications.js @@ -13,16 +13,20 @@ define('notifications', [ let unreadNotifs = {}; - const _addShortTimeagoString = ({ notifications: notifs }) => new Promise((resolve) => { + const _addTimeagoString = ({ notifications: notifs }) => new Promise((resolve) => { + for (let i = 0; i < notifs.length; i += 1) { + notifs[i].timeagoLong = $.timeago(new Date(parseInt(notifs[i].datetime, 10))); + } translator.toggleTimeagoShorthand(function () { for (let i = 0; i < notifs.length; i += 1) { notifs[i].timeago = $.timeago(new Date(parseInt(notifs[i].datetime, 10))); + notifs[i].timeagoShort = notifs[i].timeago; } translator.toggleTimeagoShorthand(); resolve({ notifications: notifs }); }); }); - hooks.on('filter:notifications.load', _addShortTimeagoString); + hooks.on('filter:notifications.load', _addTimeagoString); Notifications.loadNotifications = function (notifList, callback) { callback = callback || function () {}; @@ -56,11 +60,14 @@ define('notifications', [ components.get('notifications').on('click', '.mark-all-read', Notifications.markAllRead); notifList.on('click', '.mark-read', function () { - const liEl = $(this).parents('li'); + const $this = $(this); + const liEl = $this.parents('li'); const unread = liEl.hasClass('unread'); const nid = liEl.attr('data-nid'); markNotification(nid, unread, function () { liEl.toggleClass('unread'); + $this.find('.unread').toggleClass('hidden', unread); + $this.find('.read').toggleClass('hidden', !unread); }); return false; });