]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user-notification.model.ts
Refactor how we use icons
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user-notification.model.ts
CommitLineData
457bb213
C
1import { UserNotification as UserNotificationServer, UserNotificationType, VideoInfo, ActorInfo } from '../../../../../shared'
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
457bb213 42 follower: ActorInfo & { avatarUrl?: string }
2f1548fd
C
43 following: {
44 type: 'account' | 'channel'
45 name: string
46 displayName: string
47 }
48 }
49
50 createdAt: string
51 updatedAt: string
52
53 // Additional fields
54 videoUrl?: string
55 commentUrl?: any[]
56 videoAbuseUrl?: string
57 accountUrl?: string
58 videoImportIdentifier?: string
59 videoImportUrl?: string
60
61 constructor (hash: UserNotificationServer) {
62 this.id = hash.id
63 this.type = hash.type
64 this.read = hash.read
65
66 this.video = hash.video
457bb213
C
67 if (this.video) this.setAvatarUrl(this.video.channel)
68
2f1548fd 69 this.videoImport = hash.videoImport
457bb213 70
2f1548fd 71 this.comment = hash.comment
457bb213
C
72 if (this.comment) this.setAvatarUrl(this.comment.account)
73
2f1548fd 74 this.videoAbuse = hash.videoAbuse
457bb213 75
2f1548fd 76 this.videoBlacklist = hash.videoBlacklist
457bb213 77
2f1548fd 78 this.account = hash.account
457bb213
C
79 if (this.account) this.setAvatarUrl(this.account)
80
2f1548fd 81 this.actorFollow = hash.actorFollow
457bb213 82 if (this.actorFollow) this.setAvatarUrl(this.actorFollow.follower)
2f1548fd
C
83
84 this.createdAt = hash.createdAt
85 this.updatedAt = hash.updatedAt
86
87 switch (this.type) {
88 case UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION:
89 this.videoUrl = this.buildVideoUrl(this.video)
90 break
91
92 case UserNotificationType.UNBLACKLIST_ON_MY_VIDEO:
93 this.videoUrl = this.buildVideoUrl(this.video)
94 break
95
96 case UserNotificationType.NEW_COMMENT_ON_MY_VIDEO:
97 case UserNotificationType.COMMENT_MENTION:
98 this.commentUrl = [ this.buildVideoUrl(this.comment.video), { threadId: this.comment.threadId } ]
99 break
100
101 case UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS:
102 this.videoAbuseUrl = '/admin/moderation/video-abuses/list'
103 this.videoUrl = this.buildVideoUrl(this.videoAbuse.video)
104 break
105
106 case UserNotificationType.BLACKLIST_ON_MY_VIDEO:
107 this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video)
108 break
109
110 case UserNotificationType.MY_VIDEO_PUBLISHED:
111 this.videoUrl = this.buildVideoUrl(this.video)
112 break
113
114 case UserNotificationType.MY_VIDEO_IMPORT_SUCCESS:
115 this.videoImportUrl = this.buildVideoImportUrl()
116 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
117 this.videoUrl = this.buildVideoUrl(this.videoImport.video)
118 break
119
120 case UserNotificationType.MY_VIDEO_IMPORT_ERROR:
121 this.videoImportUrl = this.buildVideoImportUrl()
122 this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport)
123 break
124
125 case UserNotificationType.NEW_USER_REGISTRATION:
126 this.accountUrl = this.buildAccountUrl(this.account)
127 break
128
129 case UserNotificationType.NEW_FOLLOW:
130 this.accountUrl = this.buildAccountUrl(this.actorFollow.follower)
131 break
132 }
133 }
134
135 private buildVideoUrl (video: { uuid: string }) {
136 return '/videos/watch/' + video.uuid
137 }
138
139 private buildAccountUrl (account: { name: string }) {
140 return '/accounts/' + account.name
141 }
142
143 private buildVideoImportUrl () {
144 return '/my-account/video-imports'
145 }
146
147 private buildVideoImportIdentifier (videoImport: { targetUrl?: string, magnetUri?: string, torrentName?: string }) {
148 return videoImport.targetUrl || videoImport.magnetUri || videoImport.torrentName
149 }
150
457bb213
C
151 private setAvatarUrl (actor: { avatarUrl?: string, avatar?: { path: string } }) {
152 actor.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(actor)
153 }
2f1548fd 154}