mirror of https://gitgud.io/fatchan/jschan.git
bit simpler deleting of quotes in deletepost.js, simple string repacement instead of remarking the whole post.
and refactor the deleting to return the bulkwrites partly related to #215, moveposts/editposts it makes sense to remarkup because in those case we can even be adding quotes.indiachan-spamvector
parent
676e861f82
commit
e4d6ae59ad
2 changed files with 33 additions and 24 deletions
@ -0,0 +1,30 @@ |
||||
'use strict'; |
||||
|
||||
//use simple string replacement and filter to remove dead quotes, instead of running the whole messagehandler again
|
||||
module.exports = (deletedPosts, updateQuotePosts) => { |
||||
const bulkWrites = []; |
||||
updateQuotePosts.forEach(post => { |
||||
deletedPosts.forEach(ap => { |
||||
const quotesBefore = post.quotes.length; |
||||
post.quotes = post.quotes.filter(q => q.postId !== ap.postId); |
||||
if (quotesBefore !== post.quotes.length) { //optimization, probably
|
||||
post.message = post.message.replace(`<a class="quote" href="/${ap.board}/thread/${ap.thread}.html#${ap.postId}">>>${ap.postId}</a>`, |
||||
`<span class="invalid-quote">>>${ap.postId}</span>`); |
||||
} |
||||
}); |
||||
bulkWrites.push({ |
||||
'updateOne': { |
||||
'filter': { |
||||
'_id': post._id |
||||
}, |
||||
'update': { |
||||
'$set': { |
||||
'quotes': post.quotes, |
||||
'message': post.message, |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
}); |
||||
return bulkWrites; |
||||
}; |
Loading…
Reference in new issue