fix: comment filter

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-04-17 20:38:33 +08:00
parent 73abe9c1af
commit ec58221ee6
2 changed files with 34 additions and 1 deletions

View File

@@ -35,6 +35,7 @@ import { getAvatar } from '~/utils'
import { CommentState } from '../comment/comment.model'
import { CommentService } from '../comment/comment.service'
import { ConfigsService } from '../configs/configs.service'
import { Activity } from './activity.constant'
import { ActivityModel } from './activity.model'
import {
@@ -65,6 +66,7 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {
private readonly webGateway: WebEventsGateway,
private readonly gatewayService: GatewayService,
private readonly configsService: ConfigsService,
) {
this.logger = new Logger(ActivityService.name)
}
@@ -498,10 +500,17 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {
}
async getRecentComment() {
const configs = await this.configsService.get('commentOptions')
const { commentShouldAudit } = configs
const docs = await this.commentService.model
.find({
isWhispers: false,
state: CommentState.Read,
state: commentShouldAudit
? CommentState.Read
: {
$in: [CommentState.Read, CommentState.Unread],
},
})
.populate('ref', 'title nid slug category')

View File

@@ -20,7 +20,9 @@ import { InjectModel } from '~/transformers/model.transformer'
import { getRedisKey, scheduleManager } from '~/utils'
import { normalizeRefType } from '~/utils/database.util'
import { CommentState } from '../comment/comment.model'
import { CommentService } from '../comment/comment.service'
import { ConfigsService } from '../configs/configs.service'
import { RecentlyAttitudeEnum } from './recently.dto'
import { RecentlyModel } from './recently.model'
@@ -36,6 +38,7 @@ export class RecentlyService {
private readonly cacheService: CacheService,
@Inject(forwardRef(() => CommentService))
private readonly commentService: CommentService,
private readonly configsService: ConfigsService,
) {}
public get model() {
@@ -179,6 +182,9 @@ export class RecentlyService {
}) {
size = size ?? 10
const configs = await this.configsService.get('commentOptions')
const { commentShouldAudit } = configs
const result = await this.recentlyModel.aggregate([
{
$match: after
@@ -198,6 +204,24 @@ export class RecentlyService {
as: 'comment',
foreignField: 'ref',
localField: '_id',
pipeline: [
{
$match: commentShouldAudit
? {
state: CommentState.Read,
}
: {
$or: [
{
state: CommentState.Read,
},
{
state: CommentState.Unread,
},
],
},
},
],
},
},