aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/user-notification.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-01-04 08:56:20 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-01-09 11:15:15 +0100
commitf7cc67b455a12ccae9b0ea16876d166720364357 (patch)
treeeac2cdbf2e92a16b3eda5d74371c82bd79ae22cb /server/models/account/user-notification.ts
parentdc13348070d808d0ba3feb56a435b835c2e7e791 (diff)
downloadPeerTube-f7cc67b455a12ccae9b0ea16876d166720364357.tar.gz
PeerTube-f7cc67b455a12ccae9b0ea16876d166720364357.tar.zst
PeerTube-f7cc67b455a12ccae9b0ea16876d166720364357.zip
Add new follow, mention and user registered notifs
Diffstat (limited to 'server/models/account/user-notification.ts')
-rw-r--r--server/models/account/user-notification.ts95
1 files changed, 89 insertions, 6 deletions
diff --git a/server/models/account/user-notification.ts b/server/models/account/user-notification.ts
index 251244374..79afce600 100644
--- a/server/models/account/user-notification.ts
+++ b/server/models/account/user-notification.ts
@@ -25,6 +25,8 @@ import { AccountModel } from './account'
25import { VideoAbuseModel } from '../video/video-abuse' 25import { VideoAbuseModel } from '../video/video-abuse'
26import { VideoBlacklistModel } from '../video/video-blacklist' 26import { VideoBlacklistModel } from '../video/video-blacklist'
27import { VideoImportModel } from '../video/video-import' 27import { VideoImportModel } from '../video/video-import'
28import { ActorModel } from '../activitypub/actor'
29import { ActorFollowModel } from '../activitypub/actor-follow'
28 30
29enum ScopeNames { 31enum ScopeNames {
30 WITH_ALL = 'WITH_ALL' 32 WITH_ALL = 'WITH_ALL'
@@ -38,17 +40,17 @@ function buildVideoInclude (required: boolean) {
38 } 40 }
39} 41}
40 42
41function buildChannelInclude () { 43function buildChannelInclude (required: boolean) {
42 return { 44 return {
43 required: true, 45 required,
44 attributes: [ 'id', 'name' ], 46 attributes: [ 'id', 'name' ],
45 model: () => VideoChannelModel.unscoped() 47 model: () => VideoChannelModel.unscoped()
46 } 48 }
47} 49}
48 50
49function buildAccountInclude () { 51function buildAccountInclude (required: boolean) {
50 return { 52 return {
51 required: true, 53 required,
52 attributes: [ 'id', 'name' ], 54 attributes: [ 'id', 'name' ],
53 model: () => AccountModel.unscoped() 55 model: () => AccountModel.unscoped()
54 } 56 }
@@ -58,14 +60,14 @@ function buildAccountInclude () {
58 [ScopeNames.WITH_ALL]: { 60 [ScopeNames.WITH_ALL]: {
59 include: [ 61 include: [
60 Object.assign(buildVideoInclude(false), { 62 Object.assign(buildVideoInclude(false), {
61 include: [ buildChannelInclude() ] 63 include: [ buildChannelInclude(true) ]
62 }), 64 }),
63 { 65 {
64 attributes: [ 'id', 'originCommentId' ], 66 attributes: [ 'id', 'originCommentId' ],
65 model: () => VideoCommentModel.unscoped(), 67 model: () => VideoCommentModel.unscoped(),
66 required: false, 68 required: false,
67 include: [ 69 include: [
68 buildAccountInclude(), 70 buildAccountInclude(true),
69 buildVideoInclude(true) 71 buildVideoInclude(true)
70 ] 72 ]
71 }, 73 },
@@ -86,6 +88,42 @@ function buildAccountInclude () {
86 model: () => VideoImportModel.unscoped(), 88 model: () => VideoImportModel.unscoped(),
87 required: false, 89 required: false,
88 include: [ buildVideoInclude(false) ] 90 include: [ buildVideoInclude(false) ]
91 },
92 {
93 attributes: [ 'id', 'name' ],
94 model: () => AccountModel.unscoped(),
95 required: false,
96 include: [
97 {
98 attributes: [ 'id', 'preferredUsername' ],
99 model: () => ActorModel.unscoped(),
100 required: true
101 }
102 ]
103 },
104 {
105 attributes: [ 'id' ],
106 model: () => ActorFollowModel.unscoped(),
107 required: false,
108 include: [
109 {
110 attributes: [ 'preferredUsername' ],
111 model: () => ActorModel.unscoped(),
112 required: true,
113 as: 'ActorFollower',
114 include: [ buildAccountInclude(true) ]
115 },
116 {
117 attributes: [ 'preferredUsername' ],
118 model: () => ActorModel.unscoped(),
119 required: true,
120 as: 'ActorFollowing',
121 include: [
122 buildChannelInclude(false),
123 buildAccountInclude(false)
124 ]
125 }
126 ]
89 } 127 }
90 ] 128 ]
91 } 129 }
@@ -193,6 +231,30 @@ export class UserNotificationModel extends Model<UserNotificationModel> {
193 }) 231 })
194 VideoImport: VideoImportModel 232 VideoImport: VideoImportModel
195 233
234 @ForeignKey(() => AccountModel)
235 @Column
236 accountId: number
237
238 @BelongsTo(() => AccountModel, {
239 foreignKey: {
240 allowNull: true
241 },
242 onDelete: 'cascade'
243 })
244 Account: AccountModel
245
246 @ForeignKey(() => ActorFollowModel)
247 @Column
248 actorFollowId: number
249
250 @BelongsTo(() => ActorFollowModel, {
251 foreignKey: {
252 allowNull: true
253 },
254 onDelete: 'cascade'
255 })
256 ActorFollow: ActorFollowModel
257
196 static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) { 258 static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) {
197 const query: IFindOptions<UserNotificationModel> = { 259 const query: IFindOptions<UserNotificationModel> = {
198 offset: start, 260 offset: start,
@@ -264,6 +326,25 @@ export class UserNotificationModel extends Model<UserNotificationModel> {
264 video: this.formatVideo(this.VideoBlacklist.Video) 326 video: this.formatVideo(this.VideoBlacklist.Video)
265 } : undefined 327 } : undefined
266 328
329 const account = this.Account ? {
330 id: this.Account.id,
331 displayName: this.Account.getDisplayName(),
332 name: this.Account.Actor.preferredUsername
333 } : undefined
334
335 const actorFollow = this.ActorFollow ? {
336 id: this.ActorFollow.id,
337 follower: {
338 displayName: this.ActorFollow.ActorFollower.Account.getDisplayName(),
339 name: this.ActorFollow.ActorFollower.preferredUsername
340 },
341 following: {
342 type: this.ActorFollow.ActorFollowing.VideoChannel ? 'channel' as 'channel' : 'account' as 'account',
343 displayName: (this.ActorFollow.ActorFollowing.VideoChannel || this.ActorFollow.ActorFollowing.Account).getDisplayName(),
344 name: this.ActorFollow.ActorFollowing.preferredUsername
345 }
346 } : undefined
347
267 return { 348 return {
268 id: this.id, 349 id: this.id,
269 type: this.type, 350 type: this.type,
@@ -273,6 +354,8 @@ export class UserNotificationModel extends Model<UserNotificationModel> {
273 comment, 354 comment,
274 videoAbuse, 355 videoAbuse,
275 videoBlacklist, 356 videoBlacklist,
357 account,
358 actorFollow,
276 createdAt: this.createdAt.toISOString(), 359 createdAt: this.createdAt.toISOString(),
277 updatedAt: this.updatedAt.toISOString() 360 updatedAt: this.updatedAt.toISOString()
278 } 361 }