]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user-notification.model.ts
Add newInstanceFollower in notification settings
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user-notification.model.ts
CommitLineData
846751c9 1import { ActorInfo, FollowState, UserNotification as UserNotificationServer, UserNotificationType, VideoInfo } from '../../../../../shared'
457bb213 2import { Actor } from '@app/shared/actor/actor.model'
2f1548fd
C
3
4export class UserNotification implements UserNotificationServer {
5 id: number
6 type: UserNotificationType
7 read: boolean
8
9 video?: VideoInfo & {
457bb213 10 channel: ActorInfo & { avatarUrl?: string }
2f1548fd
C
11 }
12
13 videoImport?: {
14 id: number
15 video?: VideoInfo
16 torrentName?: string
17 magnetUri?: string
18 targetUrl?: string
19 }
20
21 comment?: {
22 id: number
23 threadId: number
457bb213 24 account: ActorInfo & { avatarUrl?: string }
2f1548fd
C
25 video: VideoInfo
26 }
27
28 videoAbuse?: {
29 id: number
30 video: VideoInfo
31 }
32
33 videoBlacklist?: {
34 id: number
35 video: VideoInfo
36 }
37
457bb213 38 account?: ActorInfo & { avatarUrl?: string }
2f1548fd
C
39
40 actorFollow?: {
41 id: number
846751c9 42 state: FollowState
457bb213 43 follower: ActorInfo & { avatarUrl?: string }
2f1548fd
C
44 following: {
45 type: 'account' | 'channel'
46 name: string
47 displayName: string
48 }
49 }
50
51 createdAt: string
52 updatedAt: string
53
54 // Additional fields
55 videoUrl?: string
56 commentUrl?: any[]
57 videoAbuseUrl?: string
7ccddd7b 58 videoAutoBlacklistUrl?: string
2f1548fd
C
59 accountUrl?: string
60 videoImportIdentifier?: string
61 videoImportUrl?: string
62
63 constructor (hash: UserNotificationServer) {
64 this.id = hash.id
65 this.type = hash.type
66 this.read = hash.read
67
344d8be5
C
68 // We assume that some fields exist
69 // To prevent a notification popup crash in case of bug, wrap it inside a try/catch
70 try {
71 this.video = hash.video
72 if (this.video) this.setAvatarUrl(this.video.channel)
73
74 this.videoImport = hash.videoImport
75
76 this.comment = hash.comment
77 if (this.comment) this.setAvatarUrl(this.comment.account)
78
79 this.videoAbuse = hash.videoAbuse
80
81 this.videoBlacklist = hash.videoBlacklist
82
83 this.account = hash.account
84 if (this.account) this.setAvatarUrl(this.account)
85
86 this.actorFollow = hash.actorFollow
87 if (this.actorFollow) this.setAvatarUrl(this.actorFollow.follower)
88
89 this.createdAt = hash.createdAt
90 this.updatedAt = hash.updatedAt
91
92 switch (this.type) {
93 case UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION:
94 this.videoUrl = this.buildVideoUrl(this.video)
95 break
96
97 case UserNotificationType.UNBLACKLIST_ON_MY_VIDEO:
98 this.videoUrl = this.buildVideoUrl(this.video)
99 break
100
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 } ]
105 break
106
107 case UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS:
108 this.videoAbuseUrl = '/admin/moderation/video-abuses/list'
109 this.videoUrl = this.buildVideoUrl(this.videoAbuse.video)
110 break
111
7ccddd7b
JM
112 case UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS:
113 this.videoAutoBlacklistUrl = '/admin/moderation/video-auto-blacklist/list'
114 this.videoUrl = this.buildVideoUrl(this.video)
115 break
116
344d8be5
C
117 case UserNotificationType.BLACKLIST_ON_MY_VIDEO:
118 this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video)
119 break
120
121 case UserNotificationType.MY_VIDEO_PUBLISHED:
122 this.videoUrl = this.buildVideoUrl(this.video)
123 break
124
125 case UserNotificationType.MY_VIDEO_IMPORT_SUCCESS:
126 this.videoImportUrl = this.buildVideoImportUrl()
127 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
6d28a505
C
128
129 if (this.videoImport.video) this.videoUrl = this.buildVideoUrl(this.videoImport.video)
344d8be5
C
130 break
131
132 case UserNotificationType.MY_VIDEO_IMPORT_ERROR:
133 this.videoImportUrl = this.buildVideoImportUrl()
134 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
135 break
136
137 case UserNotificationType.NEW_USER_REGISTRATION:
138 this.accountUrl = this.buildAccountUrl(this.account)
139 break
140
141 case UserNotificationType.NEW_FOLLOW:
142 this.accountUrl = this.buildAccountUrl(this.actorFollow.follower)
143 break
144 }
145 } catch (err) {
146 console.error(err)
2f1548fd
C
147 }
148 }
149
150 private buildVideoUrl (video: { uuid: string }) {
151 return '/videos/watch/' + video.uuid
152 }
153
38967f7b
C
154 private buildAccountUrl (account: { name: string, host: string }) {
155 return '/accounts/' + Actor.CREATE_BY_STRING(account.name, account.host)
2f1548fd
C
156 }
157
158 private buildVideoImportUrl () {
159 return '/my-account/video-imports'
160 }
161
162 private buildVideoImportIdentifier (videoImport: { targetUrl?: string, magnetUri?: string, torrentName?: string }) {
163 return videoImport.targetUrl || videoImport.magnetUri || videoImport.torrentName
164 }
165
457bb213
C
166 private setAvatarUrl (actor: { avatarUrl?: string, avatar?: { path: string } }) {
167 actor.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(actor)
168 }
2f1548fd 169}