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 // We assume that some fields exist
67 // To prevent a notification popup crash in case of bug, wrap it inside a try/catch
69 this.video = hash.video
70 if (this.video) this.setAvatarUrl(this.video.channel)
72 this.videoImport = hash.videoImport
74 this.comment = hash.comment
75 if (this.comment) this.setAvatarUrl(this.comment.account)
77 this.videoAbuse = hash.videoAbuse
79 this.videoBlacklist = hash.videoBlacklist
81 this.account = hash.account
82 if (this.account) this.setAvatarUrl(this.account)
84 this.actorFollow = hash.actorFollow
85 if (this.actorFollow) this.setAvatarUrl(this.actorFollow.follower)
87 this.createdAt = hash.createdAt
88 this.updatedAt = hash.updatedAt
91 case UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION:
92 this.videoUrl = this.buildVideoUrl(this.video)
95 case UserNotificationType.UNBLACKLIST_ON_MY_VIDEO:
96 this.videoUrl = this.buildVideoUrl(this.video)
99 case UserNotificationType.NEW_COMMENT_ON_MY_VIDEO:
100 case UserNotificationType.COMMENT_MENTION:
101 this.accountUrl = this.buildAccountUrl(this.comment.account)
102 this.commentUrl = [ this.buildVideoUrl(this.comment.video), { threadId: this.comment.threadId } ]
105 case UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS:
106 this.videoAbuseUrl = '/admin/moderation/video-abuses/list'
107 this.videoUrl = this.buildVideoUrl(this.videoAbuse.video)
110 case UserNotificationType.BLACKLIST_ON_MY_VIDEO:
111 this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video)
114 case UserNotificationType.MY_VIDEO_PUBLISHED:
115 this.videoUrl = this.buildVideoUrl(this.video)
118 case UserNotificationType.MY_VIDEO_IMPORT_SUCCESS:
119 this.videoImportUrl = this.buildVideoImportUrl()
120 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
121 this.videoUrl = this.buildVideoUrl(this.videoImport.video)
124 case UserNotificationType.MY_VIDEO_IMPORT_ERROR:
125 this.videoImportUrl = this.buildVideoImportUrl()
126 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
129 case UserNotificationType.NEW_USER_REGISTRATION:
130 this.accountUrl = this.buildAccountUrl(this.account)
133 case UserNotificationType.NEW_FOLLOW:
134 this.accountUrl = this.buildAccountUrl(this.actorFollow.follower)
142 private buildVideoUrl (video: { uuid: string }) {
143 return '/videos/watch/' + video.uuid
146 private buildAccountUrl (account: { name: string, host: string }) {
147 return '/accounts/' + Actor.CREATE_BY_STRING(account.name, account.host)
150 private buildVideoImportUrl () {
151 return '/my-account/video-imports'
154 private buildVideoImportIdentifier (videoImport: { targetUrl?: string, magnetUri?: string, torrentName?: string }) {
155 return videoImport.targetUrl || videoImport.magnetUri || videoImport.torrentName
158 private setAvatarUrl (actor: { avatarUrl?: string, avatar?: { path: string } }) {
159 actor.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(actor)