Start on cross board thread moves #250

merge-requests/341/head
Thomas Lynch 1 year ago
parent 48f5651175
commit 0d6323669f
  1. 3
      controllers/forms/actions.js
  2. 4
      db/boards.js
  3. 57
      db/posts.js
  4. 4
      gulp/res/css/style.css
  5. 4
      models/forms/moveposts.js
  6. 7
      views/includes/actionfooter_manage.pug

@ -13,7 +13,7 @@ module.exports = {
paramConverter: paramConverter({
timeFields: ['ban_duration'],
trimFields: ['postpassword', 'report_reason', 'ban_reason', 'log_message'],
trimFields: ['postpassword', 'report_reason', 'ban_reason', 'log_message', 'move_to_board'],
allowedArrays: ['checkedreports', 'checkedposts'],
numberFields: ['move_to_thread', 'sticky'],
numberArrays: ['checkedposts'],
@ -84,6 +84,7 @@ module.exports = {
'referer': (req.headers.referer || `/${res.locals.posts[0].board}/manage/thread/${res.locals.posts[0].thread || res.locals.posts[0].postId}.html`) + `#${res.locals.posts[0].postId}`,
});
} else if (req.body.move) {
//TODO: update to fetch destination baord (if req.body.move_to_board), do a perms check for MANAGE_BOARD_GENERAL there, and update V
res.locals.posts = res.locals.posts.filter(p => {
//filter to remove any posts already in the thread (or the OP) of move destination
return p.postId !== req.body.move_to_thread && p.thread !== req.body.move_to_thread;

@ -504,10 +504,10 @@ module.exports = {
]).toArray();
},
getNextId: async (board, saged) => {
getNextId: async (board, saged, amount=1) => {
const update = {
'$inc': {
'sequence_value': 1
'sequence_value': amount
},
};
if (!saged) {

@ -794,25 +794,48 @@ module.exports = {
return db.deleteMany();
},
move: (ids, dest) => {
return db.updateMany({
'_id': {
'$in': ids
}
}, {
'$set': {
'thread': dest
},
'$unset': {
'replyposts': '',
'replyfiles': '',
'sticky': '',
'locked': '',
'bumplocked': '',
'cyclic': '',
'salt': ''
move: async (postMongoIds, destinationThread, destinationBoard=null) => {
let bulkWrites = []
, movePostsSet = { thread: destinationThread };
if (destinationBoard) {
//postIds need to be adjusted if moving to a different board
const lastId = await Boards.getNextId(destinationBoard, false, postMongoIds.length);
movePostsSet.board = destinationBoard;
bulkWrites = postMongoIds.map((postMongoId, index) => ({
'updateOne': {
'filter': {
'_id': postMongoId,
},
'update': {
'$set': {
'postId': lastId - index,
}
}
}
}));
}
bulkWrites.push({
'updateMany': {
'filter': {
'_id': {
'$in': postMongoIds,
}
},
'update': {
'$set': movePostsSet,
'$unset': {
'replyposts': '',
'replyfiles': '',
'sticky': '',
'locked': '',
'bumplocked': '',
'cyclic': '',
'salt': ''
}
}
}
});
return db.bulkWrite(bulkWrites);
},
threadExists: (board, thread) => {

@ -529,6 +529,10 @@ table {
max-width: 50px;
}
input[name="move_to_board"], input[name="move_to_thread"] {
max-width: 80px;
}
.w900 {
width: 900px;
}

@ -95,7 +95,7 @@ module.exports = async (req, res) => {
'updateOne': {
'filter': {
'postId': req.body.move_to_thread,
'board': req.params.board
'board': req.body.move_to_board || req.params.board,
},
'update': {
'$inc': {
@ -106,7 +106,7 @@ module.exports = async (req, res) => {
}
});
const movedPosts = await Posts.move(postMongoIds, req.body.move_to_thread).then(result => result.modifiedCount);
const movedPosts = await Posts.move(postMongoIds, req.body.move_to_thread, req.body.move_to_board).then(result => result.modifiedCount);
//emit markPost moves
for (let i = 0; i < moveEmits.length; i++) {

@ -36,8 +36,11 @@ details.toggle-label#actionform
label
input.post-check(type='checkbox', name='move' value='1')
| Move
label
input(type='number', name='move_to_thread', placeholder='Destination thread No.' autocomplete='off')
.row
label.mr-1
input(type='text', name='move_to_board', placeholder='Board' autocomplete='off')
label
input(type='number', name='move_to_thread', placeholder='Thread No.' autocomplete='off')
.col.mr-5
label
input.post-check(type='checkbox', name='report_ban' value='1')

Loading…
Cancel
Save