diff --git a/install/data/defaults.json b/install/data/defaults.json
index 18dd27f612..9cb646a2f8 100644
--- a/install/data/defaults.json
+++ b/install/data/defaults.json
@@ -114,6 +114,8 @@
"hideFullname": 0,
"hideEmail": 0,
"allowGuestHandles": 0,
+ "guestsIncrementTopicViews": 1,
+ "incrementTopicViewsInterval": 60,
"recentMaxTopics": 200,
"disableRecentCategoryFilter": 0,
"maximumRelatedTopics": 0,
diff --git a/public/language/en-GB/admin/settings/guest.json b/public/language/en-GB/admin/settings/guest.json
index a8b9d458f0..3ba81aa778 100644
--- a/public/language/en-GB/admin/settings/guest.json
+++ b/public/language/en-GB/admin/settings/guest.json
@@ -1,5 +1,7 @@
{
"handles": "Guest Handles",
"handles.enabled": "Allow guest handles",
- "handles.enabled-help": "This option exposes a new field that allows guests to pick a name to associate with each post they make. If disabled, they will simply be called \"Guest\""
+ "handles.enabled-help": "This option exposes a new field that allows guests to pick a name to associate with each post they make. If disabled, they will simply be called \"Guest\"",
+ "topic-views": "Topic views",
+ "topic-views.enabled": "Allow guests to increase topic view counts"
}
\ No newline at end of file
diff --git a/public/language/en-GB/admin/settings/post.json b/public/language/en-GB/admin/settings/post.json
index a8d0046355..27493aafbd 100644
--- a/public/language/en-GB/admin/settings/post.json
+++ b/public/language/en-GB/admin/settings/post.json
@@ -34,6 +34,8 @@
"timestamp.cut-off-help": "Dates & times will be shown in a relative manner (e.g. \"3 hours ago\" / \"5 days ago\"), and localised into various\n\t\t\t\t\tlanguages. After a certain point, this text can be switched to display the localised date itself\n\t\t\t\t\t(e.g. 5 Nov 2016 15:30).
(Default: 30
, or one month). Set to 0 to always display dates, leave blank to always display relative times.",
"timestamp.necro-threshold": "Necro Threshold (in days)",
"timestamp.necro-threshold-help": "A message will be shown between posts if the time between them is longer than the necro threshold. (Default: 7
, or one week). Set to 0 to disable.",
+ "timestamp.topic-views-interval": "Increment topic views interval (in minutes)",
+ "timestamp.topic-views-interval-help": "Topic views will only increment once every X minutes as defined by this setting.",
"teaser": "Teaser Post",
"teaser.last-post": "Last – Show the latest post, including the original post, if no replies",
"teaser.last-reply": "Last – Show the latest reply, or a \"No replies\" placeholder if no replies",
diff --git a/src/controllers/topics.js b/src/controllers/topics.js
index 0387e4b69b..2b40f4595b 100644
--- a/src/controllers/topics.js
+++ b/src/controllers/topics.js
@@ -127,11 +127,14 @@ function calculateStartStop(page, postIndex, settings) {
}
async function incrementViewCount(req, tid) {
- if (req.uid >= 1) {
+ const allow = req.uid > 0 || (meta.config.guestsIncrementTopicViews && req.uid === 0);
+ if (allow) {
req.session.tids_viewed = req.session.tids_viewed || {};
- if (!req.session.tids_viewed[tid] || req.session.tids_viewed[tid] < Date.now() - 3600000) {
+ const now = Date.now();
+ const interval = meta.config.incrementTopicViewsInterval * 60000;
+ if (!req.session.tids_viewed[tid] || req.session.tids_viewed[tid] < now - interval) {
await topics.increaseViewCount(tid);
- req.session.tids_viewed[tid] = Date.now();
+ req.session.tids_viewed[tid] = now;
}
}
}
diff --git a/src/views/admin/settings/guest.tpl b/src/views/admin/settings/guest.tpl
index e6a9672093..368f384b79 100644
--- a/src/views/admin/settings/guest.tpl
+++ b/src/views/admin/settings/guest.tpl
@@ -15,6 +15,17 @@
+ [[admin/settings/post:timestamp.topic-views-interval-help]] +
+