1 import { VideoViews } from '@server/lib/video-views'
2 import { ActivityView } from '../../../../shared/models/activitypub'
3 import { APProcessorOptions } from '../../../types/activitypub-processor.model'
4 import { MActorSignature } from '../../../types/models'
5 import { forwardVideoRelatedActivity } from '../send/shared/send-utils'
6 import { getOrCreateAPVideo } from '../videos'
8 async function processViewActivity (options: APProcessorOptions<ActivityView>) {
9 const { activity, byActor } = options
11 return processCreateView(activity, byActor)
14 // ---------------------------------------------------------------------------
20 // ---------------------------------------------------------------------------
22 async function processCreateView (activity: ActivityView, byActor: MActorSignature) {
23 const videoObject = activity.object
25 const { video } = await getOrCreateAPVideo({
27 fetchType: 'only-video',
31 const viewerExpires = activity.expires
32 ? new Date(activity.expires)
35 await VideoViews.Instance.processView({ video, ip: null, viewerExpires })
37 if (video.isOwned()) {
38 // Forward the view but don't resend the activity to the sender
39 const exceptions = [ byActor ]
40 await forwardVideoRelatedActivity(activity, undefined, exceptions, video)