diff options
Diffstat (limited to 'server/models/account/user-notification.ts')
-rw-r--r-- | server/models/account/user-notification.ts | 90 |
1 files changed, 80 insertions, 10 deletions
diff --git a/server/models/account/user-notification.ts b/server/models/account/user-notification.ts index add129644..25c523203 100644 --- a/server/models/account/user-notification.ts +++ b/server/models/account/user-notification.ts | |||
@@ -9,7 +9,9 @@ import { VideoAbuseModel } from '../abuse/video-abuse' | |||
9 | import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse' | 9 | import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse' |
10 | import { ActorModel } from '../activitypub/actor' | 10 | import { ActorModel } from '../activitypub/actor' |
11 | import { ActorFollowModel } from '../activitypub/actor-follow' | 11 | import { ActorFollowModel } from '../activitypub/actor-follow' |
12 | import { ApplicationModel } from '../application/application' | ||
12 | import { AvatarModel } from '../avatar/avatar' | 13 | import { AvatarModel } from '../avatar/avatar' |
14 | import { PluginModel } from '../server/plugin' | ||
13 | import { ServerModel } from '../server/server' | 15 | import { ServerModel } from '../server/server' |
14 | import { getSort, throwIfNotValid } from '../utils' | 16 | import { getSort, throwIfNotValid } from '../utils' |
15 | import { VideoModel } from '../video/video' | 17 | import { VideoModel } from '../video/video' |
@@ -96,7 +98,7 @@ function buildAccountInclude (required: boolean, withActor = false) { | |||
96 | attributes: [ 'id' ], | 98 | attributes: [ 'id' ], |
97 | model: VideoAbuseModel.unscoped(), | 99 | model: VideoAbuseModel.unscoped(), |
98 | required: false, | 100 | required: false, |
99 | include: [ buildVideoInclude(true) ] | 101 | include: [ buildVideoInclude(false) ] |
100 | }, | 102 | }, |
101 | { | 103 | { |
102 | attributes: [ 'id' ], | 104 | attributes: [ 'id' ], |
@@ -106,12 +108,12 @@ function buildAccountInclude (required: boolean, withActor = false) { | |||
106 | { | 108 | { |
107 | attributes: [ 'id', 'originCommentId' ], | 109 | attributes: [ 'id', 'originCommentId' ], |
108 | model: VideoCommentModel.unscoped(), | 110 | model: VideoCommentModel.unscoped(), |
109 | required: true, | 111 | required: false, |
110 | include: [ | 112 | include: [ |
111 | { | 113 | { |
112 | attributes: [ 'id', 'name', 'uuid' ], | 114 | attributes: [ 'id', 'name', 'uuid' ], |
113 | model: VideoModel.unscoped(), | 115 | model: VideoModel.unscoped(), |
114 | required: true | 116 | required: false |
115 | } | 117 | } |
116 | ] | 118 | ] |
117 | } | 119 | } |
@@ -120,7 +122,7 @@ function buildAccountInclude (required: boolean, withActor = false) { | |||
120 | { | 122 | { |
121 | model: AccountModel, | 123 | model: AccountModel, |
122 | as: 'FlaggedAccount', | 124 | as: 'FlaggedAccount', |
123 | required: true, | 125 | required: false, |
124 | include: [ buildActorWithAvatarInclude() ] | 126 | include: [ buildActorWithAvatarInclude() ] |
125 | } | 127 | } |
126 | ] | 128 | ] |
@@ -141,6 +143,18 @@ function buildAccountInclude (required: boolean, withActor = false) { | |||
141 | }, | 143 | }, |
142 | 144 | ||
143 | { | 145 | { |
146 | attributes: [ 'id', 'name', 'type', 'latestVersion' ], | ||
147 | model: PluginModel.unscoped(), | ||
148 | required: false | ||
149 | }, | ||
150 | |||
151 | { | ||
152 | attributes: [ 'id', 'latestPeerTubeVersion' ], | ||
153 | model: ApplicationModel.unscoped(), | ||
154 | required: false | ||
155 | }, | ||
156 | |||
157 | { | ||
144 | attributes: [ 'id', 'state' ], | 158 | attributes: [ 'id', 'state' ], |
145 | model: ActorFollowModel.unscoped(), | 159 | model: ActorFollowModel.unscoped(), |
146 | required: false, | 160 | required: false, |
@@ -251,6 +265,22 @@ function buildAccountInclude (required: boolean, withActor = false) { | |||
251 | [Op.ne]: null | 265 | [Op.ne]: null |
252 | } | 266 | } |
253 | } | 267 | } |
268 | }, | ||
269 | { | ||
270 | fields: [ 'pluginId' ], | ||
271 | where: { | ||
272 | pluginId: { | ||
273 | [Op.ne]: null | ||
274 | } | ||
275 | } | ||
276 | }, | ||
277 | { | ||
278 | fields: [ 'applicationId' ], | ||
279 | where: { | ||
280 | applicationId: { | ||
281 | [Op.ne]: null | ||
282 | } | ||
283 | } | ||
254 | } | 284 | } |
255 | ] as (ModelIndexesOptions & { where?: WhereOptions })[] | 285 | ] as (ModelIndexesOptions & { where?: WhereOptions })[] |
256 | }) | 286 | }) |
@@ -370,6 +400,30 @@ export class UserNotificationModel extends Model { | |||
370 | }) | 400 | }) |
371 | ActorFollow: ActorFollowModel | 401 | ActorFollow: ActorFollowModel |
372 | 402 | ||
403 | @ForeignKey(() => PluginModel) | ||
404 | @Column | ||
405 | pluginId: number | ||
406 | |||
407 | @BelongsTo(() => PluginModel, { | ||
408 | foreignKey: { | ||
409 | allowNull: true | ||
410 | }, | ||
411 | onDelete: 'cascade' | ||
412 | }) | ||
413 | Plugin: PluginModel | ||
414 | |||
415 | @ForeignKey(() => ApplicationModel) | ||
416 | @Column | ||
417 | applicationId: number | ||
418 | |||
419 | @BelongsTo(() => ApplicationModel, { | ||
420 | foreignKey: { | ||
421 | allowNull: true | ||
422 | }, | ||
423 | onDelete: 'cascade' | ||
424 | }) | ||
425 | Application: ApplicationModel | ||
426 | |||
373 | static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) { | 427 | static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) { |
374 | const where = { userId } | 428 | const where = { userId } |
375 | 429 | ||
@@ -524,6 +578,18 @@ export class UserNotificationModel extends Model { | |||
524 | } | 578 | } |
525 | : undefined | 579 | : undefined |
526 | 580 | ||
581 | const plugin = this.Plugin | ||
582 | ? { | ||
583 | name: this.Plugin.name, | ||
584 | type: this.Plugin.type, | ||
585 | latestVersion: this.Plugin.latestVersion | ||
586 | } | ||
587 | : undefined | ||
588 | |||
589 | const peertube = this.Application | ||
590 | ? { latestVersion: this.Application.latestPeerTubeVersion } | ||
591 | : undefined | ||
592 | |||
527 | return { | 593 | return { |
528 | id: this.id, | 594 | id: this.id, |
529 | type: this.type, | 595 | type: this.type, |
@@ -535,6 +601,8 @@ export class UserNotificationModel extends Model { | |||
535 | videoBlacklist, | 601 | videoBlacklist, |
536 | account, | 602 | account, |
537 | actorFollow, | 603 | actorFollow, |
604 | plugin, | ||
605 | peertube, | ||
538 | createdAt: this.createdAt.toISOString(), | 606 | createdAt: this.createdAt.toISOString(), |
539 | updatedAt: this.updatedAt.toISOString() | 607 | updatedAt: this.updatedAt.toISOString() |
540 | } | 608 | } |
@@ -553,17 +621,19 @@ export class UserNotificationModel extends Model { | |||
553 | ? { | 621 | ? { |
554 | threadId: abuse.VideoCommentAbuse.VideoComment.getThreadId(), | 622 | threadId: abuse.VideoCommentAbuse.VideoComment.getThreadId(), |
555 | 623 | ||
556 | video: { | 624 | video: abuse.VideoCommentAbuse.VideoComment.Video |
557 | id: abuse.VideoCommentAbuse.VideoComment.Video.id, | 625 | ? { |
558 | name: abuse.VideoCommentAbuse.VideoComment.Video.name, | 626 | id: abuse.VideoCommentAbuse.VideoComment.Video.id, |
559 | uuid: abuse.VideoCommentAbuse.VideoComment.Video.uuid | 627 | name: abuse.VideoCommentAbuse.VideoComment.Video.name, |
560 | } | 628 | uuid: abuse.VideoCommentAbuse.VideoComment.Video.uuid |
629 | } | ||
630 | : undefined | ||
561 | } | 631 | } |
562 | : undefined | 632 | : undefined |
563 | 633 | ||
564 | const videoAbuse = abuse.VideoAbuse?.Video ? this.formatVideo(abuse.VideoAbuse.Video) : undefined | 634 | const videoAbuse = abuse.VideoAbuse?.Video ? this.formatVideo(abuse.VideoAbuse.Video) : undefined |
565 | 635 | ||
566 | const accountAbuse = (!commentAbuse && !videoAbuse) ? this.formatActor(abuse.FlaggedAccount) : undefined | 636 | const accountAbuse = (!commentAbuse && !videoAbuse && abuse.FlaggedAccount) ? this.formatActor(abuse.FlaggedAccount) : undefined |
567 | 637 | ||
568 | return { | 638 | return { |
569 | id: abuse.id, | 639 | id: abuse.id, |