diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/users/user-notifications.ts | 61 | ||||
-rw-r--r-- | shared/models/users/user-notification-setting.model.ts | 15 | ||||
-rw-r--r-- | shared/models/users/user-notification.model.ts | 8 |
3 files changed, 79 insertions, 5 deletions
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts index 2061e3353..98d222e1d 100644 --- a/shared/extra-utils/users/user-notifications.ts +++ b/shared/extra-utils/users/user-notifications.ts | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { inspect } from 'util' | 4 | import { inspect } from 'util' |
5 | import { AbuseState } from '@shared/models' | ||
5 | import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' | 6 | import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' |
6 | import { MockSmtpServer } from '../miscs/email' | 7 | import { MockSmtpServer } from '../miscs/email' |
7 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | 8 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' |
@@ -464,6 +465,62 @@ async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUU | |||
464 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 465 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) |
465 | } | 466 | } |
466 | 467 | ||
468 | async function checkNewAbuseMessage (base: CheckerBaseParams, abuseId: number, message: string, toEmail: string, type: CheckerType) { | ||
469 | const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE | ||
470 | |||
471 | function notificationChecker (notification: UserNotification, type: CheckerType) { | ||
472 | if (type === 'presence') { | ||
473 | expect(notification).to.not.be.undefined | ||
474 | expect(notification.type).to.equal(notificationType) | ||
475 | |||
476 | expect(notification.abuse.id).to.equal(abuseId) | ||
477 | } else { | ||
478 | expect(notification).to.satisfy((n: UserNotification) => { | ||
479 | return n === undefined || n.type !== notificationType || n.abuse === undefined || n.abuse.id !== abuseId | ||
480 | }) | ||
481 | } | ||
482 | } | ||
483 | |||
484 | function emailNotificationFinder (email: object) { | ||
485 | const text = email['text'] | ||
486 | const to = email['to'].filter(t => t.address === toEmail) | ||
487 | |||
488 | return text.indexOf(message) !== -1 && to.length !== 0 | ||
489 | } | ||
490 | |||
491 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | ||
492 | } | ||
493 | |||
494 | async function checkAbuseStateChange (base: CheckerBaseParams, abuseId: number, state: AbuseState, type: CheckerType) { | ||
495 | const notificationType = UserNotificationType.ABUSE_STATE_CHANGE | ||
496 | |||
497 | function notificationChecker (notification: UserNotification, type: CheckerType) { | ||
498 | if (type === 'presence') { | ||
499 | expect(notification).to.not.be.undefined | ||
500 | expect(notification.type).to.equal(notificationType) | ||
501 | |||
502 | expect(notification.abuse.id).to.equal(abuseId) | ||
503 | expect(notification.abuse.state).to.equal(state) | ||
504 | } else { | ||
505 | expect(notification).to.satisfy((n: UserNotification) => { | ||
506 | return n === undefined || n.abuse === undefined || n.abuse.id !== abuseId | ||
507 | }) | ||
508 | } | ||
509 | } | ||
510 | |||
511 | function emailNotificationFinder (email: object) { | ||
512 | const text = email['text'] | ||
513 | |||
514 | const contains = state === AbuseState.ACCEPTED | ||
515 | ? ' accepted' | ||
516 | : ' rejected' | ||
517 | |||
518 | return text.indexOf(contains) !== -1 | ||
519 | } | ||
520 | |||
521 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | ||
522 | } | ||
523 | |||
467 | async function checkNewCommentAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { | 524 | async function checkNewCommentAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { |
468 | const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS | 525 | const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS |
469 | 526 | ||
@@ -579,6 +636,8 @@ function getAllNotificationsSettings () { | |||
579 | newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 636 | newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
580 | newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 637 | newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
581 | newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 638 | newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
639 | abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
640 | abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
582 | autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | 641 | autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL |
583 | } as UserNotificationSetting | 642 | } as UserNotificationSetting |
584 | } | 643 | } |
@@ -676,6 +735,8 @@ export { | |||
676 | updateMyNotificationSettings, | 735 | updateMyNotificationSettings, |
677 | checkNewVideoAbuseForModerators, | 736 | checkNewVideoAbuseForModerators, |
678 | checkVideoAutoBlacklistForModerators, | 737 | checkVideoAutoBlacklistForModerators, |
738 | checkNewAbuseMessage, | ||
739 | checkAbuseStateChange, | ||
679 | getUserNotifications, | 740 | getUserNotifications, |
680 | markAsReadNotifications, | 741 | markAsReadNotifications, |
681 | getLastNotification, | 742 | getLastNotification, |
diff --git a/shared/models/users/user-notification-setting.model.ts b/shared/models/users/user-notification-setting.model.ts index 4e2230a76..c7590fa8a 100644 --- a/shared/models/users/user-notification-setting.model.ts +++ b/shared/models/users/user-notification-setting.model.ts | |||
@@ -5,16 +5,23 @@ export enum UserNotificationSettingValue { | |||
5 | } | 5 | } |
6 | 6 | ||
7 | export interface UserNotificationSetting { | 7 | export interface UserNotificationSetting { |
8 | newVideoFromSubscription: UserNotificationSettingValue | ||
9 | newCommentOnMyVideo: UserNotificationSettingValue | ||
10 | abuseAsModerator: UserNotificationSettingValue | 8 | abuseAsModerator: UserNotificationSettingValue |
11 | videoAutoBlacklistAsModerator: UserNotificationSettingValue | 9 | videoAutoBlacklistAsModerator: UserNotificationSettingValue |
10 | newUserRegistration: UserNotificationSettingValue | ||
11 | |||
12 | newVideoFromSubscription: UserNotificationSettingValue | ||
13 | |||
12 | blacklistOnMyVideo: UserNotificationSettingValue | 14 | blacklistOnMyVideo: UserNotificationSettingValue |
13 | myVideoPublished: UserNotificationSettingValue | 15 | myVideoPublished: UserNotificationSettingValue |
14 | myVideoImportFinished: UserNotificationSettingValue | 16 | myVideoImportFinished: UserNotificationSettingValue |
15 | newUserRegistration: UserNotificationSettingValue | 17 | |
16 | newFollow: UserNotificationSettingValue | ||
17 | commentMention: UserNotificationSettingValue | 18 | commentMention: UserNotificationSettingValue |
19 | newCommentOnMyVideo: UserNotificationSettingValue | ||
20 | |||
21 | newFollow: UserNotificationSettingValue | ||
18 | newInstanceFollower: UserNotificationSettingValue | 22 | newInstanceFollower: UserNotificationSettingValue |
19 | autoInstanceFollowing: UserNotificationSettingValue | 23 | autoInstanceFollowing: UserNotificationSettingValue |
24 | |||
25 | abuseStateChange: UserNotificationSettingValue | ||
26 | abuseNewMessage: UserNotificationSettingValue | ||
20 | } | 27 | } |
diff --git a/shared/models/users/user-notification.model.ts b/shared/models/users/user-notification.model.ts index 5f7c33976..e2f2234e4 100644 --- a/shared/models/users/user-notification.model.ts +++ b/shared/models/users/user-notification.model.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { FollowState } from '../actors' | 1 | import { FollowState } from '../actors' |
2 | import { AbuseState } from '../moderation' | ||
2 | 3 | ||
3 | export enum UserNotificationType { | 4 | export enum UserNotificationType { |
4 | NEW_VIDEO_FROM_SUBSCRIPTION = 1, | 5 | NEW_VIDEO_FROM_SUBSCRIPTION = 1, |
@@ -21,7 +22,11 @@ export enum UserNotificationType { | |||
21 | 22 | ||
22 | NEW_INSTANCE_FOLLOWER = 13, | 23 | NEW_INSTANCE_FOLLOWER = 13, |
23 | 24 | ||
24 | AUTO_INSTANCE_FOLLOWING = 14 | 25 | AUTO_INSTANCE_FOLLOWING = 14, |
26 | |||
27 | ABUSE_STATE_CHANGE = 15, | ||
28 | |||
29 | ABUSE_NEW_MESSAGE = 16 | ||
25 | } | 30 | } |
26 | 31 | ||
27 | export interface VideoInfo { | 32 | export interface VideoInfo { |
@@ -66,6 +71,7 @@ export interface UserNotification { | |||
66 | 71 | ||
67 | abuse?: { | 72 | abuse?: { |
68 | id: number | 73 | id: number |
74 | state: AbuseState | ||
69 | 75 | ||
70 | video?: VideoInfo | 76 | video?: VideoInfo |
71 | 77 | ||