Skip to content

Node.js based forum software built for the modern web

feat: on online users page override timeago cutoff to 24 hours

Barış Soner Uşaklı7c946570d569
diff --git a/public/src/app.js b/public/src/app.js
index 87c8d3ddfc..3542a4cb43 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -239,6 +239,7 @@ app.flags = {};
app.processPage = function () {
highlightNavigationLink();
+ overrides.overrideTimeagoCutoff();
$('.timeago').timeago();
utils.makeNumbersHumanReadable($('.human-readable-number'));
utils.addCommasToNumbers($('.formatted-number'));
diff --git a/public/src/overrides.js b/public/src/overrides.js
index 123d814059..c00d3b530b 100644
--- a/public/src/overrides.js
+++ b/public/src/overrides.js
@@ -109,16 +109,21 @@ if (typeof window !== 'undefined') {
});
}());
let timeagoFn;
+ overrides.overrideTimeagoCutoff = function () {
+ const cutoff = parseInt(ajaxify.data.timeagoCutoff || config.timeagoCutoff, 10);
+ if (cutoff === 0) {
+ $.timeago.settings.cutoff = 1;
+ } else if (cutoff > 0) {
+ $.timeago.settings.cutoff = 1000 * 60 * 60 * 24 * cutoff;
+ }
+ };
+
overrides.overrideTimeago = function () {
if (!timeagoFn) {
timeagoFn = $.fn.timeago;
}
- if (parseInt(config.timeagoCutoff, 10) === 0) {
- $.timeago.settings.cutoff = 1;
- } else if (parseInt(config.timeagoCutoff, 10) > 0) {
- $.timeago.settings.cutoff = 1000 * 60 * 60 * 24 * (parseInt(config.timeagoCutoff, 10) || 30);
- }
+ overrides.overrideTimeagoCutoff();
$.timeago.settings.allowFuture = true;
const userLang = config.userLang.replace('_', '-');
diff --git a/src/controllers/users.js b/src/controllers/users.js
index 2f697c4b9c..f08e428c38 100644
--- a/src/controllers/users.js
+++ b/src/controllers/users.js
@@ -61,6 +61,7 @@ usersController.getOnlineUsers = async function (req, res) {
}
userData.anonymousUserCount = guests + hiddenCount;
+ userData.timeagoCutoff = 1000 * 60 * 60 * 24;
await render(req, res, userData);
};