diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-15 11:53:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-19 17:26:35 +0200 |
commit | 453e83ea5d81d203ba34bc43cd5c2c750ba40568 (patch) | |
tree | 604e02f4343d13a4ba42e1fb7527ba6ab9111712 /server/lib/emailer.ts | |
parent | 13176a07a95984a53cc59aec5217f2ce9806d1bc (diff) | |
download | PeerTube-453e83ea5d81d203ba34bc43cd5c2c750ba40568.tar.gz PeerTube-453e83ea5d81d203ba34bc43cd5c2c750ba40568.tar.zst PeerTube-453e83ea5d81d203ba34bc43cd5c2c750ba40568.zip |
Stronger model typings
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r-- | server/lib/emailer.ts | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index 73c2bcb1b..fe57a3e4c 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts | |||
@@ -3,16 +3,14 @@ import { isTestInstance } from '../helpers/core-utils' | |||
3 | import { bunyanLogger, logger } from '../helpers/logger' | 3 | import { bunyanLogger, logger } from '../helpers/logger' |
4 | import { CONFIG } from '../initializers/config' | 4 | import { CONFIG } from '../initializers/config' |
5 | import { UserModel } from '../models/account/user' | 5 | import { UserModel } from '../models/account/user' |
6 | import { VideoModel } from '../models/video/video' | ||
7 | import { JobQueue } from './job-queue' | 6 | import { JobQueue } from './job-queue' |
8 | import { EmailPayload } from './job-queue/handlers/email' | 7 | import { EmailPayload } from './job-queue/handlers/email' |
9 | import { readFileSync } from 'fs-extra' | 8 | import { readFileSync } from 'fs-extra' |
10 | import { VideoCommentModel } from '../models/video/video-comment' | ||
11 | import { VideoAbuseModel } from '../models/video/video-abuse' | ||
12 | import { VideoBlacklistModel } from '../models/video/video-blacklist' | 9 | import { VideoBlacklistModel } from '../models/video/video-blacklist' |
13 | import { VideoImportModel } from '../models/video/video-import' | ||
14 | import { ActorFollowModel } from '../models/activitypub/actor-follow' | ||
15 | import { WEBSERVER } from '../initializers/constants' | 10 | import { WEBSERVER } from '../initializers/constants' |
11 | import { MCommentOwnerVideo, MVideo, MVideoAbuseVideo, MVideoAccountLight, MVideoBlacklistVideo } from '../typings/models/video' | ||
12 | import { MActorFollowActors, MActorFollowFull, MUser } from '../typings/models' | ||
13 | import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import' | ||
16 | 14 | ||
17 | type SendEmailOptions = { | 15 | type SendEmailOptions = { |
18 | to: string[] | 16 | to: string[] |
@@ -90,7 +88,7 @@ class Emailer { | |||
90 | } | 88 | } |
91 | } | 89 | } |
92 | 90 | ||
93 | addNewVideoFromSubscriberNotification (to: string[], video: VideoModel) { | 91 | addNewVideoFromSubscriberNotification (to: string[], video: MVideoAccountLight) { |
94 | const channelName = video.VideoChannel.getDisplayName() | 92 | const channelName = video.VideoChannel.getDisplayName() |
95 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() | 93 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() |
96 | 94 | ||
@@ -111,7 +109,7 @@ class Emailer { | |||
111 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 109 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
112 | } | 110 | } |
113 | 111 | ||
114 | addNewFollowNotification (to: string[], actorFollow: ActorFollowModel, followType: 'account' | 'channel') { | 112 | addNewFollowNotification (to: string[], actorFollow: MActorFollowFull, followType: 'account' | 'channel') { |
115 | const followerName = actorFollow.ActorFollower.Account.getDisplayName() | 113 | const followerName = actorFollow.ActorFollower.Account.getDisplayName() |
116 | const followingName = (actorFollow.ActorFollowing.VideoChannel || actorFollow.ActorFollowing.Account).getDisplayName() | 114 | const followingName = (actorFollow.ActorFollowing.VideoChannel || actorFollow.ActorFollowing.Account).getDisplayName() |
117 | 115 | ||
@@ -130,7 +128,7 @@ class Emailer { | |||
130 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 128 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
131 | } | 129 | } |
132 | 130 | ||
133 | addNewInstanceFollowerNotification (to: string[], actorFollow: ActorFollowModel) { | 131 | addNewInstanceFollowerNotification (to: string[], actorFollow: MActorFollowActors) { |
134 | const awaitingApproval = actorFollow.state === 'pending' ? ' awaiting manual approval.' : '' | 132 | const awaitingApproval = actorFollow.state === 'pending' ? ' awaiting manual approval.' : '' |
135 | 133 | ||
136 | const text = `Hi dear admin,\n\n` + | 134 | const text = `Hi dear admin,\n\n` + |
@@ -148,7 +146,7 @@ class Emailer { | |||
148 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 146 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
149 | } | 147 | } |
150 | 148 | ||
151 | myVideoPublishedNotification (to: string[], video: VideoModel) { | 149 | myVideoPublishedNotification (to: string[], video: MVideo) { |
152 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() | 150 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() |
153 | 151 | ||
154 | const text = `Hi dear user,\n\n` + | 152 | const text = `Hi dear user,\n\n` + |
@@ -168,7 +166,7 @@ class Emailer { | |||
168 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 166 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
169 | } | 167 | } |
170 | 168 | ||
171 | myVideoImportSuccessNotification (to: string[], videoImport: VideoImportModel) { | 169 | myVideoImportSuccessNotification (to: string[], videoImport: MVideoImportVideo) { |
172 | const videoUrl = WEBSERVER.URL + videoImport.Video.getWatchStaticPath() | 170 | const videoUrl = WEBSERVER.URL + videoImport.Video.getWatchStaticPath() |
173 | 171 | ||
174 | const text = `Hi dear user,\n\n` + | 172 | const text = `Hi dear user,\n\n` + |
@@ -188,7 +186,7 @@ class Emailer { | |||
188 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 186 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
189 | } | 187 | } |
190 | 188 | ||
191 | myVideoImportErrorNotification (to: string[], videoImport: VideoImportModel) { | 189 | myVideoImportErrorNotification (to: string[], videoImport: MVideoImport) { |
192 | const importUrl = WEBSERVER.URL + '/my-account/video-imports' | 190 | const importUrl = WEBSERVER.URL + '/my-account/video-imports' |
193 | 191 | ||
194 | const text = `Hi dear user,\n\n` + | 192 | const text = `Hi dear user,\n\n` + |
@@ -208,7 +206,7 @@ class Emailer { | |||
208 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 206 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
209 | } | 207 | } |
210 | 208 | ||
211 | addNewCommentOnMyVideoNotification (to: string[], comment: VideoCommentModel) { | 209 | addNewCommentOnMyVideoNotification (to: string[], comment: MCommentOwnerVideo) { |
212 | const accountName = comment.Account.getDisplayName() | 210 | const accountName = comment.Account.getDisplayName() |
213 | const video = comment.Video | 211 | const video = comment.Video |
214 | const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath() | 212 | const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath() |
@@ -230,7 +228,7 @@ class Emailer { | |||
230 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 228 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
231 | } | 229 | } |
232 | 230 | ||
233 | addNewCommentMentionNotification (to: string[], comment: VideoCommentModel) { | 231 | addNewCommentMentionNotification (to: string[], comment: MCommentOwnerVideo) { |
234 | const accountName = comment.Account.getDisplayName() | 232 | const accountName = comment.Account.getDisplayName() |
235 | const video = comment.Video | 233 | const video = comment.Video |
236 | const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath() | 234 | const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath() |
@@ -252,7 +250,7 @@ class Emailer { | |||
252 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 250 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
253 | } | 251 | } |
254 | 252 | ||
255 | addVideoAbuseModeratorsNotification (to: string[], videoAbuse: VideoAbuseModel) { | 253 | addVideoAbuseModeratorsNotification (to: string[], videoAbuse: MVideoAbuseVideo) { |
256 | const videoUrl = WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath() | 254 | const videoUrl = WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath() |
257 | 255 | ||
258 | const text = `Hi,\n\n` + | 256 | const text = `Hi,\n\n` + |
@@ -269,7 +267,7 @@ class Emailer { | |||
269 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 267 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
270 | } | 268 | } |
271 | 269 | ||
272 | addVideoAutoBlacklistModeratorsNotification (to: string[], video: VideoModel) { | 270 | addVideoAutoBlacklistModeratorsNotification (to: string[], video: MVideo) { |
273 | const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' | 271 | const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' |
274 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() | 272 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() |
275 | 273 | ||
@@ -292,7 +290,7 @@ class Emailer { | |||
292 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 290 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
293 | } | 291 | } |
294 | 292 | ||
295 | addNewUserRegistrationNotification (to: string[], user: UserModel) { | 293 | addNewUserRegistrationNotification (to: string[], user: MUser) { |
296 | const text = `Hi,\n\n` + | 294 | const text = `Hi,\n\n` + |
297 | `User ${user.username} just registered on ${WEBSERVER.HOST} PeerTube instance.\n\n` + | 295 | `User ${user.username} just registered on ${WEBSERVER.HOST} PeerTube instance.\n\n` + |
298 | `Cheers,\n` + | 296 | `Cheers,\n` + |
@@ -307,7 +305,7 @@ class Emailer { | |||
307 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 305 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
308 | } | 306 | } |
309 | 307 | ||
310 | addVideoBlacklistNotification (to: string[], videoBlacklist: VideoBlacklistModel) { | 308 | addVideoBlacklistNotification (to: string[], videoBlacklist: MVideoBlacklistVideo) { |
311 | const videoName = videoBlacklist.Video.name | 309 | const videoName = videoBlacklist.Video.name |
312 | const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() | 310 | const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() |
313 | 311 | ||
@@ -329,7 +327,7 @@ class Emailer { | |||
329 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 327 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
330 | } | 328 | } |
331 | 329 | ||
332 | addVideoUnblacklistNotification (to: string[], video: VideoModel) { | 330 | addVideoUnblacklistNotification (to: string[], video: MVideo) { |
333 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() | 331 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() |
334 | 332 | ||
335 | const text = 'Hi,\n\n' + | 333 | const text = 'Hi,\n\n' + |
@@ -381,7 +379,7 @@ class Emailer { | |||
381 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 379 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
382 | } | 380 | } |
383 | 381 | ||
384 | addUserBlockJob (user: UserModel, blocked: boolean, reason?: string) { | 382 | addUserBlockJob (user: MUser, blocked: boolean, reason?: string) { |
385 | const reasonString = reason ? ` for the following reason: ${reason}` : '' | 383 | const reasonString = reason ? ` for the following reason: ${reason}` : '' |
386 | const blockedWord = blocked ? 'blocked' : 'unblocked' | 384 | const blockedWord = blocked ? 'blocked' : 'unblocked' |
387 | const blockedString = `Your account ${user.username} on ${WEBSERVER.HOST} has been ${blockedWord}${reasonString}.` | 385 | const blockedString = `Your account ${user.username} on ${WEBSERVER.HOST} has been ${blockedWord}${reasonString}.` |