From bc23ae80cc34515a4b2f72042b1bff5de34c690e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 16 Feb 2023 11:51:07 -0500 Subject: [PATCH] closes #11218, :train: --- public/language/en-GB/topic.json | 5 +++++ public/src/modules/helpers.common.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/public/language/en-GB/topic.json b/public/language/en-GB/topic.json index f7fcbc2465..81527bad22 100644 --- a/public/language/en-GB/topic.json +++ b/public/language/en-GB/topic.json @@ -43,6 +43,11 @@ "ban-ip": "Ban IP", "view-history": "Edit History", + "wrote-ago": "wrote ", + "wrote-on": "wrote on ", + "replied-to-user-ago": "replied to %3 ", + "replied-to-user-on": "replied to %3 on ", + "user-locked-topic-ago": "%1 locked this topic %2", "user-locked-topic-on": "%1 locked this topic on %2", "user-unlocked-topic-ago": "%1 unlocked this topic %2", diff --git a/public/src/modules/helpers.common.js b/public/src/modules/helpers.common.js index 17a5b2c095..fb9ed1c4f4 100644 --- a/public/src/modules/helpers.common.js +++ b/public/src/modules/helpers.common.js @@ -3,6 +3,7 @@ module.exports = function (utils, Benchpress, relative_path) { Benchpress.setGlobal('true', true); Benchpress.setGlobal('false', false); + const oneDayInMs = 24 * 60 * 60 * 1000; const helpers = { displayMenuItem, @@ -24,6 +25,8 @@ module.exports = function (utils, Benchpress, relative_path) { userAgentIcons, buildAvatar, increment, + generateRepliedTo, + generateWrote, register, __escape: identity, }; @@ -320,6 +323,20 @@ module.exports = function (utils, Benchpress, relative_path) { return value + parseInt(inc, 10); } + function generateRepliedTo(post, timeagoCutoff) { + const username = post.parent && post.parent.username ? + post.parent.username : '[[global:guest]]'; + const isBeforeCutoff = post.timestamp < (Date.now() - (timeagoCutoff * oneDayInMs)); + const langSuffix = isBeforeCutoff ? 'on' : 'ago'; + return `[[topic:replied-to-user-${langSuffix}, ${post.pid}, ${relative_path}/post/${post.pid}, ${username}, ${post.timestampISO}]]`; + } + + function generateWrote(post, timeagoCutoff) { + const isBeforeCutoff = post.timestamp < (Date.now() - (timeagoCutoff * oneDayInMs)); + const langSuffix = isBeforeCutoff ? 'on' : 'ago'; + return `[[topic:wrote-${langSuffix}, ${post.timestampISO}]]`; + } + function register() { Object.keys(helpers).forEach(function (helperName) { Benchpress.registerHelper(helperName, helpers[helperName]);