1 import { ActivityAnnounce } from '../../../../shared/models/activitypub'
2 import { logger, retryTransactionWrapper } from '../../../helpers'
3 import { sequelizeTypescript } from '../../../initializers'
4 import { ActorModel } from '../../../models/activitypub/actor'
5 import { VideoModel } from '../../../models/video/video'
6 import { VideoShareModel } from '../../../models/video/video-share'
7 import { getOrCreateActorAndServerAndModel } from '../actor'
8 import { forwardActivity } from '../send/misc'
9 import { processCreateActivity } from './process-create'
11 async function processAnnounceActivity (activity: ActivityAnnounce) {
12 const announcedActivity = activity.object
13 const actorAnnouncer = await getOrCreateActorAndServerAndModel(activity.actor)
15 if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'Video') {
16 return processVideoShare(actorAnnouncer, activity)
20 'Unknown activity object type %s -> %s when announcing activity.', announcedActivity.type, announcedActivity.object.type,
21 { activity: activity.id }
27 // ---------------------------------------------------------------------------
30 processAnnounceActivity
33 // ---------------------------------------------------------------------------
35 function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) {
37 arguments: [ actorAnnouncer, activity ],
38 errorMessage: 'Cannot share the video with many retries.'
41 return retryTransactionWrapper(shareVideo, options)
44 function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounce) {
45 const announcedActivity = activity.object
47 return sequelizeTypescript.transaction(async t => {
49 const video: VideoModel = await processCreateActivity(announcedActivity)
52 actorId: actorAnnouncer.id,
56 const [ , created ] = await VideoShareModel.findOrCreate({
62 if (video.isOwned() && created === true) {
63 // Don't resend the activity to the sender
64 const exceptions = [ actorAnnouncer ]
65 await forwardActivity(activity, t, exceptions)