import { MCommentOwnerVideo, MVideoAccountLight, MVideoFullLight } from '../../types/models/video'
import { JobQueue } from '../job-queue'
import { PeerTubeSocket } from '../peertube-socket'
+import { Hooks } from '../plugins/hooks'
import {
AbstractNotification,
AbuseStateChangeForReporter,
AutoFollowForInstance,
CommentMention,
- StudioEditionFinishedForOwner,
FollowForInstance,
FollowForUser,
ImportFinishedForOwner,
OwnedPublicationAfterScheduleUpdate,
OwnedPublicationAfterTranscoding,
RegistrationForModerators,
+ StudioEditionFinishedForOwner,
UnblacklistForOwner
} from './shared'
for (const user of users) {
const setting = object.getSetting(user)
- if (this.isWebNotificationEnabled(setting)) {
- const notification = await object.createNotification(user)
+ const webNotificationEnabled = this.isWebNotificationEnabled(setting)
+ const emailNotificationEnabled = this.isEmailEnabled(user, setting)
+ const notification = object.createNotification(user)
+
+ if (webNotificationEnabled) {
+ await notification.save()
PeerTubeSocket.Instance.sendNotification(user.id, notification)
}
- if (this.isEmailEnabled(user, setting)) {
+ if (emailNotificationEnabled) {
toEmails.push(user.email)
}
+
+ Hooks.runAction('action:notifier.notification.created', { webNotificationEnabled, emailNotificationEnabled, user, notification })
}
for (const to of toEmails) {
return user.NotificationSetting.abuseNewMessage
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.ABUSE_NEW_MESSAGE,
userId: user.id,
abuseId: this.abuse.id
return [ this.user ]
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.ABUSE_STATE_CHANGE,
userId: user.id,
abuseId: this.abuse.id
return this.moderators
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.NEW_ABUSE_FOR_MODERATORS,
userId: user.id,
abuseId: this.payload.abuseInstance.id
return this.moderators
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS,
userId: user.id,
videoBlacklistId: this.payload.id
return [ this.user ]
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.BLACKLIST_ON_MY_VIDEO,
userId: user.id,
videoBlacklistId: this.payload.id
return [ this.user ]
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.UNBLACKLIST_ON_MY_VIDEO,
userId: user.id,
videoId: this.payload.id
return this.users
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.COMMENT_MENTION,
userId: user.id,
commentId: this.payload.id
return [ this.user ]
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.NEW_COMMENT_ON_MY_VIDEO,
userId: user.id,
commentId: this.payload.id
abstract getSetting (user: U): UserNotificationSettingValue
abstract getTargetUsers (): U[]
- abstract createNotification (user: U): Promise<UserNotificationModelForApi>
+ abstract createNotification (user: U): UserNotificationModelForApi
abstract createEmail (to: string): EmailPayload | Promise<EmailPayload>
isDisabled (): boolean | Promise<boolean> {
return this.admins
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.AUTO_INSTANCE_FOLLOWING,
userId: user.id,
actorFollowId: this.actorFollow.id
return this.admins
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.NEW_INSTANCE_FOLLOWER,
userId: user.id,
actorFollowId: this.actorFollow.id
return [ this.user ]
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.NEW_FOLLOW,
userId: user.id,
actorFollowId: this.actorFollow.id
return this.admins
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.NEW_PEERTUBE_VERSION,
userId: user.id,
applicationId: this.payload.application.id
return this.admins
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.NEW_PLUGIN_VERSION,
userId: user.id,
pluginId: this.plugin.id
return this.moderators
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.NEW_USER_REGISTRATION,
userId: user.id,
accountId: this.payload.Account.id
return [ this.user ]
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.MY_VIDEO_PUBLISHED,
userId: user.id,
videoId: this.payload.id
return [ this.user ]
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: this.payload.success
? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS
: UserNotificationType.MY_VIDEO_IMPORT_ERROR,
return this.users
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION,
userId: user.id,
videoId: this.payload.id
return [ this.user ]
}
- async createNotification (user: MUserWithNotificationSetting) {
- const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ createNotification (user: MUserWithNotificationSetting) {
+ const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.MY_VIDEO_STUDIO_EDITION_FINISHED,
userId: user.id,
videoId: this.payload.id
async function register ({ registerHook, registerSetting, settingsManager, storageManager, peertubeHelpers }) {
const actionHooks = [
'action:application.listening',
+ 'action:notifier.notification.created',
'action:api.video.updated',
'action:api.video.deleted',
let videoUUID: string
let threadId: number
- function checkHook (hook: ServerHookName) {
- return servers[0].servers.waitUntilLog('Run hook ' + hook)
+ function checkHook (hook: ServerHookName, strictCount = true) {
+ return servers[0].servers.waitUntilLog('Run hook ' + hook, 1, strictCount)
}
before(async function () {
})
})
+ describe('Notification hook', function () {
+
+ it('Should run action:notifier.notification.created', async function () {
+ await checkHook('action:notifier.notification.created', false)
+ })
+ })
+
after(async function () {
await cleanupTests(servers)
})
// Fired when the application has been loaded and is listening HTTP requests
'action:application.listening': true,
+ // Fired when a new notification is created
+ 'action:notifier.notification.created': true,
+
// API actions hooks give access to the original express `req` and `res` parameters
// Fired when a local video is updated