mirror of
https://github.com/wassname/talk.git
synced 2026-08-11 11:27:10 +08:00
Exclude deleted comments
This commit is contained in:
@@ -432,6 +432,7 @@ const withModQueueQuery = withQuery(
|
||||
${Object.keys(queueConfig).map(
|
||||
queue => `
|
||||
${queue}: comments(query: {
|
||||
excludeDeleted: true,
|
||||
statuses: ${
|
||||
queueConfig[queue].statuses
|
||||
? `[${queueConfig[queue].statuses.join(', ')}],`
|
||||
@@ -458,6 +459,7 @@ const withModQueueQuery = withQuery(
|
||||
${Object.keys(queueConfig).map(
|
||||
queue => `
|
||||
${queue}Count: commentCount(query: {
|
||||
excludeDeleted: true,
|
||||
statuses: ${
|
||||
queueConfig[queue].statuses
|
||||
? `[${queueConfig[queue].statuses.join(', ')}],`
|
||||
|
||||
+24
-10
@@ -94,6 +94,7 @@ const getCommentCountByQuery = (ctx, options) => {
|
||||
author_id,
|
||||
tags,
|
||||
action_type,
|
||||
excludeDeleted,
|
||||
} = options;
|
||||
|
||||
// If user queries for statuses other than NONE and/or ACCEPTED statuses, it needs
|
||||
@@ -120,6 +121,12 @@ const getCommentCountByQuery = (ctx, options) => {
|
||||
query.merge({ author_id });
|
||||
}
|
||||
|
||||
if (excludeDeleted) {
|
||||
// The null query matches documents that either contain the `deleted_at`
|
||||
// field whose value is null or that do not contain the `deleted_at` field.
|
||||
query.merge({ deleted_at: null });
|
||||
}
|
||||
|
||||
if (ctx.user != null && ctx.user.can(SEARCH_OTHERS_COMMENTS) && action_type) {
|
||||
query.merge({
|
||||
[`action_counts.${sc(action_type.toLowerCase())}`]: {
|
||||
@@ -328,11 +335,12 @@ const getCommentsByQuery = async (
|
||||
sortOrder,
|
||||
sortBy,
|
||||
excludeIgnored,
|
||||
excludeDeleted,
|
||||
tags,
|
||||
action_type,
|
||||
}
|
||||
) => {
|
||||
let comments = CommentModel.find();
|
||||
const query = CommentModel.find();
|
||||
|
||||
// Enforce that the limit must be gte 0 if this option is not true.
|
||||
if (!ALLOW_NO_LIMIT_QUERIES && limit < 0) {
|
||||
@@ -350,11 +358,17 @@ const getCommentsByQuery = async (
|
||||
}
|
||||
|
||||
if (statuses) {
|
||||
comments = comments.where({ status: { $in: statuses } });
|
||||
query.merge({ status: { $in: statuses } });
|
||||
}
|
||||
|
||||
if (excludeDeleted) {
|
||||
// The null query matches documents that either contain the `deleted_at`
|
||||
// field whose value is null or that do not contain the `deleted_at` field.
|
||||
query.merge({ deleted_at: null });
|
||||
}
|
||||
|
||||
if (ctx.user != null && ctx.user.can(SEARCH_OTHERS_COMMENTS) && action_type) {
|
||||
comments = comments.where({
|
||||
query.merge({
|
||||
[`action_counts.${sc(action_type.toLowerCase())}`]: {
|
||||
$gt: 0,
|
||||
},
|
||||
@@ -362,7 +376,7 @@ const getCommentsByQuery = async (
|
||||
}
|
||||
|
||||
if (ids) {
|
||||
comments = comments.find({
|
||||
query.merge({
|
||||
id: {
|
||||
$in: ids,
|
||||
},
|
||||
@@ -370,7 +384,7 @@ const getCommentsByQuery = async (
|
||||
}
|
||||
|
||||
if (tags) {
|
||||
comments = comments.find({
|
||||
query.merge({
|
||||
'tags.tag.name': {
|
||||
$in: tags,
|
||||
},
|
||||
@@ -383,17 +397,17 @@ const getCommentsByQuery = async (
|
||||
(ctx.user.can(SEARCH_OTHERS_COMMENTS) || ctx.user.id === author_id) &&
|
||||
author_id != null
|
||||
) {
|
||||
comments = comments.where({ author_id });
|
||||
query.merge({ author_id });
|
||||
}
|
||||
|
||||
if (asset_id) {
|
||||
comments = comments.where({ asset_id });
|
||||
query.merge({ asset_id });
|
||||
}
|
||||
|
||||
// We perform the undefined check because, null, is a valid state for the
|
||||
// search to be with, which indicates that it is at depth 0.
|
||||
if (parent_id !== undefined) {
|
||||
comments = comments.where({ parent_id });
|
||||
query.merge({ parent_id });
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -402,12 +416,12 @@ const getCommentsByQuery = async (
|
||||
ctx.user.ignoresUsers &&
|
||||
ctx.user.ignoresUsers.length > 0
|
||||
) {
|
||||
comments = comments.where({
|
||||
query.merge({
|
||||
author_id: { $nin: ctx.user.ignoresUsers },
|
||||
});
|
||||
}
|
||||
|
||||
return executeWithSort(ctx, comments, { cursor, sortOrder, sortBy, limit });
|
||||
return executeWithSort(ctx, query, { cursor, sortOrder, sortBy, limit });
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+10
-1
@@ -418,6 +418,9 @@ input CommentsQuery {
|
||||
|
||||
# Exclude comments ignored by the requesting user
|
||||
excludeIgnored: Boolean
|
||||
|
||||
# excludeDeleted when true will exclude deleted comments from the response.
|
||||
excludeDeleted: Boolean = false
|
||||
}
|
||||
|
||||
input RepliesQuery {
|
||||
@@ -434,6 +437,9 @@ input RepliesQuery {
|
||||
|
||||
# Exclude comments ignored by the requesting user
|
||||
excludeIgnored: Boolean
|
||||
|
||||
# excludeDeleted when true will exclude deleted comments from the response.
|
||||
excludeDeleted: Boolean = false
|
||||
}
|
||||
|
||||
# CommentCountQuery allows the ability to query comment counts by specific
|
||||
@@ -463,6 +469,9 @@ input CommentCountQuery {
|
||||
|
||||
# Filter by a specific tag name.
|
||||
tags: [String!]
|
||||
|
||||
# excludeDeleted when true will exclude deleted comments from the count.
|
||||
excludeDeleted: Boolean = false
|
||||
}
|
||||
|
||||
# UserCountQuery allows the ability to query user counts by specific
|
||||
@@ -519,7 +528,7 @@ type Comment {
|
||||
replies(query: RepliesQuery = {}): CommentConnection!
|
||||
|
||||
# replyCount is the number of replies with a depth of 1. Only direct replies
|
||||
# to this comment are counted.
|
||||
# to this comment are counted. Deleted comments are included in this count.
|
||||
replyCount: Int
|
||||
|
||||
# Actions completed on the parent. Requires the `ADMIN` role.
|
||||
|
||||
@@ -39,9 +39,12 @@ module.exports = {
|
||||
const created_at = new Date();
|
||||
|
||||
// Check to see if we are replying to a comment, and if that comment is
|
||||
// visible.
|
||||
// visible and that it's not deleted.
|
||||
if (parent_id !== null) {
|
||||
const parent = await CommentModel.findOne({ id: parent_id });
|
||||
const parent = await CommentModel.findOne({
|
||||
id: parent_id,
|
||||
deleted_at: null,
|
||||
});
|
||||
if (parent === null || !parent.visible) {
|
||||
throw new ErrParentDoesNotVisible();
|
||||
}
|
||||
@@ -94,6 +97,7 @@ module.exports = {
|
||||
status: {
|
||||
$in: EDITABLE_STATUSES,
|
||||
},
|
||||
deleted_at: null,
|
||||
};
|
||||
|
||||
// Establish the edit window (if it exists) and add the condition to the
|
||||
@@ -186,8 +190,10 @@ module.exports = {
|
||||
*/
|
||||
pushStatus: async (id, status, assigned_by = null) => {
|
||||
const created_at = new Date();
|
||||
|
||||
// Update the comment unless the comment was deleted.
|
||||
const originalComment = await CommentModel.findOneAndUpdate(
|
||||
{ id },
|
||||
{ id, deleted_at: null },
|
||||
{
|
||||
$push: {
|
||||
status_history: {
|
||||
|
||||
Reference in New Issue
Block a user