+ static listForApi (parameters: {
+ start: number
+ count: number
+ sort: string
+
+ serverAccountId: number
+ user?: MUserAccountId
+
+ id?: number
+ predefinedReason?: VideoAbusePredefinedReasonsString
+ state?: VideoAbuseState
+ videoIs?: VideoAbuseVideoIs
+
+ search?: string
+ searchReporter?: string
+ searchReportee?: string
+ searchVideo?: string
+ searchVideoChannel?: string
+ }) {
+ const {
+ start,
+ count,
+ sort,
+ search,
+ user,
+ serverAccountId,
+ state,
+ videoIs,
+ predefinedReason,
+ searchReportee,
+ searchVideo,
+ searchVideoChannel,
+ searchReporter,
+ id
+ } = parameters
+
+ const userAccountId = user ? user.Account.id : undefined
+ const predefinedReasonId = predefinedReason ? videoAbusePredefinedReasonsMap[predefinedReason] : undefined
+
+ const query = {
+ offset: start,
+ limit: count,
+ order: getSort(sort),
+ col: 'VideoAbuseModel.id',
+ distinct: true
+ }
+
+ const filters = {
+ id,
+ predefinedReasonId,
+ search,
+ state,
+ videoIs,
+ searchReportee,
+ searchVideo,
+ searchVideoChannel,
+ searchReporter,
+ serverAccountId,
+ userAccountId
+ }
+
+ return VideoAbuseModel
+ .scope([
+ { method: [ ScopeNames.FOR_API, filters ] }
+ ])
+ .findAndCountAll(query)
+ .then(({ rows, count }) => {
+ return { total: count, data: rows }
+ })
+ }
+
+ toFormattedJSON (this: MVideoAbuseFormattable): VideoAbuse {
+ const predefinedReasons = VideoAbuseModel.getPredefinedReasonsStrings(this.predefinedReasons)
+ const countReportsForVideo = this.get('countReportsForVideo') as number
+ const nthReportForVideo = this.get('nthReportForVideo') as number
+ const countReportsForReporterVideo = this.get('countReportsForReporter__video') as number
+ const countReportsForReporterDeletedVideo = this.get('countReportsForReporter__deletedVideo') as number
+ const countReportsForReporteeVideo = this.get('countReportsForReportee__video') as number
+ const countReportsForReporteeDeletedVideo = this.get('countReportsForReportee__deletedVideo') as number
+
+ const video = this.Video
+ ? this.Video
+ : this.deletedVideo
+
+ return {
+ id: this.id,
+ reason: this.reason,
+ predefinedReasons,
+ reporterAccount: this.Account.toFormattedJSON(),
+ state: {
+ id: this.state,
+ label: VideoAbuseModel.getStateLabel(this.state)
+ },
+ moderationComment: this.moderationComment,
+ video: {
+ id: video.id,
+ uuid: video.uuid,
+ name: video.name,
+ nsfw: video.nsfw,
+ deleted: !this.Video,
+ blacklisted: this.Video?.isBlacklisted() || false,
+ thumbnailPath: this.Video?.getMiniatureStaticPath(),
+ channel: this.Video?.VideoChannel.toFormattedJSON() || this.deletedVideo?.channel
+ },
+ createdAt: this.createdAt,
+ updatedAt: this.updatedAt,
+ startAt: this.startAt,
+ endAt: this.endAt,
+ count: countReportsForVideo || 0,
+ nth: nthReportForVideo || 0,
+ countReportsForReporter: (countReportsForReporterVideo || 0) + (countReportsForReporterDeletedVideo || 0),
+ countReportsForReportee: (countReportsForReporteeVideo || 0) + (countReportsForReporteeDeletedVideo || 0)
+ }
+ }
+
+ toActivityPubObject (this: MVideoAbuseVideo): VideoAbuseObject {
+ const predefinedReasons = VideoAbuseModel.getPredefinedReasonsStrings(this.predefinedReasons)
+
+ const startAt = this.startAt
+ const endAt = this.endAt
+
+ return {
+ type: 'Flag' as 'Flag',
+ content: this.reason,
+ object: this.Video.url,
+ tag: predefinedReasons.map(r => ({
+ type: 'Hashtag' as 'Hashtag',
+ name: r
+ })),
+ startAt,
+ endAt
+ }
+ }
+
+ private static getStateLabel (id: number) {
+ return VIDEO_ABUSE_STATES[id] || 'Unknown'
+ }
+
+ private static getPredefinedReasonsStrings (predefinedReasons: VideoAbusePredefinedReasons[]): VideoAbusePredefinedReasonsString[] {
+ return (predefinedReasons || [])
+ .filter(r => r in VideoAbusePredefinedReasons)
+ .map(r => invert(videoAbusePredefinedReasonsMap)[r] as VideoAbusePredefinedReasonsString)
+ }