29 lines
633 B
JavaScript
29 lines
633 B
JavaScript
const { isPublicPostStatus } = require('./moderationStatus')
|
|
|
|
function applyReportHiddenFilter (filter = {}) {
|
|
const hiddenGuard = {
|
|
$or: [
|
|
{ report_hidden: false },
|
|
{ report_hidden: { $exists: false } },
|
|
{ report_hidden: null },
|
|
],
|
|
}
|
|
|
|
if (filter.$and) {
|
|
return { ...filter, $and: [...filter.$and, hiddenGuard] }
|
|
}
|
|
|
|
return { ...filter, $and: [hiddenGuard] }
|
|
}
|
|
|
|
function isPostPubliclyVisible (post) {
|
|
if (!post) return false
|
|
if (!isPublicPostStatus(post.status)) return false
|
|
return post.report_hidden !== true
|
|
}
|
|
|
|
module.exports = {
|
|
applyReportHiddenFilter,
|
|
isPostPubliclyVisible,
|
|
}
|