1 import { ActorInfo, FollowState, UserNotification as UserNotificationServer, UserNotificationType, VideoInfo } 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 }
43 follower: ActorInfo & { avatarUrl?: string }
45 type: 'account' | 'channel'
57 videoAbuseUrl?: string
58 videoAutoBlacklistUrl?: string
60 videoImportIdentifier?: string
61 videoImportUrl?: string
63 constructor (hash: UserNotificationServer) {
68 // We assume that some fields exist
69 // To prevent a notification popup crash in case of bug, wrap it inside a try/catch
71 this.video = hash.video
72 if (this.video) this.setAvatarUrl(this.video.channel)
74 this.videoImport = hash.videoImport
76 this.comment = hash.comment
77 if (this.comment) this.setAvatarUrl(this.comment.account)
79 this.videoAbuse = hash.videoAbuse
81 this.videoBlacklist = hash.videoBlacklist
83 this.account = hash.account
84 if (this.account) this.setAvatarUrl(this.account)
86 this.actorFollow = hash.actorFollow
87 if (this.actorFollow) this.setAvatarUrl(this.actorFollow.follower)
89 this.createdAt = hash.createdAt
90 this.updatedAt = hash.updatedAt
93 case UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION:
94 this.videoUrl = this.buildVideoUrl(this.video)
97 case UserNotificationType.UNBLACKLIST_ON_MY_VIDEO:
98 this.videoUrl = this.buildVideoUrl(this.video)
101 case UserNotificationType.NEW_COMMENT_ON_MY_VIDEO:
102 case UserNotificationType.COMMENT_MENTION:
103 this.accountUrl = this.buildAccountUrl(this.comment.account)
104 this.commentUrl = [ this.buildVideoUrl(this.comment.video), { threadId: this.comment.threadId } ]
107 case UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS:
108 this.videoAbuseUrl = '/admin/moderation/video-abuses/list'
109 this.videoUrl = this.buildVideoUrl(this.videoAbuse.video)
112 case UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS:
113 this.videoAutoBlacklistUrl = '/admin/moderation/video-auto-blacklist/list'
114 this.videoUrl = this.buildVideoUrl(this.video)
117 case UserNotificationType.BLACKLIST_ON_MY_VIDEO:
118 this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video)
121 case UserNotificationType.MY_VIDEO_PUBLISHED:
122 this.videoUrl = this.buildVideoUrl(this.video)
125 case UserNotificationType.MY_VIDEO_IMPORT_SUCCESS:
126 this.videoImportUrl = this.buildVideoImportUrl()
127 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
129 if (this.videoImport.video) this.videoUrl = this.buildVideoUrl(this.videoImport.video)
132 case UserNotificationType.MY_VIDEO_IMPORT_ERROR:
133 this.videoImportUrl = this.buildVideoImportUrl()
134 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
137 case UserNotificationType.NEW_USER_REGISTRATION:
138 this.accountUrl = this.buildAccountUrl(this.account)
141 case UserNotificationType.NEW_FOLLOW:
142 this.accountUrl = this.buildAccountUrl(this.actorFollow.follower)
150 private buildVideoUrl (video: { uuid: string }) {
151 return '/videos/watch/' + video.uuid
154 private buildAccountUrl (account: { name: string, host: string }) {
155 return '/accounts/' + Actor.CREATE_BY_STRING(account.name, account.host)
158 private buildVideoImportUrl () {
159 return '/my-account/video-imports'
162 private buildVideoImportIdentifier (videoImport: { targetUrl?: string, magnetUri?: string, torrentName?: string }) {
163 return videoImport.targetUrl || videoImport.magnetUri || videoImport.torrentName
166 private setAvatarUrl (actor: { avatarUrl?: string, avatar?: { path: string } }) {
167 actor.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(actor)