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]);