X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fschedulers%2Fupdate-videos-scheduler.ts;h=350a335d379517d1d7f1a630c8037fe36f3059e1;hb=22a73cb879a5cc775d4bec3d72fa9c9cf52e5175;hp=80080a132e8b3da3cd391b6b3518882ed134c9da;hpb=97567dd81f508dd6295ac4d73d849aa2ce0a6549;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/schedulers/update-videos-scheduler.ts b/server/lib/schedulers/update-videos-scheduler.ts index 80080a132..350a335d3 100644 --- a/server/lib/schedulers/update-videos-scheduler.ts +++ b/server/lib/schedulers/update-videos-scheduler.ts @@ -6,8 +6,8 @@ import { federateVideoIfNeeded } from '../activitypub' import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' import { VideoPrivacy } from '../../../shared/models/videos' import { Notifier } from '../notifier' -import { VideoModel } from '../../models/video/video' import { sequelizeTypescript } from '../../initializers/database' +import { MVideoFullLight } from '@server/typings/models' export class UpdateVideosScheduler extends AbstractScheduler { @@ -28,25 +28,23 @@ export class UpdateVideosScheduler extends AbstractScheduler { const publishedVideos = await sequelizeTypescript.transaction(async t => { const schedules = await ScheduleVideoUpdateModel.listVideosToUpdate(t) - const publishedVideos: VideoModel[] = [] + const publishedVideos: MVideoFullLight[] = [] for (const schedule of schedules) { const video = schedule.Video logger.info('Executing scheduled video update on %s.', video.uuid) if (schedule.privacy) { - const oldPrivacy = video.privacy - const isNewVideo = oldPrivacy === VideoPrivacy.PRIVATE - - video.privacy = schedule.privacy - if (isNewVideo === true) video.publishedAt = new Date() + const wasConfidentialVideo = video.isConfidential() + const isNewVideo = video.isNewVideo(schedule.privacy) + video.setPrivacy(schedule.privacy) await video.save({ transaction: t }) await federateVideoIfNeeded(video, isNewVideo, t) - if (oldPrivacy === VideoPrivacy.UNLISTED || oldPrivacy === VideoPrivacy.PRIVATE) { - video.ScheduleVideoUpdate = schedule - publishedVideos.push(video) + if (wasConfidentialVideo) { + const videoToPublish: MVideoFullLight = Object.assign(video, { ScheduleVideoUpdate: schedule, UserVideoHistories: [] }) + publishedVideos.push(videoToPublish) } } @@ -57,7 +55,7 @@ export class UpdateVideosScheduler extends AbstractScheduler { }) for (const v of publishedVideos) { - Notifier.Instance.notifyOnNewVideo(v) + Notifier.Instance.notifyOnNewVideoIfNeeded(v) Notifier.Instance.notifyOnVideoPublishedAfterScheduledUpdate(v) } }