aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/emailer.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-01-04 08:56:20 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-01-09 11:15:15 +0100
commitf7cc67b455a12ccae9b0ea16876d166720364357 (patch)
treeeac2cdbf2e92a16b3eda5d74371c82bd79ae22cb /server/lib/emailer.ts
parentdc13348070d808d0ba3feb56a435b835c2e7e791 (diff)
downloadPeerTube-f7cc67b455a12ccae9b0ea16876d166720364357.tar.gz
PeerTube-f7cc67b455a12ccae9b0ea16876d166720364357.tar.zst
PeerTube-f7cc67b455a12ccae9b0ea16876d166720364357.zip
Add new follow, mention and user registered notifs
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r--server/lib/emailer.ts63
1 files changed, 60 insertions, 3 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index 6dc8f2adf..3429498e7 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -11,6 +11,7 @@ import { VideoCommentModel } from '../models/video/video-comment'
11import { VideoAbuseModel } from '../models/video/video-abuse' 11import { VideoAbuseModel } from '../models/video/video-abuse'
12import { VideoBlacklistModel } from '../models/video/video-blacklist' 12import { VideoBlacklistModel } from '../models/video/video-blacklist'
13import { VideoImportModel } from '../models/video/video-import' 13import { VideoImportModel } from '../models/video/video-import'
14import { ActorFollowModel } from '../models/activitypub/actor-follow'
14 15
15class Emailer { 16class Emailer {
16 17
@@ -103,6 +104,25 @@ class Emailer {
103 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 104 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
104 } 105 }
105 106
107 addNewFollowNotification (to: string[], actorFollow: ActorFollowModel, followType: 'account' | 'channel') {
108 const followerName = actorFollow.ActorFollower.Account.getDisplayName()
109 const followingName = (actorFollow.ActorFollowing.VideoChannel || actorFollow.ActorFollowing.Account).getDisplayName()
110
111 const text = `Hi dear user,\n\n` +
112 `Your ${followType} ${followingName} has a new subscriber: ${followerName}` +
113 `\n\n` +
114 `Cheers,\n` +
115 `PeerTube.`
116
117 const emailPayload: EmailPayload = {
118 to,
119 subject: 'New follower on your channel ' + followingName,
120 text
121 }
122
123 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
124 }
125
106 myVideoPublishedNotification (to: string[], video: VideoModel) { 126 myVideoPublishedNotification (to: string[], video: VideoModel) {
107 const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() 127 const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath()
108 128
@@ -185,7 +205,29 @@ class Emailer {
185 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 205 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
186 } 206 }
187 207
188 async addVideoAbuseModeratorsNotification (to: string[], videoAbuse: VideoAbuseModel) { 208 addNewCommentMentionNotification (to: string[], comment: VideoCommentModel) {
209 const accountName = comment.Account.getDisplayName()
210 const video = comment.Video
211 const commentUrl = CONFIG.WEBSERVER.URL + comment.getCommentStaticPath()
212
213 const text = `Hi dear user,\n\n` +
214 `${accountName} mentioned you on video ${video.name}` +
215 `\n\n` +
216 `You can view the comment on ${commentUrl} ` +
217 `\n\n` +
218 `Cheers,\n` +
219 `PeerTube.`
220
221 const emailPayload: EmailPayload = {
222 to,
223 subject: 'Mention on video ' + video.name,
224 text
225 }
226
227 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
228 }
229
230 addVideoAbuseModeratorsNotification (to: string[], videoAbuse: VideoAbuseModel) {
189 const videoUrl = CONFIG.WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath() 231 const videoUrl = CONFIG.WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath()
190 232
191 const text = `Hi,\n\n` + 233 const text = `Hi,\n\n` +
@@ -202,7 +244,22 @@ class Emailer {
202 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 244 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
203 } 245 }
204 246
205 async addVideoBlacklistNotification (to: string[], videoBlacklist: VideoBlacklistModel) { 247 addNewUserRegistrationNotification (to: string[], user: UserModel) {
248 const text = `Hi,\n\n` +
249 `User ${user.username} just registered on ${CONFIG.WEBSERVER.HOST} PeerTube instance.\n\n` +
250 `Cheers,\n` +
251 `PeerTube.`
252
253 const emailPayload: EmailPayload = {
254 to,
255 subject: '[PeerTube] New user registration on ' + CONFIG.WEBSERVER.HOST,
256 text
257 }
258
259 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
260 }
261
262 addVideoBlacklistNotification (to: string[], videoBlacklist: VideoBlacklistModel) {
206 const videoName = videoBlacklist.Video.name 263 const videoName = videoBlacklist.Video.name
207 const videoUrl = CONFIG.WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() 264 const videoUrl = CONFIG.WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath()
208 265
@@ -224,7 +281,7 @@ class Emailer {
224 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 281 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
225 } 282 }
226 283
227 async addVideoUnblacklistNotification (to: string[], video: VideoModel) { 284 addVideoUnblacklistNotification (to: string[], video: VideoModel) {
228 const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() 285 const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath()
229 286
230 const text = 'Hi,\n\n' + 287 const text = 'Hi,\n\n' +