aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-03-11 16:54:52 +0100
committerChocobozzz <me@florianbigard.com>2021-03-24 18:18:41 +0100
commit32a18cbf33a7cdbbe3d4885d32e4b67e19cdc1cf (patch)
tree1db53245688a6b7839cab00f9d65e6c1c1774b00 /server/models/account
parent3fbc6974334ca58c068f0f9def0b0a40db2a6de1 (diff)
downloadPeerTube-32a18cbf33a7cdbbe3d4885d32e4b67e19cdc1cf.tar.gz
PeerTube-32a18cbf33a7cdbbe3d4885d32e4b67e19cdc1cf.tar.zst
PeerTube-32a18cbf33a7cdbbe3d4885d32e4b67e19cdc1cf.zip
Add new plugin/peertube version notifs
Diffstat (limited to 'server/models/account')
-rw-r--r--server/models/account/user-notification-setting.ts22
-rw-r--r--server/models/account/user-notification.ts90
2 files changed, 101 insertions, 11 deletions
diff --git a/server/models/account/user-notification-setting.ts b/server/models/account/user-notification-setting.ts
index ebab8b6d2..de1501299 100644
--- a/server/models/account/user-notification-setting.ts
+++ b/server/models/account/user-notification-setting.ts
@@ -156,6 +156,24 @@ export class UserNotificationSettingModel extends Model {
156 @Column 156 @Column
157 abuseNewMessage: UserNotificationSettingValue 157 abuseNewMessage: UserNotificationSettingValue
158 158
159 @AllowNull(false)
160 @Default(null)
161 @Is(
162 'UserNotificationSettingNewPeerTubeVersion',
163 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPeerTubeVersion')
164 )
165 @Column
166 newPeerTubeVersion: UserNotificationSettingValue
167
168 @AllowNull(false)
169 @Default(null)
170 @Is(
171 'UserNotificationSettingNewPeerPluginVersion',
172 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPluginVersion')
173 )
174 @Column
175 newPluginVersion: UserNotificationSettingValue
176
159 @ForeignKey(() => UserModel) 177 @ForeignKey(() => UserModel)
160 @Column 178 @Column
161 userId: number 179 userId: number
@@ -195,7 +213,9 @@ export class UserNotificationSettingModel extends Model {
195 newInstanceFollower: this.newInstanceFollower, 213 newInstanceFollower: this.newInstanceFollower,
196 autoInstanceFollowing: this.autoInstanceFollowing, 214 autoInstanceFollowing: this.autoInstanceFollowing,
197 abuseNewMessage: this.abuseNewMessage, 215 abuseNewMessage: this.abuseNewMessage,
198 abuseStateChange: this.abuseStateChange 216 abuseStateChange: this.abuseStateChange,
217 newPeerTubeVersion: this.newPeerTubeVersion,
218 newPluginVersion: this.newPluginVersion
199 } 219 }
200 } 220 }
201} 221}
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'
9import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse' 9import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse'
10import { ActorModel } from '../activitypub/actor' 10import { ActorModel } from '../activitypub/actor'
11import { ActorFollowModel } from '../activitypub/actor-follow' 11import { ActorFollowModel } from '../activitypub/actor-follow'
12import { ApplicationModel } from '../application/application'
12import { AvatarModel } from '../avatar/avatar' 13import { AvatarModel } from '../avatar/avatar'
14import { PluginModel } from '../server/plugin'
13import { ServerModel } from '../server/server' 15import { ServerModel } from '../server/server'
14import { getSort, throwIfNotValid } from '../utils' 16import { getSort, throwIfNotValid } from '../utils'
15import { VideoModel } from '../video/video' 17import { 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,