dont allow cross-board quotes so current board and properly handle quote errors

merge-requests/208/head
fatchan 5 years ago
parent ecba75c975
commit c2bdcbe9dd
  1. 9
      helpers/quotes.js

@ -31,7 +31,7 @@ module.exports = async (board, text) => {
const crossQuote = crossQuotes[i].split('/'); const crossQuote = crossQuotes[i].split('/');
const crossQuoteBoard = crossQuote[1]; const crossQuoteBoard = crossQuote[1];
const crossQuotePostId = +crossQuote[2]; const crossQuotePostId = +crossQuote[2];
if (crossQuoteBoard === board || crossQuotePostId === 0) { //zero for no postid, i.e. just a board quote if (crossQuoteBoard === board) {
continue; continue;
} }
if (!crossQuoteMap[crossQuoteBoard]) { if (!crossQuoteMap[crossQuoteBoard]) {
@ -53,14 +53,14 @@ module.exports = async (board, text) => {
} }
//get all the posts from quotes //get all the posts from quotes
const postThreadIdMap = {};
if (queryOrs.length > 0) {
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;
} }
//turn the result into a map of postId => threadId/postId //turn the result into a map of postId => threadId/postId
const postThreadIdMap = {};
for (let i = 0; i < posts.length; i++) { for (let i = 0; i < posts.length; i++) {
const post = posts[i]; const post = posts[i];
if (!postThreadIdMap[post.board]) { if (!postThreadIdMap[post.board]) {
@ -68,9 +68,10 @@ module.exports = async (board, text) => {
} }
postThreadIdMap[post.board][post.postId] = post.thread || post.postId; postThreadIdMap[post.board][post.postId] = post.thread || post.postId;
} }
}
//then replace the quotes with only ones that exist //then replace the quotes with only ones that exist
if (quotes) { if (quotes && Object.keys(postThreadIdMap).length > 0) {
text = text.replace(quoteRegex, (match) => { text = text.replace(quoteRegex, (match) => {
const quotenum = +match.substring(2); const quotenum = +match.substring(2);
if (postThreadIdMap[board] && postThreadIdMap[board][quotenum]) { if (postThreadIdMap[board] && postThreadIdMap[board][quotenum]) {

Loading…
Cancel
Save