jschan - Anonymous imageboard software. Classic look, modern features and feel. Works without JavaScript and supports Tor, I2P, Lokinet, etc.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

45 lines
1.1 KiB

'use strict';
const Posts = require(__dirname+'/../db/posts.js')
, quoteRegex = />>\d+/gm;
module.exports = async (board, text) => {
//get the matches
const matches = text.match(quoteRegex);
if (!matches) {
return text;
}
//get all the Ids
const quoteIds = matches.map(x => +x.substring(2));
//get all posts with those Ids
const posts = await Posts.getPosts(board, quoteIds, false);
//turn the result into a map of postId => threadId/postId
const postThreadObject = {};
let validQuotes = 0;
for (let i = 0; i < posts.length; i++) {
const post = posts[i];
postThreadObject[post.postId] = post.thread || post.postId;
validQuotes++;
}
//if none of the quotes were real, dont do a replace
if (validQuotes === 0) {
return text;
}
//then replace the quotes with only ones that exist
text = text.replace(quoteRegex, (match) => {
const quotenum = +match.substring(2);
if (postThreadObject[quotenum]) {
return `<a class='quote' href='/${board}/thread/${postThreadObject[quotenum]}#${quotenum}'>&gt;&gt;${quotenum}</a>`;
}
return match;
});
return text;
}