1 import { ActivityAnnounce } from '../../../../shared/models/activitypub'
2 import { retryTransactionWrapper } from '../../../helpers/database-utils'
3 import { sequelizeTypescript } from '../../../initializers/database'
4 import { VideoShareModel } from '../../../models/video/video-share'
5 import { forwardVideoRelatedActivity } from '../send/utils'
6 import { getOrCreateAPVideo } from '../videos'
7 import { Notifier } from '../../notifier'
8 import { logger } from '../../../helpers/logger'
9 import { APProcessorOptions } from '../../../types/activitypub-processor.model'
10 import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models'
12 async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) {
13 const { activity, byActor: actorAnnouncer } = options
14 // Only notify if it is not from a fetcher job
15 const notify = options.fromFetch !== true
17 return retryTransactionWrapper(processVideoShare, actorAnnouncer, activity, notify)
20 // ---------------------------------------------------------------------------
23 processAnnounceActivity
26 // ---------------------------------------------------------------------------
28 async function processVideoShare (actorAnnouncer: MActorSignature, activity: ActivityAnnounce, notify: boolean) {
29 const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id
31 let video: MVideoAccountLightBlacklistAllFiles
32 let videoCreated: boolean
35 const result = await getOrCreateAPVideo({ videoObject: objectUri })
37 videoCreated = result.created
39 logger.debug('Cannot process share of %s. Maybe this is not a video object, so just skipping.', objectUri, { err })
43 await sequelizeTypescript.transaction(async t => {
47 actorId: actorAnnouncer.id,
52 const [ , created ] = await VideoShareModel.findOrCreate({
60 if (video.isOwned() && created === true) {
61 // Don't resend the activity to the sender
62 const exceptions = [ actorAnnouncer ]
64 await forwardVideoRelatedActivity(activity, t, exceptions, video)
70 if (videoCreated && notify) Notifier.Instance.notifyOnNewVideoIfNeeded(video)