Allow sticky to be input as a number, 0 is disabled, higher numbers are a priority and threads will be sorted in descending order reference #289

merge-requests/208/head
Thomas Lynch 4 years ago
parent db60e5bbc8
commit b5580edd9e
  1. 4
      helpers/checks/actionchecker.js
  2. 4
      helpers/paramconverter.js
  3. 4
      models/forms/actionhandler.js
  4. 3
      models/forms/makepost.js
  5. 12
      models/forms/stickyposts.js
  6. 3
      views/includes/actionfooter_manage.pug

@ -34,8 +34,8 @@ module.exports = (req, res) => {
for (let i = 0; i < actions.length; i++) {
const action = actions[i];
const bodyHasAction = req.body[action.name];
if (bodyHasAction) {
const bodyAction = req.body[action.name];
if (bodyAction != null) {
validActions.push(action.name);
if (action.global) {
numGlobal++;

@ -5,7 +5,7 @@ const { ObjectId } = require(__dirname+'/../db/db.js')
'checkedreports', 'checkedbans', 'checkedbanners', 'checkedaccounts', 'countries']) //only these should be arrays, since express bodyparser can output arrays
, trimFields = ['tags', 'uri', 'moderators', 'filters', 'announcement', 'description', 'message',
'name', 'subject', 'email', 'postpassword', 'password', 'default_name', 'report_reason', 'ban_reason', 'log_message', 'custom_css'] //trim if we dont want filed with whitespace
, numberFields = ['lock_reset', 'captcha_reset', 'filter_mode', 'lock_mode', 'message_r9k_mode', 'file_r9k_mode', 'captcha_mode',
, numberFields = ['sticky', 'lock_reset', 'captcha_reset', 'filter_mode', 'lock_mode', 'message_r9k_mode', 'file_r9k_mode', 'captcha_mode',
'tph_trigger', 'pph_trigger', 'pph_trigger_action', 'tph_trigger_action', 'bump_limit', 'reply_limit', 'move_to_thread', 'postId',
'max_files', 'thread_limit', 'thread', 'max_thread_message_length', 'max_reply_message_length', 'min_thread_message_length', 'min_reply_message_length', 'auth_level'] //convert these to numbers before they hit our routes
, banDurationRegex = /^(?<YEAR>[\d]+y)?(?<MONTH>[\d]+mo)?(?<WEEK>[\d]+w)?(?<DAY>[\d]+d)?(?<HOUR>[\d]+h)?(?<MINUTE>[\d]+m)?(?<SECOND>[\d]+s)?$/
@ -47,7 +47,7 @@ module.exports = (req, res, next) => {
for (let i = 0; i < numberFields.length; i++) {
const field = numberFields[i];
if (req.body[field]) {
if (req.body[field] != null) {
const num = parseInt(req.body[field]);
if (Number.isSafeInteger(num)) {
req.body[field] = num;

@ -208,8 +208,8 @@ module.exports = async (req, res, next) => {
}
messages.push(message);
}
if (req.body.sticky) {
const { message, action, query } = stickyPosts(res.locals.posts);
if (req.body.sticky != null) {
const { message, action, query } = stickyPosts(res.locals.posts, req.body.sticky);
if (action) {
modlogActions.push('Sticky');
combinedQuery[action] = { ...combinedQuery[action], ...query}

@ -468,8 +468,9 @@ module.exports = async (req, res, next) => {
Object.assign(data, {
'replyposts': 0,
'replyfiles': 0,
//NOTE: these are numbers because we XOR them for toggling in action handler
//NOTE: sticky is a number, 0 = not sticky, higher numbers are a priority and will be sorted in descending order
'sticky': Mongo.NumberInt(0),
//NOTE: these are numbers because we XOR them for toggling in action handler
'locked': Mongo.NumberInt(0),
'bumplocked': Mongo.NumberInt(0),
'cyclic': Mongo.NumberInt(0),

@ -2,7 +2,7 @@
const { NumberInt } = require(__dirname+'/../../db/db.js')
module.exports = (posts) => {
module.exports = (posts, sticky) => {
const filteredposts = posts.filter(post => {
return !post.thread
@ -14,13 +14,13 @@ module.exports = (posts) => {
};
}
const stickyValue = NumberInt(sticky);
return {
message: `Toggled sticky for ${filteredposts.length} thread(s)`,
action: '$bit',
message: `Set sticky for ${filteredposts.length} thread(s) to ${sticky}`,
action: '$set',
query: {
'sticky': {
'xor': NumberInt(1)
},
'sticky': stickyValue,
}
};

@ -74,8 +74,7 @@ details.toggle-label#actionform
input.post-check(type='checkbox', name='edit' value='1')
| Edit Post
label
input.post-check(type='checkbox', name='sticky' value='1')
| Toggle Sticky
input(type='text', name='sticky' placeholder='Sticky priority, 0 = unsticky')
label
input.post-check(type='checkbox', name='lock' value='1')
| Toggle Lock

Loading…
Cancel
Save