From 5b77537ce54832f47931ba47dc513be2a9197f92 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Jul 2019 12:04:15 +0200 Subject: Correctly notify on auto blacklist --- server/controllers/api/videos/blacklist.ts | 3 ++- server/controllers/api/videos/import.ts | 9 ++++++++- server/controllers/api/videos/index.ts | 19 +++++++------------ 3 files changed, 17 insertions(+), 14 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index 0ec518e0d..9ff494def 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts @@ -115,6 +115,7 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex const videoBlacklistType = videoBlacklist.type await videoBlacklist.destroy({ transaction: t }) + video.VideoBlacklist = undefined // Re federate the video if (unfederated === true) { @@ -131,7 +132,7 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex // Delete on object so new video notifications will send delete video.VideoBlacklist - Notifier.Instance.notifyOnNewVideo(video) + Notifier.Instance.notifyOnNewVideoIfNeeded(video) } logger.info('Video %s removed from blacklist.', res.locals.video.uuid) diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index 47c6f122c..1f08fe20a 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -245,7 +245,14 @@ function insertIntoDB (parameters: { if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t) - await autoBlacklistVideoIfNeeded({ video, user, isRemote: false, isNew: true, transaction: t }) + await autoBlacklistVideoIfNeeded({ + video, + user, + notify: false, + isRemote: false, + isNew: true, + transaction: t + }) // Set tags to the video if (tags) { diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 6a79a16c7..973bf1123 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -235,7 +235,7 @@ async function addVideo (req: express.Request, res: express.Response) { // Create the torrent file await video.createTorrentAndSetInfoHash(videoFile) - const { videoCreated, videoWasAutoBlacklisted } = await sequelizeTypescript.transaction(async t => { + const { videoCreated } = await sequelizeTypescript.transaction(async t => { const sequelizeOptions = { transaction: t } const videoCreated = await video.save(sequelizeOptions) @@ -268,23 +268,22 @@ async function addVideo (req: express.Request, res: express.Response) { }, { transaction: t }) } - const videoWasAutoBlacklisted = await autoBlacklistVideoIfNeeded({ + await autoBlacklistVideoIfNeeded({ video, user: res.locals.oauth.token.User, isRemote: false, isNew: true, transaction: t }) - if (!videoWasAutoBlacklisted) await federateVideoIfNeeded(video, true, t) + await federateVideoIfNeeded(video, true, t) auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON())) logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) - return { videoCreated, videoWasAutoBlacklisted } + return { videoCreated } }) - if (videoWasAutoBlacklisted) Notifier.Instance.notifyOnVideoAutoBlacklist(videoCreated) - else Notifier.Instance.notifyOnNewVideo(videoCreated) + Notifier.Instance.notifyOnNewVideoIfNeeded(videoCreated) if (video.state === VideoState.TO_TRANSCODE) { // Put uuid because we don't have id auto incremented for now @@ -413,11 +412,7 @@ async function updateVideo (req: express.Request, res: express.Response) { }) const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE - - // Don't send update if the video was unfederated - if (!videoInstanceUpdated.VideoBlacklist || videoInstanceUpdated.VideoBlacklist.unfederated === false) { - await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) - } + await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) auditLogger.update( getAuditIdFromRes(res), @@ -430,7 +425,7 @@ async function updateVideo (req: express.Request, res: express.Response) { }) if (wasUnlistedVideo || wasPrivateVideo) { - Notifier.Instance.notifyOnNewVideo(videoInstanceUpdated) + Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated) } Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated }) -- cgit v1.2.3