diff options
Diffstat (limited to 'client/src/app/shared/users/user-notification.model.ts')
-rw-r--r-- | client/src/app/shared/users/user-notification.model.ts | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/client/src/app/shared/users/user-notification.model.ts b/client/src/app/shared/users/user-notification.model.ts new file mode 100644 index 000000000..5ff816fb8 --- /dev/null +++ b/client/src/app/shared/users/user-notification.model.ts | |||
@@ -0,0 +1,153 @@ | |||
1 | import { UserNotification as UserNotificationServer, UserNotificationType, VideoInfo } from '../../../../../shared' | ||
2 | |||
3 | export class UserNotification implements UserNotificationServer { | ||
4 | id: number | ||
5 | type: UserNotificationType | ||
6 | read: boolean | ||
7 | |||
8 | video?: VideoInfo & { | ||
9 | channel: { | ||
10 | id: number | ||
11 | displayName: string | ||
12 | } | ||
13 | } | ||
14 | |||
15 | videoImport?: { | ||
16 | id: number | ||
17 | video?: VideoInfo | ||
18 | torrentName?: string | ||
19 | magnetUri?: string | ||
20 | targetUrl?: string | ||
21 | } | ||
22 | |||
23 | comment?: { | ||
24 | id: number | ||
25 | threadId: number | ||
26 | account: { | ||
27 | id: number | ||
28 | displayName: string | ||
29 | } | ||
30 | video: VideoInfo | ||
31 | } | ||
32 | |||
33 | videoAbuse?: { | ||
34 | id: number | ||
35 | video: VideoInfo | ||
36 | } | ||
37 | |||
38 | videoBlacklist?: { | ||
39 | id: number | ||
40 | video: VideoInfo | ||
41 | } | ||
42 | |||
43 | account?: { | ||
44 | id: number | ||
45 | displayName: string | ||
46 | name: string | ||
47 | } | ||
48 | |||
49 | actorFollow?: { | ||
50 | id: number | ||
51 | follower: { | ||
52 | name: string | ||
53 | displayName: string | ||
54 | } | ||
55 | following: { | ||
56 | type: 'account' | 'channel' | ||
57 | name: string | ||
58 | displayName: string | ||
59 | } | ||
60 | } | ||
61 | |||
62 | createdAt: string | ||
63 | updatedAt: string | ||
64 | |||
65 | // Additional fields | ||
66 | videoUrl?: string | ||
67 | commentUrl?: any[] | ||
68 | videoAbuseUrl?: string | ||
69 | accountUrl?: string | ||
70 | videoImportIdentifier?: string | ||
71 | videoImportUrl?: string | ||
72 | |||
73 | constructor (hash: UserNotificationServer) { | ||
74 | this.id = hash.id | ||
75 | this.type = hash.type | ||
76 | this.read = hash.read | ||
77 | |||
78 | this.video = hash.video | ||
79 | this.videoImport = hash.videoImport | ||
80 | this.comment = hash.comment | ||
81 | this.videoAbuse = hash.videoAbuse | ||
82 | this.videoBlacklist = hash.videoBlacklist | ||
83 | this.account = hash.account | ||
84 | this.actorFollow = hash.actorFollow | ||
85 | |||
86 | this.createdAt = hash.createdAt | ||
87 | this.updatedAt = hash.updatedAt | ||
88 | |||
89 | switch (this.type) { | ||
90 | case UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION: | ||
91 | this.videoUrl = this.buildVideoUrl(this.video) | ||
92 | break | ||
93 | |||
94 | case UserNotificationType.UNBLACKLIST_ON_MY_VIDEO: | ||
95 | this.videoUrl = this.buildVideoUrl(this.video) | ||
96 | break | ||
97 | |||
98 | case UserNotificationType.NEW_COMMENT_ON_MY_VIDEO: | ||
99 | case UserNotificationType.COMMENT_MENTION: | ||
100 | this.commentUrl = [ this.buildVideoUrl(this.comment.video), { threadId: this.comment.threadId } ] | ||
101 | break | ||
102 | |||
103 | case UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS: | ||
104 | this.videoAbuseUrl = '/admin/moderation/video-abuses/list' | ||
105 | this.videoUrl = this.buildVideoUrl(this.videoAbuse.video) | ||
106 | break | ||
107 | |||
108 | case UserNotificationType.BLACKLIST_ON_MY_VIDEO: | ||
109 | this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video) | ||
110 | break | ||
111 | |||
112 | case UserNotificationType.MY_VIDEO_PUBLISHED: | ||
113 | this.videoUrl = this.buildVideoUrl(this.video) | ||
114 | break | ||
115 | |||
116 | case UserNotificationType.MY_VIDEO_IMPORT_SUCCESS: | ||
117 | this.videoImportUrl = this.buildVideoImportUrl() | ||
118 | this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport) | ||
119 | this.videoUrl = this.buildVideoUrl(this.videoImport.video) | ||
120 | break | ||
121 | |||
122 | case UserNotificationType.MY_VIDEO_IMPORT_ERROR: | ||
123 | this.videoImportUrl = this.buildVideoImportUrl() | ||
124 | this.videoImportIdentifier = this.buildVideoImportIdentifier(this.videoImport) | ||
125 | break | ||
126 | |||
127 | case UserNotificationType.NEW_USER_REGISTRATION: | ||
128 | this.accountUrl = this.buildAccountUrl(this.account) | ||
129 | break | ||
130 | |||
131 | case UserNotificationType.NEW_FOLLOW: | ||
132 | this.accountUrl = this.buildAccountUrl(this.actorFollow.follower) | ||
133 | break | ||
134 | } | ||
135 | } | ||
136 | |||
137 | private buildVideoUrl (video: { uuid: string }) { | ||
138 | return '/videos/watch/' + video.uuid | ||
139 | } | ||
140 | |||
141 | private buildAccountUrl (account: { name: string }) { | ||
142 | return '/accounts/' + account.name | ||
143 | } | ||
144 | |||
145 | private buildVideoImportUrl () { | ||
146 | return '/my-account/video-imports' | ||
147 | } | ||
148 | |||
149 | private buildVideoImportIdentifier (videoImport: { targetUrl?: string, magnetUri?: string, torrentName?: string }) { | ||
150 | return videoImport.targetUrl || videoImport.magnetUri || videoImport.torrentName | ||
151 | } | ||
152 | |||
153 | } | ||