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 { VideoPrivacy } from '../../../../shared/models/videos'
9 import { Notifier } from '../../notifier'
11 async function processAnnounceActivity (activity: ActivityAnnounce, actorAnnouncer: ActorModel) {
12 return retryTransactionWrapper(processVideoShare, actorAnnouncer, activity)
15 // ---------------------------------------------------------------------------
18 processAnnounceActivity
21 // ---------------------------------------------------------------------------
23 async function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) {
24 const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id
26 const { video, created: videoCreated } = await getOrCreateVideoAndAccountAndChannel({ videoObject: objectUri })
28 await sequelizeTypescript.transaction(async t => {
32 actorId: actorAnnouncer.id,
37 const [ , created ] = await VideoShareModel.findOrCreate({
45 if (video.isOwned() && created === true) {
46 // Don't resend the activity to the sender
47 const exceptions = [ actorAnnouncer ]
49 await forwardVideoRelatedActivity(activity, t, exceptions, video)
55 if (videoCreated) Notifier.Instance.notifyOnNewVideo(video)