X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fprocess%2Fprocess-announce.ts;h=9cc87ee27a13fc60a5aa60efa0d323685c1bcc6f;hb=7e98a7df7d04e19ba67163a86c7b876d78d76839;hp=4e50da8d2fe36f02115e65fb3512778e810d3332;hpb=9588d4f49b7183631ddb97fa9c3cd79f9bfe2945;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts index 4e50da8d2..9cc87ee27 100644 --- a/server/lib/activitypub/process/process-announce.ts +++ b/server/lib/activitypub/process/process-announce.ts @@ -1,17 +1,24 @@ +import { getAPId } from '@server/lib/activitypub/activity' import { ActivityAnnounce } from '../../../../shared/models/activitypub' import { retryTransactionWrapper } from '../../../helpers/database-utils' -import { sequelizeTypescript } from '../../../initializers' -import { ActorModel } from '../../../models/activitypub/actor' -import { VideoModel } from '../../../models/video/video' +import { logger } from '../../../helpers/logger' +import { sequelizeTypescript } from '../../../initializers/database' import { VideoShareModel } from '../../../models/video/video-share' -import { getOrCreateActorAndServerAndModel } from '../actor' -import { forwardVideoRelatedActivity } from '../send/utils' -import { getOrCreateAccountAndVideoAndChannel } from '../videos' +import { APProcessorOptions } from '../../../types/activitypub-processor.model' +import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models' +import { Notifier } from '../../notifier' +import { forwardVideoRelatedActivity } from '../send/shared/send-utils' +import { getOrCreateAPVideo } from '../videos' -async function processAnnounceActivity (activity: ActivityAnnounce) { - const actorAnnouncer = await getOrCreateActorAndServerAndModel(activity.actor) +async function processAnnounceActivity (options: APProcessorOptions) { + const { activity, byActor: actorAnnouncer } = options + // Only notify if it is not from a fetcher job + const notify = options.fromFetch !== true - return processVideoShare(actorAnnouncer, activity) + // Announces on accounts are not supported + if (actorAnnouncer.type !== 'Application' && actorAnnouncer.type !== 'Group') return + + return retryTransactionWrapper(processVideoShare, actorAnnouncer, activity, notify) } // --------------------------------------------------------------------------- @@ -22,23 +29,22 @@ export { // --------------------------------------------------------------------------- -function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { - const options = { - arguments: [ actorAnnouncer, activity ], - errorMessage: 'Cannot share the video activity with many retries.' - } - - return retryTransactionWrapper(shareVideo, options) -} +async function processVideoShare (actorAnnouncer: MActorSignature, activity: ActivityAnnounce, notify: boolean) { + const objectUri = getAPId(activity.object) -async function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { - const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id - let video: VideoModel + let video: MVideoAccountLightBlacklistAllFiles + let videoCreated: boolean - const res = await getOrCreateAccountAndVideoAndChannel(objectUri) - video = res.video + try { + const result = await getOrCreateAPVideo({ videoObject: objectUri }) + video = result.video + videoCreated = result.created + } catch (err) { + logger.debug('Cannot process share of %s. Maybe this is not a video object, so just skipping.', objectUri, { err }) + return + } - return sequelizeTypescript.transaction(async t => { + await sequelizeTypescript.transaction(async t => { // Add share entry const share = { @@ -64,4 +70,6 @@ async function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounc return undefined }) + + if (videoCreated && notify) Notifier.Instance.notifyOnNewVideoIfNeeded(video) }