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
62 instanceFollowUrl?: string
64 constructor (hash: UserNotificationServer) {
69 // We assume that some fields exist
70 // To prevent a notification popup crash in case of bug, wrap it inside a try/catch
72 this.video = hash.video
73 if (this.video) this.setAvatarUrl(this.video.channel)
75 this.videoImport = hash.videoImport
77 this.comment = hash.comment
78 if (this.comment) this.setAvatarUrl(this.comment.account)
80 this.videoAbuse = hash.videoAbuse
82 this.videoBlacklist = hash.videoBlacklist
84 this.account = hash.account
85 if (this.account) this.setAvatarUrl(this.account)
87 this.actorFollow = hash.actorFollow
88 if (this.actorFollow) this.setAvatarUrl(this.actorFollow.follower)
90 this.createdAt = hash.createdAt
91 this.updatedAt = hash.updatedAt
94 case UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION:
95 this.videoUrl = this.buildVideoUrl(this.video)
98 case UserNotificationType.UNBLACKLIST_ON_MY_VIDEO:
99 this.videoUrl = this.buildVideoUrl(this.video)
102 case UserNotificationType.NEW_COMMENT_ON_MY_VIDEO:
103 case UserNotificationType.COMMENT_MENTION:
104 this.accountUrl = this.buildAccountUrl(this.comment.account)
105 this.commentUrl = [ this.buildVideoUrl(this.comment.video), { threadId: this.comment.threadId } ]
108 case UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS:
109 this.videoAbuseUrl = '/admin/moderation/video-abuses/list'
110 this.videoUrl = this.buildVideoUrl(this.videoAbuse.video)
113 case UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS:
114 this.videoAutoBlacklistUrl = '/admin/moderation/video-auto-blacklist/list'
115 this.videoUrl = this.buildVideoUrl(this.video)
118 case UserNotificationType.BLACKLIST_ON_MY_VIDEO:
119 this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video)
122 case UserNotificationType.MY_VIDEO_PUBLISHED:
123 this.videoUrl = this.buildVideoUrl(this.video)
126 case UserNotificationType.MY_VIDEO_IMPORT_SUCCESS:
127 this.videoImportUrl = this.buildVideoImportUrl()
128 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
130 if (this.videoImport.video) this.videoUrl = this.buildVideoUrl(this.videoImport.video)
133 case UserNotificationType.MY_VIDEO_IMPORT_ERROR:
134 this.videoImportUrl = this.buildVideoImportUrl()
135 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
138 case UserNotificationType.NEW_USER_REGISTRATION:
139 this.accountUrl = this.buildAccountUrl(this.account)
142 case UserNotificationType.NEW_FOLLOW:
143 this.accountUrl = this.buildAccountUrl(this.actorFollow.follower)
146 case UserNotificationType.NEW_INSTANCE_FOLLOWER:
147 this.instanceFollowUrl = '/admin/follows/followers-list'
155 private buildVideoUrl (video: { uuid: string }) {
156 return '/videos/watch/' + video.uuid
159 private buildAccountUrl (account: { name: string, host: string }) {
160 return '/accounts/' + Actor.CREATE_BY_STRING(account.name, account.host)
163 private buildVideoImportUrl () {
164 return '/my-account/video-imports'
167 private buildVideoImportIdentifier (videoImport: { targetUrl?: string, magnetUri?: string, torrentName?: string }) {
168 return videoImport.targetUrl || videoImport.magnetUri || videoImport.torrentName
171 private setAvatarUrl (actor: { avatarUrl?: string, avatar?: { path: string } }) {
172 actor.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(actor)