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
57 videoAutoBlacklistUrl?: string
59 videoImportIdentifier?: string
60 videoImportUrl?: string
62 constructor (hash: UserNotificationServer) {
67 // We assume that some fields exist
68 // To prevent a notification popup crash in case of bug, wrap it inside a try/catch
70 this.video = hash.video
71 if (this.video) this.setAvatarUrl(this.video.channel)
73 this.videoImport = hash.videoImport
75 this.comment = hash.comment
76 if (this.comment) this.setAvatarUrl(this.comment.account)
78 this.videoAbuse = hash.videoAbuse
80 this.videoBlacklist = hash.videoBlacklist
82 this.account = hash.account
83 if (this.account) this.setAvatarUrl(this.account)
85 this.actorFollow = hash.actorFollow
86 if (this.actorFollow) this.setAvatarUrl(this.actorFollow.follower)
88 this.createdAt = hash.createdAt
89 this.updatedAt = hash.updatedAt
92 case UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION:
93 this.videoUrl = this.buildVideoUrl(this.video)
96 case UserNotificationType.UNBLACKLIST_ON_MY_VIDEO:
97 this.videoUrl = this.buildVideoUrl(this.video)
100 case UserNotificationType.NEW_COMMENT_ON_MY_VIDEO:
101 case UserNotificationType.COMMENT_MENTION:
102 this.accountUrl = this.buildAccountUrl(this.comment.account)
103 this.commentUrl = [ this.buildVideoUrl(this.comment.video), { threadId: this.comment.threadId } ]
106 case UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS:
107 this.videoAbuseUrl = '/admin/moderation/video-abuses/list'
108 this.videoUrl = this.buildVideoUrl(this.videoAbuse.video)
111 case UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS:
112 this.videoAutoBlacklistUrl = '/admin/moderation/video-auto-blacklist/list'
113 this.videoUrl = this.buildVideoUrl(this.video)
116 case UserNotificationType.BLACKLIST_ON_MY_VIDEO:
117 this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video)
120 case UserNotificationType.MY_VIDEO_PUBLISHED:
121 this.videoUrl = this.buildVideoUrl(this.video)
124 case UserNotificationType.MY_VIDEO_IMPORT_SUCCESS:
125 this.videoImportUrl = this.buildVideoImportUrl()
126 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
128 if (this.videoImport.video) this.videoUrl = this.buildVideoUrl(this.videoImport.video)
131 case UserNotificationType.MY_VIDEO_IMPORT_ERROR:
132 this.videoImportUrl = this.buildVideoImportUrl()
133 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
136 case UserNotificationType.NEW_USER_REGISTRATION:
137 this.accountUrl = this.buildAccountUrl(this.account)
140 case UserNotificationType.NEW_FOLLOW:
141 this.accountUrl = this.buildAccountUrl(this.actorFollow.follower)
149 private buildVideoUrl (video: { uuid: string }) {
150 return '/videos/watch/' + video.uuid
153 private buildAccountUrl (account: { name: string, host: string }) {
154 return '/accounts/' + Actor.CREATE_BY_STRING(account.name, account.host)
157 private buildVideoImportUrl () {
158 return '/my-account/video-imports'
161 private buildVideoImportIdentifier (videoImport: { targetUrl?: string, magnetUri?: string, torrentName?: string }) {
162 return videoImport.targetUrl || videoImport.magnetUri || videoImport.torrentName
165 private setAvatarUrl (actor: { avatarUrl?: string, avatar?: { path: string } }) {
166 actor.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(actor)