1 import { VideoViewsManager } from '@server/lib/views/video-views-manager'
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 VideoViewsManager.Instance.processRemoteView({ video, viewerId: activity.id, 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)