|
|
|
|
@ -1,4 +1,11 @@ |
|
|
|
|
import type { IMessage, IModerationAudit, IModerationReport, RocketChatRecordDeleted } from '@rocket.chat/core-typings'; |
|
|
|
|
import type { |
|
|
|
|
IMessage, |
|
|
|
|
IModerationAudit, |
|
|
|
|
IModerationReport, |
|
|
|
|
RocketChatRecordDeleted, |
|
|
|
|
MessageReport, |
|
|
|
|
UserReport, |
|
|
|
|
} from '@rocket.chat/core-typings'; |
|
|
|
|
import type { FindPaginated, IModerationReportsModel, PaginationParams } from '@rocket.chat/model-typings'; |
|
|
|
|
import type { AggregationCursor, Collection, Db, Document, FindCursor, FindOptions, IndexDescription, UpdateResult } from 'mongodb'; |
|
|
|
|
|
|
|
|
|
@ -13,6 +20,7 @@ export class ModerationReportsRaw extends BaseRaw<IModerationReport> implements |
|
|
|
|
return [ |
|
|
|
|
{ key: { 'ts': 1, 'reports.ts': 1 } }, |
|
|
|
|
{ key: { 'message.u._id': 1, 'ts': 1 } }, |
|
|
|
|
{ key: { 'reportedUser._id': 1, 'ts': 1 } }, |
|
|
|
|
{ key: { 'message.rid': 1, 'ts': 1 } }, |
|
|
|
|
{ key: { userId: 1, ts: 1 } }, |
|
|
|
|
{ key: { 'message._id': 1, 'ts': 1 } }, |
|
|
|
|
@ -21,7 +29,7 @@ export class ModerationReportsRaw extends BaseRaw<IModerationReport> implements |
|
|
|
|
|
|
|
|
|
createWithMessageDescriptionAndUserId( |
|
|
|
|
message: IMessage, |
|
|
|
|
description: string, |
|
|
|
|
description: IModerationReport['description'], |
|
|
|
|
room: IModerationReport['room'], |
|
|
|
|
reportedBy: IModerationReport['reportedBy'], |
|
|
|
|
): ReturnType<BaseRaw<IModerationReport>['insertOne']> { |
|
|
|
|
@ -35,7 +43,22 @@ export class ModerationReportsRaw extends BaseRaw<IModerationReport> implements |
|
|
|
|
return this.insertOne(record); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
findReportsGroupedByUser( |
|
|
|
|
createWithDescriptionAndUser( |
|
|
|
|
reportedUser: UserReport['reportedUser'], |
|
|
|
|
description: UserReport['description'], |
|
|
|
|
reportedBy: UserReport['reportedBy'], |
|
|
|
|
): ReturnType<BaseRaw<IModerationReport>['insertOne']> { |
|
|
|
|
const record = { |
|
|
|
|
description, |
|
|
|
|
reportedBy, |
|
|
|
|
reportedUser, |
|
|
|
|
ts: new Date(), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return this.insertOne(record); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
findMessageReportsGroupedByUser( |
|
|
|
|
latest: Date, |
|
|
|
|
oldest: Date, |
|
|
|
|
selector: string, |
|
|
|
|
@ -109,7 +132,7 @@ export class ModerationReportsRaw extends BaseRaw<IModerationReport> implements |
|
|
|
|
return this.col.aggregate(params, { allowDiskUse: true }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
countReportsInRange(latest: Date, oldest: Date, selector: string): Promise<number> { |
|
|
|
|
countMessageReportsInRange(latest: Date, oldest: Date, selector: string): Promise<number> { |
|
|
|
|
return this.col.countDocuments({ |
|
|
|
|
_hidden: { $ne: true }, |
|
|
|
|
ts: { $lt: latest, $gt: oldest }, |
|
|
|
|
@ -122,7 +145,7 @@ export class ModerationReportsRaw extends BaseRaw<IModerationReport> implements |
|
|
|
|
selector: string, |
|
|
|
|
pagination: PaginationParams<IModerationReport>, |
|
|
|
|
options: FindOptions<IModerationReport> = {}, |
|
|
|
|
): FindPaginated<FindCursor<Pick<IModerationReport, '_id' | 'message' | 'ts' | 'room'>>> { |
|
|
|
|
): FindPaginated<FindCursor<Pick<MessageReport, '_id' | 'message' | 'ts' | 'room'>>> { |
|
|
|
|
const query = { |
|
|
|
|
'_hidden': { |
|
|
|
|
$ne: true, |
|
|
|
|
@ -134,14 +157,10 @@ export class ModerationReportsRaw extends BaseRaw<IModerationReport> implements |
|
|
|
|
|
|
|
|
|
const fuzzyQuery = selector |
|
|
|
|
? { |
|
|
|
|
$or: [ |
|
|
|
|
{ |
|
|
|
|
'message.msg': { |
|
|
|
|
$regex: selector, |
|
|
|
|
$options: 'i', |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
'message.msg': { |
|
|
|
|
$regex: selector, |
|
|
|
|
$options: 'i', |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
: {}; |
|
|
|
|
|
|
|
|
|
@ -198,7 +217,7 @@ export class ModerationReportsRaw extends BaseRaw<IModerationReport> implements |
|
|
|
|
return this.findPaginated(query, opts); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async hideReportsByMessageId(messageId: string, userId: string, reason: string, action: string): Promise<UpdateResult | Document> { |
|
|
|
|
async hideMessageReportsByMessageId(messageId: string, userId: string, reason: string, action: string): Promise<UpdateResult | Document> { |
|
|
|
|
const query = { |
|
|
|
|
'message._id': messageId, |
|
|
|
|
}; |
|
|
|
|
@ -213,7 +232,7 @@ export class ModerationReportsRaw extends BaseRaw<IModerationReport> implements |
|
|
|
|
return this.updateMany(query, update); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async hideReportsByUserId(userId: string, moderatorId: string, reason: string, action: string): Promise<UpdateResult | Document> { |
|
|
|
|
async hideMessageReportsByUserId(userId: string, moderatorId: string, reason: string, action: string): Promise<UpdateResult | Document> { |
|
|
|
|
const query = { |
|
|
|
|
'message.u._id': userId, |
|
|
|
|
}; |
|
|
|
|
@ -228,10 +247,12 @@ export class ModerationReportsRaw extends BaseRaw<IModerationReport> implements |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private getSearchQueryForSelector(selector?: string): any { |
|
|
|
|
const messageExistsQuery = { message: { $exists: true } }; |
|
|
|
|
if (!selector) { |
|
|
|
|
return {}; |
|
|
|
|
return messageExistsQuery; |
|
|
|
|
} |
|
|
|
|
return { |
|
|
|
|
...messageExistsQuery, |
|
|
|
|
$or: [ |
|
|
|
|
{ |
|
|
|
|
'message.msg': { |
|
|
|
|
|