Skip to content

Commit d982108

Browse files
committed
v1.1.0 max post age
v1.1.0 now you can limit post age
1 parent 3835880 commit d982108

9 files changed

Lines changed: 37 additions & 5 deletions

File tree

Config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ var MIN_POSTS_TO_UPVOTE = 20,
1111
REP_LOG_NAMESPACE = "reputationLog",
1212
DISABLED_CATEGORIES_IDS = [],
1313
MAX_POINTS_FOR_UPVOTE = 10,
14-
MAX_POINTS_FOR_DOWNVOTE = 10;
14+
MAX_POINTS_FOR_DOWNVOTE = 10,
15+
MAX_POST_AGE_DAYS = 0; // 0 means disabled
1516

1617
var Config = {
1718
minPostToDownvote: function () {
@@ -84,6 +85,9 @@ var Config = {
8485
getDisabledCategories: function () {
8586
return DISABLED_CATEGORIES_IDS;
8687
},
88+
getMaxPostAgeDays: function() {
89+
return MAX_POST_AGE_DAYS;
90+
},
8791
getSettings: function () {
8892
var settings = {};
8993
settings.minPostsToUpvote = MIN_POSTS_TO_UPVOTE;
@@ -100,6 +104,7 @@ var Config = {
100104
settings.repLogNamespace = REP_LOG_NAMESPACE;
101105
settings.maxUpvoteWeigh = MAX_POINTS_FOR_UPVOTE;
102106
settings.maxDownvoteWeigh = MAX_POINTS_FOR_DOWNVOTE;
107+
settings.maxPostAgeDays = MAX_POST_AGE_DAYS;
103108
return settings;
104109
},
105110
setSettings: function (settings) {
@@ -116,6 +121,7 @@ var Config = {
116121
DISABLED_CATEGORIES_IDS = intArray(settings.disabledCategoriesIds);
117122
MAX_POINTS_FOR_UPVOTE = settings.maxUpvoteWeigh;
118123
MAX_POINTS_FOR_DOWNVOTE = settings.maxDownvoteWeigh;
124+
MAX_POST_AGE_DAYS = parseInt(settings.maxPostAgeDays, 10) || 0;
119125
}
120126
};
121127

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,10 @@ Undoing votes:
4747
### Rule #10
4848
Upvotes and downvotes should have a maximum weigh, configurable. So that rule **#8** doesn't make vote points tend to infinity.
4949

50+
### Rule #11
51+
Optional: you can limit upvotes and downvotes to recent posts. In other words, if a message is too old, users won't be able to vote it.
52+
You can configure what "too old" means for you, for example 30 days, 90 days, or 0 if you want to disable this feature and allow votes in old posts.
53+
**Note** unvotes are always allowed.
54+
5055
### (TO-DO)
5156
- Ban for low reputation

ReputationManager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ var ReputationManager = function (Config) {
1414
userPermissions.isOldEnoughToUpvote,
1515
userPermissions.hasVotedTooManyPostsInThread,
1616
userPermissions.hasVotedAuthorTooManyTimesThisMonth,
17-
userPermissions.hasVotedTooManyTimesToday
17+
userPermissions.hasVotedTooManyTimesToday,
18+
userPermissions.postIsNotTooOld
1819
],
1920
function (err) {
2021
if (err) {
@@ -41,7 +42,8 @@ var ReputationManager = function (Config) {
4142
userPermissions.hasEnoughReputationToDownvote,
4243
userPermissions.hasVotedTooManyPostsInThread,
4344
userPermissions.hasVotedAuthorTooManyTimesThisMonth,
44-
userPermissions.hasVotedTooManyTimesToday
45+
userPermissions.hasVotedTooManyTimesToday,
46+
userPermissions.postIsNotTooOld
4547
],
4648
function (err) {
4749
if (err) {

UserVotingPermissions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ var UserVotingPermissions = function (Config, db, user, post) {
8888
else callback();
8989
};
9090

91+
this.postIsNotTooOld = function (callback) {
92+
if (Config.getMaxPostAgeDays() === 0) return callback();
93+
94+
var now = new Date();
95+
var postAgeDays = (now - _this.post.timestamp)/24/60/60/1000;
96+
if (postAgeDays > Config.getMaxPostAgeDays()) callback({'reason': 'postTooOld'});
97+
else callback();
98+
};
99+
91100
function countVotesInThread(userId, threadId, callback) {
92101
var voteIdentifier = Config.getPerThreadLogId(userId, threadId);
93102
db.getSetMembers(voteIdentifier, function (err, setMembers) {

library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
var plugin = {'settingsVersion': '1.0.4'},
3+
var plugin = {'settingsVersion': '1.1.0'},
44
db = module.parent.require('./database'),
55
users = module.parent.require('./user'),
66
meta = module.parent.require('./meta'),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nodebb-plugin-reputation-rules",
3-
"version": "1.0.4",
3+
"version": "1.1.0",
44
"description": "Reputation rules to prevent abuse and make it more reliable",
55
"main": "library.js",
66
"repository": {

public/languages/en_GB/nodebb-plugin-reputation-rules.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"tooManyVotesInThread": "You can't vote more messages in this thread",
77
"tooManyVotesToSameUserThisMonth": "You can't vote this user again until next month",
88
"tooManyVotesToday": "You can't vote more messages today",
9+
"postTooOld": "You can't vote this message, it is too old",
910
"unknownError": "Error voting"
1011
}

public/languages/es/nodebb-plugin-reputation-rules.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"tooManyVotesInThread": "No puedes votar más mensajes en este hilo",
77
"tooManyVotesToSameUserThisMonth": "Ya has votado a este usuario este mes",
88
"tooManyVotesToday": "No puedes votar más mensajes hoy",
9+
"postTooOld": "No puedes votar este mensaje, es muy antiguo",
910
"unknownError": "Error al votar"
1011
}

public/templates/admin/plugins/reputation-rules.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@
138138
<div data-key="disabledCategoriesIds" data-attributes='{"data-type":"input", "style":"width:80%;margin-bottom:10px;"}' data-split="<br>" data-new='' style="width:100%;"></div>
139139
<br>
140140
</div>
141+
142+
<div class="form-group">
143+
<!-- (MAX_POST_AGE_DAYS) -->
144+
<label>Maximum post age, in number of days, to allow votes:</label>
145+
<input class="form-control" type="number" data-key="maxPostAgeDays" title="Maximum post age, in number of days, to allow votes">
146+
<p class="help-block">Enter zero to disable this and allow votes to any post. Unvotes are ALWAYS allowed.</p>
147+
<br>
148+
</div>
141149
</div>
142150
</div>
143151

0 commit comments

Comments
 (0)