]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/users/user-notification.model.ts
modify user-quota to match account settings style
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / users / user-notification.model.ts
CommitLineData
67ed6552
C
1import { Actor } from '../account/actor.model'
2import { ActorInfo, Avatar, FollowState, UserNotification as UserNotificationServer, UserNotificationType, VideoInfo } from '@shared/models'
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
d95d1559 28 abuse?: {
2f1548fd 29 id: number
d95d1559
C
30
31 video?: VideoInfo
32
33 comment?: {
34 threadId: number
35
36 video: {
cfde28ba 37 id: number
d95d1559 38 uuid: string
cfde28ba 39 name: string
d95d1559
C
40 }
41 }
42
43 account?: ActorInfo
2f1548fd
C
44 }
45
46 videoBlacklist?: {
47 id: number
48 video: VideoInfo
49 }
50
457bb213 51 account?: ActorInfo & { avatarUrl?: string }
2f1548fd
C
52
53 actorFollow?: {
54 id: number
846751c9 55 state: FollowState
457bb213 56 follower: ActorInfo & { avatarUrl?: string }
2f1548fd 57 following: {
e1b49ee5 58 type: 'account' | 'channel' | 'instance'
2f1548fd
C
59 name: string
60 displayName: string
e1b49ee5 61 host: string
2f1548fd
C
62 }
63 }
64
65 createdAt: string
66 updatedAt: string
67
68 // Additional fields
69 videoUrl?: string
70 commentUrl?: any[]
d95d1559 71 abuseUrl?: string
7ccddd7b 72 videoAutoBlacklistUrl?: string
2f1548fd
C
73 accountUrl?: string
74 videoImportIdentifier?: string
75 videoImportUrl?: string
8ce1ba6e 76 instanceFollowUrl?: string
2f1548fd
C
77
78 constructor (hash: UserNotificationServer) {
79 this.id = hash.id
80 this.type = hash.type
81 this.read = hash.read
82
344d8be5
C
83 // We assume that some fields exist
84 // To prevent a notification popup crash in case of bug, wrap it inside a try/catch
85 try {
86 this.video = hash.video
87 if (this.video) this.setAvatarUrl(this.video.channel)
88
89 this.videoImport = hash.videoImport
90
91 this.comment = hash.comment
92 if (this.comment) this.setAvatarUrl(this.comment.account)
93
d95d1559 94 this.abuse = hash.abuse
344d8be5
C
95
96 this.videoBlacklist = hash.videoBlacklist
97
98 this.account = hash.account
99 if (this.account) this.setAvatarUrl(this.account)
100
101 this.actorFollow = hash.actorFollow
102 if (this.actorFollow) this.setAvatarUrl(this.actorFollow.follower)
103
104 this.createdAt = hash.createdAt
105 this.updatedAt = hash.updatedAt
106
107 switch (this.type) {
108 case UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION:
109 this.videoUrl = this.buildVideoUrl(this.video)
110 break
111
112 case UserNotificationType.UNBLACKLIST_ON_MY_VIDEO:
113 this.videoUrl = this.buildVideoUrl(this.video)
114 break
115
116 case UserNotificationType.NEW_COMMENT_ON_MY_VIDEO:
117 case UserNotificationType.COMMENT_MENTION:
c5c09c1e 118 if (!this.comment) break
344d8be5 119 this.accountUrl = this.buildAccountUrl(this.comment.account)
cfde28ba 120 this.commentUrl = this.buildCommentUrl(this.comment)
344d8be5
C
121 break
122
310b5219 123 case UserNotificationType.NEW_ABUSE_FOR_MODERATORS:
d95d1559
C
124 this.abuseUrl = '/admin/moderation/abuses/list'
125
126 if (this.abuse.video) this.videoUrl = this.buildVideoUrl(this.abuse.video)
cfde28ba
C
127 else if (this.abuse.comment) this.commentUrl = this.buildCommentUrl(this.abuse.comment)
128 else if (this.abuse.account) this.accountUrl = this.buildAccountUrl(this.abuse.account)
344d8be5
C
129 break
130
7ccddd7b
JM
131 case UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS:
132 this.videoAutoBlacklistUrl = '/admin/moderation/video-auto-blacklist/list'
43d35494
C
133 // Backward compatibility where we did not assign videoBlacklist to this type of notification before
134 if (!this.videoBlacklist) this.videoBlacklist = { id: null, video: this.video }
135
8424c402 136 this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video)
7ccddd7b
JM
137 break
138
344d8be5
C
139 case UserNotificationType.BLACKLIST_ON_MY_VIDEO:
140 this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video)
141 break
142
143 case UserNotificationType.MY_VIDEO_PUBLISHED:
144 this.videoUrl = this.buildVideoUrl(this.video)
145 break
146
147 case UserNotificationType.MY_VIDEO_IMPORT_SUCCESS:
148 this.videoImportUrl = this.buildVideoImportUrl()
149 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
6d28a505
C
150
151 if (this.videoImport.video) this.videoUrl = this.buildVideoUrl(this.videoImport.video)
344d8be5
C
152 break
153
154 case UserNotificationType.MY_VIDEO_IMPORT_ERROR:
155 this.videoImportUrl = this.buildVideoImportUrl()
156 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
157 break
158
159 case UserNotificationType.NEW_USER_REGISTRATION:
160 this.accountUrl = this.buildAccountUrl(this.account)
161 break
162
163 case UserNotificationType.NEW_FOLLOW:
164 this.accountUrl = this.buildAccountUrl(this.actorFollow.follower)
165 break
8ce1ba6e
C
166
167 case UserNotificationType.NEW_INSTANCE_FOLLOWER:
168 this.instanceFollowUrl = '/admin/follows/followers-list'
169 break
e1b49ee5
C
170
171 case UserNotificationType.AUTO_INSTANCE_FOLLOWING:
172 this.instanceFollowUrl = '/admin/follows/following-list'
173 break
344d8be5
C
174 }
175 } catch (err) {
44b88f18 176 this.type = null
344d8be5 177 console.error(err)
2f1548fd
C
178 }
179 }
180
181 private buildVideoUrl (video: { uuid: string }) {
182 return '/videos/watch/' + video.uuid
183 }
184
38967f7b
C
185 private buildAccountUrl (account: { name: string, host: string }) {
186 return '/accounts/' + Actor.CREATE_BY_STRING(account.name, account.host)
2f1548fd
C
187 }
188
189 private buildVideoImportUrl () {
190 return '/my-account/video-imports'
191 }
192
193 private buildVideoImportIdentifier (videoImport: { targetUrl?: string, magnetUri?: string, torrentName?: string }) {
194 return videoImport.targetUrl || videoImport.magnetUri || videoImport.torrentName
195 }
196
cfde28ba
C
197 private buildCommentUrl (comment: { video: { uuid: string }, threadId: number }) {
198 return [ this.buildVideoUrl(comment.video), { threadId: comment.threadId } ]
199 }
200
d95d1559 201 private setAvatarUrl (actor: { avatarUrl?: string, avatar?: { url?: string, path: string } }) {
457bb213
C
202 actor.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(actor)
203 }
2f1548fd 204}