aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/user-notification.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/account/user-notification.ts')
-rw-r--r--server/models/account/user-notification.ts29
1 files changed, 22 insertions, 7 deletions
diff --git a/server/models/account/user-notification.ts b/server/models/account/user-notification.ts
index f38cd7e78..ccb81b891 100644
--- a/server/models/account/user-notification.ts
+++ b/server/models/account/user-notification.ts
@@ -16,6 +16,7 @@ import { ActorModel } from '../activitypub/actor'
16import { ActorFollowModel } from '../activitypub/actor-follow' 16import { ActorFollowModel } from '../activitypub/actor-follow'
17import { AvatarModel } from '../avatar/avatar' 17import { AvatarModel } from '../avatar/avatar'
18import { ServerModel } from '../server/server' 18import { ServerModel } from '../server/server'
19import { UserNotificationIncludes, UserNotificationModelForApi } from '@server/typings/models/user'
19 20
20enum ScopeNames { 21enum ScopeNames {
21 WITH_ALL = 'WITH_ALL' 22 WITH_ALL = 'WITH_ALL'
@@ -134,13 +135,18 @@ function buildAccountInclude (required: boolean, withActor = false) {
134 ] 135 ]
135 }, 136 },
136 { 137 {
137 attributes: [ 'preferredUsername' ], 138 attributes: [ 'preferredUsername', 'type' ],
138 model: ActorModel.unscoped(), 139 model: ActorModel.unscoped(),
139 required: true, 140 required: true,
140 as: 'ActorFollowing', 141 as: 'ActorFollowing',
141 include: [ 142 include: [
142 buildChannelInclude(false), 143 buildChannelInclude(false),
143 buildAccountInclude(false) 144 buildAccountInclude(false),
145 {
146 attributes: [ 'host' ],
147 model: ServerModel.unscoped(),
148 required: false
149 }
144 ] 150 ]
145 } 151 }
146 ] 152 ]
@@ -371,7 +377,7 @@ export class UserNotificationModel extends Model<UserNotificationModel> {
371 return UserNotificationModel.update({ read: true }, query) 377 return UserNotificationModel.update({ read: true }, query)
372 } 378 }
373 379
374 toFormattedJSON (): UserNotification { 380 toFormattedJSON (this: UserNotificationModelForApi): UserNotification {
375 const video = this.Video 381 const video = this.Video
376 ? Object.assign(this.formatVideo(this.Video),{ channel: this.formatActor(this.Video.VideoChannel) }) 382 ? Object.assign(this.formatVideo(this.Video),{ channel: this.formatActor(this.Video.VideoChannel) })
377 : undefined 383 : undefined
@@ -403,6 +409,11 @@ export class UserNotificationModel extends Model<UserNotificationModel> {
403 409
404 const account = this.Account ? this.formatActor(this.Account) : undefined 410 const account = this.Account ? this.formatActor(this.Account) : undefined
405 411
412 const actorFollowingType = {
413 Application: 'instance' as 'instance',
414 Group: 'channel' as 'channel',
415 Person: 'account' as 'account'
416 }
406 const actorFollow = this.ActorFollow ? { 417 const actorFollow = this.ActorFollow ? {
407 id: this.ActorFollow.id, 418 id: this.ActorFollow.id,
408 state: this.ActorFollow.state, 419 state: this.ActorFollow.state,
@@ -414,9 +425,10 @@ export class UserNotificationModel extends Model<UserNotificationModel> {
414 host: this.ActorFollow.ActorFollower.getHost() 425 host: this.ActorFollow.ActorFollower.getHost()
415 }, 426 },
416 following: { 427 following: {
417 type: this.ActorFollow.ActorFollowing.VideoChannel ? 'channel' as 'channel' : 'account' as 'account', 428 type: actorFollowingType[this.ActorFollow.ActorFollowing.type],
418 displayName: (this.ActorFollow.ActorFollowing.VideoChannel || this.ActorFollow.ActorFollowing.Account).getDisplayName(), 429 displayName: (this.ActorFollow.ActorFollowing.VideoChannel || this.ActorFollow.ActorFollowing.Account).getDisplayName(),
419 name: this.ActorFollow.ActorFollowing.preferredUsername 430 name: this.ActorFollow.ActorFollowing.preferredUsername,
431 host: this.ActorFollow.ActorFollowing.getHost()
420 } 432 }
421 } : undefined 433 } : undefined
422 434
@@ -436,7 +448,7 @@ export class UserNotificationModel extends Model<UserNotificationModel> {
436 } 448 }
437 } 449 }
438 450
439 private formatVideo (video: VideoModel) { 451 formatVideo (this: UserNotificationModelForApi, video: UserNotificationIncludes.VideoInclude) {
440 return { 452 return {
441 id: video.id, 453 id: video.id,
442 uuid: video.uuid, 454 uuid: video.uuid,
@@ -444,7 +456,10 @@ export class UserNotificationModel extends Model<UserNotificationModel> {
444 } 456 }
445 } 457 }
446 458
447 private formatActor (accountOrChannel: AccountModel | VideoChannelModel) { 459 formatActor (
460 this: UserNotificationModelForApi,
461 accountOrChannel: UserNotificationIncludes.AccountIncludeActor | UserNotificationIncludes.VideoChannelIncludeActor
462 ) {
448 const avatar = accountOrChannel.Actor.Avatar 463 const avatar = accountOrChannel.Actor.Avatar
449 ? { path: accountOrChannel.Actor.Avatar.getStaticPath() } 464 ? { path: accountOrChannel.Actor.Avatar.getStaticPath() }
450 : undefined 465 : undefined