1 import { ActivityAnnounce } from '../../../../shared/models/activitypub'
2 import { retryTransactionWrapper } from '../../../helpers/database-utils'
3 import { sequelizeTypescript } from '../../../initializers'
4 import { ActorModel } from '../../../models/activitypub/actor'
5 import { VideoShareModel } from '../../../models/video/video-share'
6 import { forwardVideoRelatedActivity } from '../send/utils'
7 import { getOrCreateVideoAndAccountAndChannel } from '../videos'
8 import { Notifier } from '../../notifier'
9 import { VideoModel } from '../../../models/video/video'
10 import { logger } from '../../../helpers/logger'
12 async function processAnnounceActivity (activity: ActivityAnnounce, actorAnnouncer: ActorModel) {
13 return retryTransactionWrapper(processVideoShare, actorAnnouncer, activity)
16 // ---------------------------------------------------------------------------
19 processAnnounceActivity
22 // ---------------------------------------------------------------------------
24 async function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) {
25 const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id
28 let videoCreated: boolean
31 const result = await getOrCreateVideoAndAccountAndChannel({ videoObject: objectUri })
33 videoCreated = result.created
35 logger.debug('Cannot process share of %s. Maybe this is not a video object, so just skipping.', objectUri, { err })
39 await sequelizeTypescript.transaction(async t => {
43 actorId: actorAnnouncer.id,
48 const [ , created ] = await VideoShareModel.findOrCreate({
56 if (video.isOwned() && created === true) {
57 // Don't resend the activity to the sender
58 const exceptions = [ actorAnnouncer ]
60 await forwardVideoRelatedActivity(activity, t, exceptions, video)
66 if (videoCreated) Notifier.Instance.notifyOnNewVideo(video)