Correctly notify on auto blacklist

This commit is contained in:
Chocobozzz
2019-07-23 12:04:15 +02:00
committed by Chocobozzz
parent d8e9a42c4b
commit 5b77537ce5
15 changed files with 61 additions and 55 deletions

View File

@@ -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)

View File

@@ -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) {

View File

@@ -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 })