Cross board post move bugfixes/changes

merge-requests/341/head
Thomas Lynch 1 year ago
parent 379e7b6287
commit 344ed5f662
  1. 7
      db/posts.js
  2. 17
      models/forms/moveposts.js

@ -811,7 +811,7 @@ module.exports = {
},
'update': {
'$set': {
'postId': lastId - index,
'postId': newDestinationThreadId + index,
}
}
}
@ -864,8 +864,9 @@ module.exports = {
}
});
}
//console.log(JSON.stringify(bulkWrites, null, 4));
return db.bulkWrite(bulkWrites);
// console.log(JSON.stringify(bulkWrites, null, 4))
const movedPosts = await db.bulkWrite(bulkWrites).then(result => result.modifiedCount);
return { movedPosts, destinationThreadId: newDestinationThreadId };
},
threadExists: (board, thread) => {

@ -113,14 +113,20 @@ module.exports = async (req, res) => {
const destinationBoard = res.locals.destinationBoard ? res.locals.destinationBoard._id : req.params.board;
const crossBoard = destinationBoard !== req.params.board;
const destinationThreadId = res.locals.destinationThread ? res.locals.destinationThread.postId : (crossBoard ? null : postIds[0]);
const movedPosts = await Posts.move(postMongoIds, crossBoard, destinationThreadId, destinationBoard).then(result => result.modifiedCount);
let destinationThreadId = res.locals.destinationThread ? res.locals.destinationThread.postId : (crossBoard ? null : postIds[0])
, movedPosts = 0;
({ destinationThreadId, movedPosts } = await Posts.move(postMongoIds, crossBoard, destinationThreadId, destinationBoard));
//emit markPost moves
for (let i = 0; i < moveEmits.length; i++) {
Socketio.emitRoom(moveEmits[i].room, 'markPost', { postId: moveEmits[i].postId, type: 'move', mark: 'Moved' });
}
//no destination thread specified (making new thread from posts), need to fetch OP as destinationThread for remarkup/salt
if (!res.locals.destinationThread) {
res.locals.destinationThread = await Posts.threadExists(destinationBoard, destinationThreadId);
}
//get posts that quoted moved posts so we can remarkup them
if (backlinkRebuilds.size > 0) {
const remarkupPosts = await Posts.globalGetPosts([...backlinkRebuilds]);
@ -168,13 +174,6 @@ module.exports = async (req, res) => {
}));
}
/*
- post A quotes B, then A is moved to another thread: WORKS (removes backlink on B)
- moving post A back into thread with B and backlink gets readded: WORKS
- move post B out and backlink from A gets removed: WORKS
- moving post B post back into thread with A and backlinks re-added: FAIL (need to come up with solution, but this is an uncommon occurence)
*/
//bulkwrite it all
if (bulkWrites.length > 0) {
await Posts.db.bulkWrite(bulkWrites);

Loading…
Cancel
Save