diff options
author | Chocobozzz <me@florianbigard.com> | 2020-07-27 16:26:25 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-07-31 11:35:19 +0200 |
commit | 594d3e48d8a887bbf48ce4cc594c1c36c9640fb1 (patch) | |
tree | bae28fa6215a3a3c6ccd78aea6ea7e75c500a96f /server/models | |
parent | 94148c9028829b5576a5dcbfba2c7fb9cf6443d3 (diff) | |
download | PeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.tar.gz PeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.tar.zst PeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.zip |
Add abuse messages/states notifications
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/abuse/abuse.ts | 54 | ||||
-rw-r--r-- | server/models/account/user-notification-setting.ts | 30 | ||||
-rw-r--r-- | server/models/account/user-notification.ts | 3 | ||||
-rw-r--r-- | server/models/video/video-comment.ts | 2 |
4 files changed, 78 insertions, 11 deletions
diff --git a/server/models/abuse/abuse.ts b/server/models/abuse/abuse.ts index 3353e9e41..1b599db62 100644 --- a/server/models/abuse/abuse.ts +++ b/server/models/abuse/abuse.ts | |||
@@ -32,14 +32,14 @@ import { | |||
32 | UserVideoAbuse | 32 | UserVideoAbuse |
33 | } from '@shared/models' | 33 | } from '@shared/models' |
34 | import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants' | 34 | import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants' |
35 | import { MAbuse, MAbuseAdminFormattable, MAbuseAP, MAbuseReporter, MAbuseUserFormattable, MUserAccountId } from '../../types/models' | 35 | import { MAbuseAdminFormattable, MAbuseAP, MAbuseFull, MAbuseReporter, MAbuseUserFormattable, MUserAccountId } from '../../types/models' |
36 | import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account' | 36 | import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account' |
37 | import { getSort, throwIfNotValid } from '../utils' | 37 | import { getSort, throwIfNotValid } from '../utils' |
38 | import { ThumbnailModel } from '../video/thumbnail' | 38 | import { ThumbnailModel } from '../video/thumbnail' |
39 | import { VideoModel } from '../video/video' | 39 | import { ScopeNames as VideoScopeNames, VideoModel } from '../video/video' |
40 | import { VideoBlacklistModel } from '../video/video-blacklist' | 40 | import { VideoBlacklistModel } from '../video/video-blacklist' |
41 | import { ScopeNames as VideoChannelScopeNames, SummaryOptions as ChannelSummaryOptions, VideoChannelModel } from '../video/video-channel' | 41 | import { ScopeNames as VideoChannelScopeNames, SummaryOptions as ChannelSummaryOptions, VideoChannelModel } from '../video/video-channel' |
42 | import { VideoCommentModel } from '../video/video-comment' | 42 | import { ScopeNames as CommentScopeNames, VideoCommentModel } from '../video/video-comment' |
43 | import { buildAbuseListQuery, BuildAbusesQueryOptions } from './abuse-query-builder' | 43 | import { buildAbuseListQuery, BuildAbusesQueryOptions } from './abuse-query-builder' |
44 | import { VideoAbuseModel } from './video-abuse' | 44 | import { VideoAbuseModel } from './video-abuse' |
45 | import { VideoCommentAbuseModel } from './video-comment-abuse' | 45 | import { VideoCommentAbuseModel } from './video-comment-abuse' |
@@ -307,6 +307,52 @@ export class AbuseModel extends Model<AbuseModel> { | |||
307 | return AbuseModel.findOne(query) | 307 | return AbuseModel.findOne(query) |
308 | } | 308 | } |
309 | 309 | ||
310 | static loadFull (id: number): Bluebird<MAbuseFull> { | ||
311 | const query = { | ||
312 | where: { | ||
313 | id | ||
314 | }, | ||
315 | include: [ | ||
316 | { | ||
317 | model: AccountModel.scope(AccountScopeNames.SUMMARY), | ||
318 | required: false, | ||
319 | as: 'ReporterAccount' | ||
320 | }, | ||
321 | { | ||
322 | model: AccountModel.scope(AccountScopeNames.SUMMARY), | ||
323 | as: 'FlaggedAccount' | ||
324 | }, | ||
325 | { | ||
326 | model: VideoAbuseModel, | ||
327 | required: false, | ||
328 | include: [ | ||
329 | { | ||
330 | model: VideoModel.scope([ VideoScopeNames.WITH_ACCOUNT_DETAILS ]) | ||
331 | } | ||
332 | ] | ||
333 | }, | ||
334 | { | ||
335 | model: VideoCommentAbuseModel, | ||
336 | required: false, | ||
337 | include: [ | ||
338 | { | ||
339 | model: VideoCommentModel.scope([ | ||
340 | CommentScopeNames.WITH_ACCOUNT | ||
341 | ]), | ||
342 | include: [ | ||
343 | { | ||
344 | model: VideoModel | ||
345 | } | ||
346 | ] | ||
347 | } | ||
348 | ] | ||
349 | } | ||
350 | ] | ||
351 | } | ||
352 | |||
353 | return AbuseModel.findOne(query) | ||
354 | } | ||
355 | |||
310 | static async listForAdminApi (parameters: { | 356 | static async listForAdminApi (parameters: { |
311 | start: number | 357 | start: number |
312 | count: number | 358 | count: number |
@@ -455,7 +501,7 @@ export class AbuseModel extends Model<AbuseModel> { | |||
455 | blacklisted: abuseModel.Video?.isBlacklisted() || false, | 501 | blacklisted: abuseModel.Video?.isBlacklisted() || false, |
456 | thumbnailPath: abuseModel.Video?.getMiniatureStaticPath(), | 502 | thumbnailPath: abuseModel.Video?.getMiniatureStaticPath(), |
457 | 503 | ||
458 | channel: abuseModel.Video?.VideoChannel.toFormattedJSON() || abuseModel.deletedVideo?.channel, | 504 | channel: abuseModel.Video?.VideoChannel.toFormattedJSON() || abuseModel.deletedVideo?.channel |
459 | } | 505 | } |
460 | } | 506 | } |
461 | 507 | ||
diff --git a/server/models/account/user-notification-setting.ts b/server/models/account/user-notification-setting.ts index d8f3f13da..acc192d53 100644 --- a/server/models/account/user-notification-setting.ts +++ b/server/models/account/user-notification-setting.ts | |||
@@ -12,12 +12,12 @@ import { | |||
12 | Table, | 12 | Table, |
13 | UpdatedAt | 13 | UpdatedAt |
14 | } from 'sequelize-typescript' | 14 | } from 'sequelize-typescript' |
15 | import { throwIfNotValid } from '../utils' | 15 | import { MNotificationSettingFormattable } from '@server/types/models' |
16 | import { UserModel } from './user' | ||
17 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' | ||
18 | import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model' | 16 | import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model' |
17 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' | ||
19 | import { clearCacheByUserId } from '../../lib/oauth-model' | 18 | import { clearCacheByUserId } from '../../lib/oauth-model' |
20 | import { MNotificationSettingFormattable } from '@server/types/models' | 19 | import { throwIfNotValid } from '../utils' |
20 | import { UserModel } from './user' | ||
21 | 21 | ||
22 | @Table({ | 22 | @Table({ |
23 | tableName: 'userNotificationSetting', | 23 | tableName: 'userNotificationSetting', |
@@ -138,6 +138,24 @@ export class UserNotificationSettingModel extends Model<UserNotificationSettingM | |||
138 | @Column | 138 | @Column |
139 | commentMention: UserNotificationSettingValue | 139 | commentMention: UserNotificationSettingValue |
140 | 140 | ||
141 | @AllowNull(false) | ||
142 | @Default(null) | ||
143 | @Is( | ||
144 | 'UserNotificationSettingAbuseStateChange', | ||
145 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseStateChange') | ||
146 | ) | ||
147 | @Column | ||
148 | abuseStateChange: UserNotificationSettingValue | ||
149 | |||
150 | @AllowNull(false) | ||
151 | @Default(null) | ||
152 | @Is( | ||
153 | 'UserNotificationSettingAbuseNewMessage', | ||
154 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseNewMessage') | ||
155 | ) | ||
156 | @Column | ||
157 | abuseNewMessage: UserNotificationSettingValue | ||
158 | |||
141 | @ForeignKey(() => UserModel) | 159 | @ForeignKey(() => UserModel) |
142 | @Column | 160 | @Column |
143 | userId: number | 161 | userId: number |
@@ -175,7 +193,9 @@ export class UserNotificationSettingModel extends Model<UserNotificationSettingM | |||
175 | commentMention: this.commentMention, | 193 | commentMention: this.commentMention, |
176 | newFollow: this.newFollow, | 194 | newFollow: this.newFollow, |
177 | newInstanceFollower: this.newInstanceFollower, | 195 | newInstanceFollower: this.newInstanceFollower, |
178 | autoInstanceFollowing: this.autoInstanceFollowing | 196 | autoInstanceFollowing: this.autoInstanceFollowing, |
197 | abuseNewMessage: this.abuseNewMessage, | ||
198 | abuseStateChange: this.abuseStateChange | ||
179 | } | 199 | } |
180 | } | 200 | } |
181 | } | 201 | } |
diff --git a/server/models/account/user-notification.ts b/server/models/account/user-notification.ts index 2945bf709..bd89b8973 100644 --- a/server/models/account/user-notification.ts +++ b/server/models/account/user-notification.ts | |||
@@ -88,7 +88,7 @@ function buildAccountInclude (required: boolean, withActor = false) { | |||
88 | }, | 88 | }, |
89 | 89 | ||
90 | { | 90 | { |
91 | attributes: [ 'id' ], | 91 | attributes: [ 'id', 'state' ], |
92 | model: AbuseModel.unscoped(), | 92 | model: AbuseModel.unscoped(), |
93 | required: false, | 93 | required: false, |
94 | include: [ | 94 | include: [ |
@@ -504,6 +504,7 @@ export class UserNotificationModel extends Model<UserNotificationModel> { | |||
504 | 504 | ||
505 | return { | 505 | return { |
506 | id: abuse.id, | 506 | id: abuse.id, |
507 | state: abuse.state, | ||
507 | video: videoAbuse, | 508 | video: videoAbuse, |
508 | comment: commentAbuse, | 509 | comment: commentAbuse, |
509 | account: accountAbuse | 510 | account: accountAbuse |
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 75b914b8c..1d5c7280d 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -44,7 +44,7 @@ import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIf | |||
44 | import { VideoModel } from './video' | 44 | import { VideoModel } from './video' |
45 | import { VideoChannelModel } from './video-channel' | 45 | import { VideoChannelModel } from './video-channel' |
46 | 46 | ||
47 | enum ScopeNames { | 47 | export enum ScopeNames { |
48 | WITH_ACCOUNT = 'WITH_ACCOUNT', | 48 | WITH_ACCOUNT = 'WITH_ACCOUNT', |
49 | WITH_ACCOUNT_FOR_API = 'WITH_ACCOUNT_FOR_API', | 49 | WITH_ACCOUNT_FOR_API = 'WITH_ACCOUNT_FOR_API', |
50 | WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO', | 50 | WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO', |