From e8d246d5267ea8b6b3114d4bcf4f34fe5f3a5241 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 28 Dec 2018 13:47:17 +0100 Subject: Add notification settings migration --- server/controllers/api/videos/index.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 94ed08fed..33521a8c1 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -264,7 +264,6 @@ async function addVideo (req: express.Request, res: express.Response) { } await federateVideoIfNeeded(video, true, t) - Notifier.Instance.notifyOnNewVideo(video) auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON())) logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) @@ -272,6 +271,8 @@ async function addVideo (req: express.Request, res: express.Response) { return videoCreated }) + Notifier.Instance.notifyOnNewVideo(videoCreated) + if (video.state === VideoState.TO_TRANSCODE) { // Put uuid because we don't have id auto incremented for now const dataInput = { @@ -311,10 +312,8 @@ async function updateVideo (req: express.Request, res: express.Response) { } try { - await sequelizeTypescript.transaction(async t => { - const sequelizeOptions = { - transaction: t - } + const videoInstanceUpdated = await sequelizeTypescript.transaction(async t => { + const sequelizeOptions = { transaction: t } const oldVideoChannel = videoInstance.VideoChannel if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name) @@ -367,17 +366,19 @@ async function updateVideo (req: express.Request, res: express.Response) { const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) - if (wasUnlistedVideo || wasPrivateVideo) { - Notifier.Instance.notifyOnNewVideo(videoInstanceUpdated) - } - auditLogger.update( getAuditIdFromRes(res), new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()), oldVideoAuditView ) logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid) + + return videoInstanceUpdated }) + + if (wasUnlistedVideo || wasPrivateVideo) { + Notifier.Instance.notifyOnNewVideo(videoInstanceUpdated) + } } catch (err) { // Force fields we want to update // If the transaction is retried, sequelize will think the object has not changed -- cgit v1.2.3