]>
Commit | Line | Data |
---|---|---|
846751c9 | 1 | import { ActorInfo, FollowState, UserNotification as UserNotificationServer, UserNotificationType, VideoInfo } from '../../../../../shared' |
457bb213 | 2 | import { Actor } from '@app/shared/actor/actor.model' |
2f1548fd C |
3 | |
4 | export 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 | 44 | following: { |
e1b49ee5 | 45 | type: 'account' | 'channel' | 'instance' |
2f1548fd C |
46 | name: string |
47 | displayName: string | |
e1b49ee5 | 48 | host: string |
2f1548fd C |
49 | } |
50 | } | |
51 | ||
52 | createdAt: string | |
53 | updatedAt: string | |
54 | ||
55 | // Additional fields | |
56 | videoUrl?: string | |
57 | commentUrl?: any[] | |
58 | videoAbuseUrl?: string | |
7ccddd7b | 59 | videoAutoBlacklistUrl?: string |
2f1548fd C |
60 | accountUrl?: string |
61 | videoImportIdentifier?: string | |
62 | videoImportUrl?: string | |
8ce1ba6e | 63 | instanceFollowUrl?: string |
2f1548fd C |
64 | |
65 | constructor (hash: UserNotificationServer) { | |
66 | this.id = hash.id | |
67 | this.type = hash.type | |
68 | this.read = hash.read | |
69 | ||
344d8be5 C |
70 | // We assume that some fields exist |
71 | // To prevent a notification popup crash in case of bug, wrap it inside a try/catch | |
72 | try { | |
73 | this.video = hash.video | |
74 | if (this.video) this.setAvatarUrl(this.video.channel) | |
75 | ||
76 | this.videoImport = hash.videoImport | |
77 | ||
78 | this.comment = hash.comment | |
79 | if (this.comment) this.setAvatarUrl(this.comment.account) | |
80 | ||
81 | this.videoAbuse = hash.videoAbuse | |
82 | ||
83 | this.videoBlacklist = hash.videoBlacklist | |
84 | ||
85 | this.account = hash.account | |
86 | if (this.account) this.setAvatarUrl(this.account) | |
87 | ||
88 | this.actorFollow = hash.actorFollow | |
89 | if (this.actorFollow) this.setAvatarUrl(this.actorFollow.follower) | |
90 | ||
91 | this.createdAt = hash.createdAt | |
92 | this.updatedAt = hash.updatedAt | |
93 | ||
94 | switch (this.type) { | |
95 | case UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION: | |
96 | this.videoUrl = this.buildVideoUrl(this.video) | |
97 | break | |
98 | ||
99 | case UserNotificationType.UNBLACKLIST_ON_MY_VIDEO: | |
100 | this.videoUrl = this.buildVideoUrl(this.video) | |
101 | break | |
102 | ||
103 | case UserNotificationType.NEW_COMMENT_ON_MY_VIDEO: | |
104 | case UserNotificationType.COMMENT_MENTION: | |
c5c09c1e | 105 | if (!this.comment) break |
344d8be5 C |
106 | this.accountUrl = this.buildAccountUrl(this.comment.account) |
107 | this.commentUrl = [ this.buildVideoUrl(this.comment.video), { threadId: this.comment.threadId } ] | |
108 | break | |
109 | ||
110 | case UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS: | |
111 | this.videoAbuseUrl = '/admin/moderation/video-abuses/list' | |
112 | this.videoUrl = this.buildVideoUrl(this.videoAbuse.video) | |
113 | break | |
114 | ||
7ccddd7b JM |
115 | case UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS: |
116 | this.videoAutoBlacklistUrl = '/admin/moderation/video-auto-blacklist/list' | |
43d35494 C |
117 | // Backward compatibility where we did not assign videoBlacklist to this type of notification before |
118 | if (!this.videoBlacklist) this.videoBlacklist = { id: null, video: this.video } | |
119 | ||
8424c402 | 120 | this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video) |
7ccddd7b JM |
121 | break |
122 | ||
344d8be5 C |
123 | case UserNotificationType.BLACKLIST_ON_MY_VIDEO: |
124 | this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video) | |
125 | break | |
126 | ||
127 | case UserNotificationType.MY_VIDEO_PUBLISHED: | |
128 | this.videoUrl = this.buildVideoUrl(this.video) | |
129 | break | |
130 | ||
131 | case UserNotificationType.MY_VIDEO_IMPORT_SUCCESS: | |
132 | this.videoImportUrl = this.buildVideoImportUrl() | |
133 | this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport) | |
6d28a505 C |
134 | |
135 | if (this.videoImport.video) this.videoUrl = this.buildVideoUrl(this.videoImport.video) | |
344d8be5 C |
136 | break |
137 | ||
138 | case UserNotificationType.MY_VIDEO_IMPORT_ERROR: | |
139 | this.videoImportUrl = this.buildVideoImportUrl() | |
140 | this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport) | |
141 | break | |
142 | ||
143 | case UserNotificationType.NEW_USER_REGISTRATION: | |
144 | this.accountUrl = this.buildAccountUrl(this.account) | |
145 | break | |
146 | ||
147 | case UserNotificationType.NEW_FOLLOW: | |
148 | this.accountUrl = this.buildAccountUrl(this.actorFollow.follower) | |
149 | break | |
8ce1ba6e C |
150 | |
151 | case UserNotificationType.NEW_INSTANCE_FOLLOWER: | |
152 | this.instanceFollowUrl = '/admin/follows/followers-list' | |
153 | break | |
e1b49ee5 C |
154 | |
155 | case UserNotificationType.AUTO_INSTANCE_FOLLOWING: | |
156 | this.instanceFollowUrl = '/admin/follows/following-list' | |
157 | break | |
344d8be5 C |
158 | } |
159 | } catch (err) { | |
44b88f18 | 160 | this.type = null |
344d8be5 | 161 | console.error(err) |
2f1548fd C |
162 | } |
163 | } | |
164 | ||
165 | private buildVideoUrl (video: { uuid: string }) { | |
166 | return '/videos/watch/' + video.uuid | |
167 | } | |
168 | ||
38967f7b C |
169 | private buildAccountUrl (account: { name: string, host: string }) { |
170 | return '/accounts/' + Actor.CREATE_BY_STRING(account.name, account.host) | |
2f1548fd C |
171 | } |
172 | ||
173 | private buildVideoImportUrl () { | |
174 | return '/my-account/video-imports' | |
175 | } | |
176 | ||
177 | private buildVideoImportIdentifier (videoImport: { targetUrl?: string, magnetUri?: string, torrentName?: string }) { | |
178 | return videoImport.targetUrl || videoImport.magnetUri || videoImport.torrentName | |
179 | } | |
180 | ||
457bb213 C |
181 | private setAvatarUrl (actor: { avatarUrl?: string, avatar?: { path: string } }) { |
182 | actor.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(actor) | |
183 | } | |
2f1548fd | 184 | } |