aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-05-05 20:22:22 +0200
committerRigel Kent <par@rigelk.eu>2020-05-08 15:31:51 +0200
commitdf4c603dea022146476812cbbc2b9f8f1e5e4870 (patch)
treec0d27576fb6711b4b64d2186e8dca3f04b9b1dfe /shared/extra-utils
parent91b8e675e26dd65e1ebb23706cb16b3a3f8bcf73 (diff)
downloadPeerTube-df4c603dea022146476812cbbc2b9f8f1e5e4870.tar.gz
PeerTube-df4c603dea022146476812cbbc2b9f8f1e5e4870.tar.zst
PeerTube-df4c603dea022146476812cbbc2b9f8f1e5e4870.zip
Switch emails to pug templates and provide richer html/text-only versions
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/users/user-notifications.ts60
1 files changed, 30 insertions, 30 deletions
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts
index f949878e4..bd00894c4 100644
--- a/shared/extra-utils/users/user-notifications.ts
+++ b/shared/extra-utils/users/user-notifications.ts
@@ -110,10 +110,10 @@ async function checkNotification (
110 110
111 if (checkType === 'presence') { 111 if (checkType === 'presence') {
112 const obj = inspect(base.socketNotifications, { depth: 5 }) 112 const obj = inspect(base.socketNotifications, { depth: 5 })
113 expect(socketNotification, 'The socket notification is absent. ' + obj).to.not.be.undefined 113 expect(socketNotification, 'The socket notification is absent when is should be present. ' + obj).to.not.be.undefined
114 } else { 114 } else {
115 const obj = inspect(socketNotification, { depth: 5 }) 115 const obj = inspect(socketNotification, { depth: 5 })
116 expect(socketNotification, 'The socket notification is present. ' + obj).to.be.undefined 116 expect(socketNotification, 'The socket notification is present when is should not be present. ' + obj).to.be.undefined
117 } 117 }
118 } 118 }
119 119
@@ -125,9 +125,9 @@ async function checkNotification (
125 .find(e => emailNotificationFinder(e)) 125 .find(e => emailNotificationFinder(e))
126 126
127 if (checkType === 'presence') { 127 if (checkType === 'presence') {
128 expect(email, 'The email is absent. ' + inspect(base.emails)).to.not.be.undefined 128 expect(email, 'The email is absent when is should be present. ' + inspect(base.emails)).to.not.be.undefined
129 } else { 129 } else {
130 expect(email, 'The email is present. ' + inspect(email)).to.be.undefined 130 expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined
131 } 131 }
132 } 132 }
133} 133}
@@ -172,12 +172,12 @@ async function checkNewVideoFromSubscription (base: CheckerBaseParams, videoName
172 } 172 }
173 } 173 }
174 174
175 function emailFinder (email: object) { 175 function emailNotificationFinder (email: object) {
176 const text = email['text'] 176 const text = email['text']
177 return text.indexOf(videoUUID) !== -1 && text.indexOf('Your subscription') !== -1 177 return text.indexOf(videoUUID) !== -1 && text.indexOf('Your subscription') !== -1
178 } 178 }
179 179
180 await checkNotification(base, notificationChecker, emailFinder, type) 180 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
181} 181}
182 182
183async function checkVideoIsPublished (base: CheckerBaseParams, videoName: string, videoUUID: string, type: CheckerType) { 183async function checkVideoIsPublished (base: CheckerBaseParams, videoName: string, videoUUID: string, type: CheckerType) {
@@ -195,12 +195,12 @@ async function checkVideoIsPublished (base: CheckerBaseParams, videoName: string
195 } 195 }
196 } 196 }
197 197
198 function emailFinder (email: object) { 198 function emailNotificationFinder (email: object) {
199 const text: string = email['text'] 199 const text: string = email['text']
200 return text.includes(videoUUID) && text.includes('Your video') 200 return text.includes(videoUUID) && text.includes('Your video')
201 } 201 }
202 202
203 await checkNotification(base, notificationChecker, emailFinder, type) 203 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
204} 204}
205 205
206async function checkMyVideoImportIsFinished ( 206async function checkMyVideoImportIsFinished (
@@ -226,14 +226,14 @@ async function checkMyVideoImportIsFinished (
226 } 226 }
227 } 227 }
228 228
229 function emailFinder (email: object) { 229 function emailNotificationFinder (email: object) {
230 const text: string = email['text'] 230 const text: string = email['text']
231 const toFind = success ? ' finished' : ' error' 231 const toFind = success ? ' finished' : ' error'
232 232
233 return text.includes(url) && text.includes(toFind) 233 return text.includes(url) && text.includes(toFind)
234 } 234 }
235 235
236 await checkNotification(base, notificationChecker, emailFinder, type) 236 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
237} 237}
238 238
239async function checkUserRegistered (base: CheckerBaseParams, username: string, type: CheckerType) { 239async function checkUserRegistered (base: CheckerBaseParams, username: string, type: CheckerType) {
@@ -251,13 +251,13 @@ async function checkUserRegistered (base: CheckerBaseParams, username: string, t
251 } 251 }
252 } 252 }
253 253
254 function emailFinder (email: object) { 254 function emailNotificationFinder (email: object) {
255 const text: string = email['text'] 255 const text: string = email['text']
256 256
257 return text.includes(' registered ') && text.includes(username) 257 return text.includes(' registered.') && text.includes(username)
258 } 258 }
259 259
260 await checkNotification(base, notificationChecker, emailFinder, type) 260 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
261} 261}
262 262
263async function checkNewActorFollow ( 263async function checkNewActorFollow (
@@ -291,13 +291,13 @@ async function checkNewActorFollow (
291 } 291 }
292 } 292 }
293 293
294 function emailFinder (email: object) { 294 function emailNotificationFinder (email: object) {
295 const text: string = email['text'] 295 const text: string = email['text']
296 296
297 return text.includes('Your ' + followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName) 297 return text.includes(followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName)
298 } 298 }
299 299
300 await checkNotification(base, notificationChecker, emailFinder, type) 300 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
301} 301}
302 302
303async function checkNewInstanceFollower (base: CheckerBaseParams, followerHost: string, type: CheckerType) { 303async function checkNewInstanceFollower (base: CheckerBaseParams, followerHost: string, type: CheckerType) {
@@ -320,13 +320,13 @@ async function checkNewInstanceFollower (base: CheckerBaseParams, followerHost:
320 } 320 }
321 } 321 }
322 322
323 function emailFinder (email: object) { 323 function emailNotificationFinder (email: object) {
324 const text: string = email['text'] 324 const text: string = email['text']
325 325
326 return text.includes('instance has a new follower') && text.includes(followerHost) 326 return text.includes('instance has a new follower') && text.includes(followerHost)
327 } 327 }
328 328
329 await checkNotification(base, notificationChecker, emailFinder, type) 329 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
330} 330}
331 331
332async function checkAutoInstanceFollowing (base: CheckerBaseParams, followerHost: string, followingHost: string, type: CheckerType) { 332async function checkAutoInstanceFollowing (base: CheckerBaseParams, followerHost: string, followingHost: string, type: CheckerType) {
@@ -351,13 +351,13 @@ async function checkAutoInstanceFollowing (base: CheckerBaseParams, followerHost
351 } 351 }
352 } 352 }
353 353
354 function emailFinder (email: object) { 354 function emailNotificationFinder (email: object) {
355 const text: string = email['text'] 355 const text: string = email['text']
356 356
357 return text.includes(' automatically followed a new instance') && text.includes(followingHost) 357 return text.includes(' automatically followed a new instance') && text.includes(followingHost)
358 } 358 }
359 359
360 await checkNotification(base, notificationChecker, emailFinder, type) 360 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
361} 361}
362 362
363async function checkCommentMention ( 363async function checkCommentMention (
@@ -385,13 +385,13 @@ async function checkCommentMention (
385 } 385 }
386 } 386 }
387 387
388 function emailFinder (email: object) { 388 function emailNotificationFinder (email: object) {
389 const text: string = email['text'] 389 const text: string = email['text']
390 390
391 return text.includes(' mentioned ') && text.includes(uuid) && text.includes(byAccountDisplayName) 391 return text.includes(' mentioned ') && text.includes(uuid) && text.includes(byAccountDisplayName)
392 } 392 }
393 393
394 await checkNotification(base, notificationChecker, emailFinder, type) 394 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
395} 395}
396 396
397let lastEmailCount = 0 397let lastEmailCount = 0
@@ -416,11 +416,11 @@ async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string,
416 416
417 const commentUrl = `http://localhost:${base.server.port}/videos/watch/${uuid};threadId=${threadId}` 417 const commentUrl = `http://localhost:${base.server.port}/videos/watch/${uuid};threadId=${threadId}`
418 418
419 function emailFinder (email: object) { 419 function emailNotificationFinder (email: object) {
420 return email['text'].indexOf(commentUrl) !== -1 420 return email['text'].indexOf(commentUrl) !== -1
421 } 421 }
422 422
423 await checkNotification(base, notificationChecker, emailFinder, type) 423 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
424 424
425 if (type === 'presence') { 425 if (type === 'presence') {
426 // We cannot detect email duplicates, so check we received another email 426 // We cannot detect email duplicates, so check we received another email
@@ -446,12 +446,12 @@ async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUU
446 } 446 }
447 } 447 }
448 448
449 function emailFinder (email: object) { 449 function emailNotificationFinder (email: object) {
450 const text = email['text'] 450 const text = email['text']
451 return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1 451 return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1
452 } 452 }
453 453
454 await checkNotification(base, notificationChecker, emailFinder, type) 454 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
455} 455}
456 456
457async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { 457async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
@@ -471,12 +471,12 @@ async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, vi
471 } 471 }
472 } 472 }
473 473
474 function emailFinder (email: object) { 474 function emailNotificationFinder (email: object) {
475 const text = email['text'] 475 const text = email['text']
476 return text.indexOf(videoUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1 476 return text.indexOf(videoUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1
477 } 477 }
478 478
479 await checkNotification(base, notificationChecker, emailFinder, type) 479 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
480} 480}
481 481
482async function checkNewBlacklistOnMyVideo ( 482async function checkNewBlacklistOnMyVideo (
@@ -498,12 +498,12 @@ async function checkNewBlacklistOnMyVideo (
498 checkVideo(video, videoName, videoUUID) 498 checkVideo(video, videoName, videoUUID)
499 } 499 }
500 500
501 function emailFinder (email: object) { 501 function emailNotificationFinder (email: object) {
502 const text = email['text'] 502 const text = email['text']
503 return text.indexOf(videoUUID) !== -1 && text.indexOf(' ' + blacklistType) !== -1 503 return text.indexOf(videoUUID) !== -1 && text.indexOf(' ' + blacklistType) !== -1
504 } 504 }
505 505
506 await checkNotification(base, notificationChecker, emailFinder, 'presence') 506 await checkNotification(base, notificationChecker, emailNotificationFinder, 'presence')
507} 507}
508 508
509// --------------------------------------------------------------------------- 509// ---------------------------------------------------------------------------