|
|
@ -5,7 +5,7 @@ const Posts = require(__dirname+'/../../db/posts.js') |
|
|
|
, quoteRegex = />>\d+/g |
|
|
|
, quoteRegex = />>\d+/g |
|
|
|
, crossQuoteRegex = />>>\/\w+\/\d*$/gm; |
|
|
|
, crossQuoteRegex = />>>\/\w+\/\d*$/gm; |
|
|
|
|
|
|
|
|
|
|
|
module.exports = async (board, text) => { |
|
|
|
module.exports = async (board, text, thread) => { |
|
|
|
|
|
|
|
|
|
|
|
//get the matches
|
|
|
|
//get the matches
|
|
|
|
const quotes = text.match(quoteRegex); |
|
|
|
const quotes = text.match(quoteRegex); |
|
|
@ -66,29 +66,38 @@ module.exports = async (board, text) => { |
|
|
|
if (!postThreadIdMap[post.board]) { |
|
|
|
if (!postThreadIdMap[post.board]) { |
|
|
|
postThreadIdMap[post.board] = {}; |
|
|
|
postThreadIdMap[post.board] = {}; |
|
|
|
} |
|
|
|
} |
|
|
|
postThreadIdMap[post.board][post.postId] = post.thread || post.postId; |
|
|
|
postThreadIdMap[post.board][post.postId] = { |
|
|
|
|
|
|
|
'_id': post._id, |
|
|
|
|
|
|
|
'thread': post.thread || post.postId, |
|
|
|
|
|
|
|
'postId': post.postId |
|
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//then replace the quotes with only ones that exist
|
|
|
|
//then replace the quotes with only ones that exist
|
|
|
|
|
|
|
|
const addedQuotes = new Set(); |
|
|
|
const threadQuotes = []; |
|
|
|
const threadQuotes = []; |
|
|
|
if (quotes && Object.keys(postThreadIdMap).length > 0) { |
|
|
|
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]) { |
|
|
|
threadQuotes.push(quotenum) |
|
|
|
if (!addedQuotes.has(postThreadIdMap[board][quotenum]._id) && postThreadIdMap[board][quotenum].thread === thread) { |
|
|
|
return `<a class='quote' href='/${board}/thread/${postThreadIdMap[board][quotenum]}.html#${quotenum}'>>>${quotenum}</a>${postThreadIdMap[board][quotenum] === quotenum ? ' <small>(OP)</small> ' : ''}`; |
|
|
|
threadQuotes.push(postThreadIdMap[board][quotenum]); |
|
|
|
|
|
|
|
addedQuotes.add(postThreadIdMap[board][quotenum]._id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return `<a class='quote' href='/${board}/thread/${postThreadIdMap[board][quotenum].thread}.html#${quotenum}'>>>${quotenum}</a>${postThreadIdMap[board][quotenum].postId == thread ? ' <small>(OP)</small> ' : ''}`; |
|
|
|
} |
|
|
|
} |
|
|
|
return match; |
|
|
|
return match; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (crossQuotes) { |
|
|
|
if (crossQuotes) { |
|
|
|
text = text.replace(crossQuoteRegex, (match) => { |
|
|
|
text = text.replace(crossQuoteRegex, (match) => { |
|
|
|
const quote = match.split('/'); |
|
|
|
const quote = match.split('/'); |
|
|
|
const quoteboard = quote[1]; |
|
|
|
const quoteboard = quote[1]; |
|
|
|
const quotenum = +quote[2]; |
|
|
|
const quotenum = +quote[2]; |
|
|
|
if (postThreadIdMap[quoteboard] && postThreadIdMap[quoteboard][quotenum]) { |
|
|
|
if (postThreadIdMap[quoteboard] && postThreadIdMap[quoteboard][quotenum]) { |
|
|
|
return `<a class='quote' href='/${quoteboard}/thread/${postThreadIdMap[quoteboard][quotenum]}.html#${quotenum}'>>>>/${quoteboard}/${quotenum}</a>`; |
|
|
|
return `<a class='quote' href='/${quoteboard}/thread/${postThreadIdMap[quoteboard][quotenum].thread}.html#${quotenum}'>>>>/${quoteboard}/${quotenum}</a>`; |
|
|
|
} else if (!quote[2]) { |
|
|
|
} else if (!quote[2]) { |
|
|
|
return `<a class='quote' href='/${quoteboard}/index.html'>>>>/${quoteboard}/</a>`; |
|
|
|
return `<a class='quote' href='/${quoteboard}/index.html'>>>>/${quoteboard}/</a>`; |
|
|
|
} |
|
|
|
} |
|
|
@ -96,6 +105,6 @@ module.exports = async (board, text) => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { quotedMessage: text, threadQuotes: [...new Set(threadQuotes)] }; |
|
|
|
return { quotedMessage: text, threadQuotes }; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|