]>
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 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 | |
8ce1ba6e | 62 | instanceFollowUrl?: string |
2f1548fd C |
63 | |
64 | constructor (hash: UserNotificationServer) { | |
65 | this.id = hash.id | |
66 | this.type = hash.type | |
67 | this.read = hash.read | |
68 | ||
344d8be5 C |
69 | // We assume that some fields exist |
70 | // To prevent a notification popup crash in case of bug, wrap it inside a try/catch | |
71 | try { | |
72 | this.video = hash.video | |
73 | if (this.video) this.setAvatarUrl(this.video.channel) | |
74 | ||
75 | this.videoImport = hash.videoImport | |
76 | ||
77 | this.comment = hash.comment | |
78 | if (this.comment) this.setAvatarUrl(this.comment.account) | |
79 | ||
80 | this.videoAbuse = hash.videoAbuse | |
81 | ||
82 | this.videoBlacklist = hash.videoBlacklist | |
83 | ||
84 | this.account = hash.account | |
85 | if (this.account) this.setAvatarUrl(this.account) | |
86 | ||
87 | this.actorFollow = hash.actorFollow | |
88 | if (this.actorFollow) this.setAvatarUrl(this.actorFollow.follower) | |
89 | ||
90 | this.createdAt = hash.createdAt | |
91 | this.updatedAt = hash.updatedAt | |
92 | ||
93 | switch (this.type) { | |
94 | case UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION: | |
95 | this.videoUrl = this.buildVideoUrl(this.video) | |
96 | break | |
97 | ||
98 | case UserNotificationType.UNBLACKLIST_ON_MY_VIDEO: | |
99 | this.videoUrl = this.buildVideoUrl(this.video) | |
100 | break | |
101 | ||
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 } ] | |
106 | break | |
107 | ||
108 | case UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS: | |
109 | this.videoAbuseUrl = '/admin/moderation/video-abuses/list' | |
110 | this.videoUrl = this.buildVideoUrl(this.videoAbuse.video) | |
111 | break | |
112 | ||
7ccddd7b JM |
113 | case UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS: |
114 | this.videoAutoBlacklistUrl = '/admin/moderation/video-auto-blacklist/list' | |
115 | this.videoUrl = this.buildVideoUrl(this.video) | |
116 | break | |
117 | ||
344d8be5 C |
118 | case UserNotificationType.BLACKLIST_ON_MY_VIDEO: |
119 | this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video) | |
120 | break | |
121 | ||
122 | case UserNotificationType.MY_VIDEO_PUBLISHED: | |
123 | this.videoUrl = this.buildVideoUrl(this.video) | |
124 | break | |
125 | ||
126 | case UserNotificationType.MY_VIDEO_IMPORT_SUCCESS: | |
127 | this.videoImportUrl = this.buildVideoImportUrl() | |
128 | this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport) | |
6d28a505 C |
129 | |
130 | if (this.videoImport.video) this.videoUrl = this.buildVideoUrl(this.videoImport.video) | |
344d8be5 C |
131 | break |
132 | ||
133 | case UserNotificationType.MY_VIDEO_IMPORT_ERROR: | |
134 | this.videoImportUrl = this.buildVideoImportUrl() | |
135 | this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport) | |
136 | break | |
137 | ||
138 | case UserNotificationType.NEW_USER_REGISTRATION: | |
139 | this.accountUrl = this.buildAccountUrl(this.account) | |
140 | break | |
141 | ||
142 | case UserNotificationType.NEW_FOLLOW: | |
143 | this.accountUrl = this.buildAccountUrl(this.actorFollow.follower) | |
144 | break | |
8ce1ba6e C |
145 | |
146 | case UserNotificationType.NEW_INSTANCE_FOLLOWER: | |
147 | this.instanceFollowUrl = '/admin/follows/followers-list' | |
148 | break | |
344d8be5 C |
149 | } |
150 | } catch (err) { | |
44b88f18 | 151 | this.type = null |
344d8be5 | 152 | console.error(err) |
2f1548fd C |
153 | } |
154 | } | |
155 | ||
156 | private buildVideoUrl (video: { uuid: string }) { | |
157 | return '/videos/watch/' + video.uuid | |
158 | } | |
159 | ||
38967f7b C |
160 | private buildAccountUrl (account: { name: string, host: string }) { |
161 | return '/accounts/' + Actor.CREATE_BY_STRING(account.name, account.host) | |
2f1548fd C |
162 | } |
163 | ||
164 | private buildVideoImportUrl () { | |
165 | return '/my-account/video-imports' | |
166 | } | |
167 | ||
168 | private buildVideoImportIdentifier (videoImport: { targetUrl?: string, magnetUri?: string, torrentName?: string }) { | |
169 | return videoImport.targetUrl || videoImport.magnetUri || videoImport.torrentName | |
170 | } | |
171 | ||
457bb213 C |
172 | private setAvatarUrl (actor: { avatarUrl?: string, avatar?: { path: string } }) { |
173 | actor.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(actor) | |
174 | } | |
2f1548fd | 175 | } |