mirror of
https://github.com/luxfi/pics.git
synced 2026-10-30 15:22:15 +00:00
33 lines
913 B
JavaScript
33 lines
913 B
JavaScript
'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;
|
|
};
|