1 import { UserNotification as UserNotificationServer, UserNotificationType, VideoInfo, ActorInfo } from '../../../../../shared'
2 import { Actor } from '@app/shared/actor/actor.model'
4 export class UserNotification implements UserNotificationServer {
6 type: UserNotificationType
10 channel: ActorInfo & { avatarUrl?: string }
24 account: ActorInfo & { avatarUrl?: string }
38 account?: ActorInfo & { avatarUrl?: string }
42 follower: ActorInfo & { avatarUrl?: string }
44 type: 'account' | 'channel'
56 videoAbuseUrl?: string
58 videoImportIdentifier?: string
59 videoImportUrl?: string
61 constructor (hash: UserNotificationServer) {
66 this.video = hash.video
67 if (this.video) this.setAvatarUrl(this.video.channel)
69 this.videoImport = hash.videoImport
71 this.comment = hash.comment
72 if (this.comment) this.setAvatarUrl(this.comment.account)
74 this.videoAbuse = hash.videoAbuse
76 this.videoBlacklist = hash.videoBlacklist
78 this.account = hash.account
79 if (this.account) this.setAvatarUrl(this.account)
81 this.actorFollow = hash.actorFollow
82 if (this.actorFollow) this.setAvatarUrl(this.actorFollow.follower)
84 this.createdAt = hash.createdAt
85 this.updatedAt = hash.updatedAt
88 case UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION:
89 this.videoUrl = this.buildVideoUrl(this.video)
92 case UserNotificationType.UNBLACKLIST_ON_MY_VIDEO:
93 this.videoUrl = this.buildVideoUrl(this.video)
96 case UserNotificationType.NEW_COMMENT_ON_MY_VIDEO:
97 case UserNotificationType.COMMENT_MENTION:
98 this.commentUrl = [ this.buildVideoUrl(this.comment.video), { threadId: this.comment.threadId } ]
101 case UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS:
102 this.videoAbuseUrl = '/admin/moderation/video-abuses/list'
103 this.videoUrl = this.buildVideoUrl(this.videoAbuse.video)
106 case UserNotificationType.BLACKLIST_ON_MY_VIDEO:
107 this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video)
110 case UserNotificationType.MY_VIDEO_PUBLISHED:
111 this.videoUrl = this.buildVideoUrl(this.video)
114 case UserNotificationType.MY_VIDEO_IMPORT_SUCCESS:
115 this.videoImportUrl = this.buildVideoImportUrl()
116 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
117 this.videoUrl = this.buildVideoUrl(this.videoImport.video)
120 case UserNotificationType.MY_VIDEO_IMPORT_ERROR:
121 this.videoImportUrl = this.buildVideoImportUrl()
122 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
125 case UserNotificationType.NEW_USER_REGISTRATION:
126 this.accountUrl = this.buildAccountUrl(this.account)
129 case UserNotificationType.NEW_FOLLOW:
130 this.accountUrl = this.buildAccountUrl(this.actorFollow.follower)
135 private buildVideoUrl (video: { uuid: string }) {
136 return '/videos/watch/' + video.uuid
139 private buildAccountUrl (account: { name: string, host: string }) {
140 return '/accounts/' + Actor.CREATE_BY_STRING(account.name, account.host)
143 private buildVideoImportUrl () {
144 return '/my-account/video-imports'
147 private buildVideoImportIdentifier (videoImport: { targetUrl?: string, magnetUri?: string, torrentName?: string }) {
148 return videoImport.targetUrl || videoImport.magnetUri || videoImport.torrentName
151 private setAvatarUrl (actor: { avatarUrl?: string, avatar?: { path: string } }) {
152 actor.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(actor)