be conditional and include quote with input board properly

merge-requests/208/head
fatchan 5 years ago
parent f05a8b0e68
commit 170badab6c
  1. 37
      helpers/quotes.js

@ -54,7 +54,6 @@ module.exports = async (board, text) => {
//get all the posts from quotes //get all the posts from quotes
const posts = await Posts.getPostsForQuotes(queryOrs); const posts = await Posts.getPostsForQuotes(queryOrs);
//if none of the quotes were real, dont do a replace //if none of the quotes were real, dont do a replace
if (posts.length === 0) { if (posts.length === 0) {
return text; return text;
@ -71,22 +70,26 @@ module.exports = async (board, text) => {
} }
//then replace the quotes with only ones that exist //then replace the quotes with only ones that exist
text = text.replace(quoteRegex, (match) => { if (quotes) {
const quotenum = +match.substring(2); text = text.replace(quoteRegex, (match) => {
if (postThreadIdMap[quotenum]) { const quotenum = +match.substring(2);
return `<a class='quote' href='/${board}/thread/${postThreadIdMap[board][quotenum]}#${quotenum}'>&gt;&gt;${quotenum}</a>`; if (postThreadIdMap[board] && postThreadIdMap[board][quotenum]) {
} return `<a class='quote' href='/${board}/thread/${postThreadIdMap[board][quotenum]}#${quotenum}'>&gt;&gt;${quotenum}</a>`;
return match; }
}); return match;
text = text.replace(crossQuoteRegex, (match) => { });
const quote = match.split('/'); }
const quoteboard = quote[1]; if (crossQuotes) {
const quotenum = +quote[2]; text = text.replace(crossQuoteRegex, (match) => {
if (postThreadIdMap[quoteboard] && postThreadIdMap[quoteboard][quotenum]) { const quote = match.split('/');
return `<a class='quote' href='/${quoteboard}/thread/${postThreadIdMap[quoteboard][quotenum]}#${quotenum}'>&gt;&gt;&gt;/${quoteboard}/${quotenum}</a>`; const quoteboard = quote[1];
} const quotenum = +quote[2];
return match; if (postThreadIdMap[quoteboard] && postThreadIdMap[quoteboard][quotenum]) {
}); return `<a class='quote' href='/${quoteboard}/thread/${postThreadIdMap[quoteboard][quotenum]}#${quotenum}'>&gt;&gt;&gt;/${quoteboard}/${quotenum}</a>`;
}
return match;
});
}
return text; return text;

Loading…
Cancel
Save