1 import { ActorModel } from '../../../models/activitypub/actor'
2 import { getOrCreateVideoAndAccountAndChannel } from '../videos'
3 import { forwardVideoRelatedActivity } from '../send/utils'
4 import { Redis } from '../../redis'
5 import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub'
6 import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
8 async function processViewActivity (options: APProcessorOptions<ActivityCreate | ActivityView>) {
9 const { activity, byActor } = options
10 return processCreateView(activity, byActor)
13 // ---------------------------------------------------------------------------
19 // ---------------------------------------------------------------------------
21 async function processCreateView (activity: ActivityView | ActivityCreate, byActor: ActorModel) {
22 const videoObject = activity.type === 'View' ? activity.object : (activity.object as ViewObject).object
25 videoObject: videoObject,
26 fetchType: 'only-video' as 'only-video'
28 const { video } = await getOrCreateVideoAndAccountAndChannel(options)
30 await Redis.Instance.addVideoView(video.id)
32 if (video.isOwned()) {
33 // Don't resend the activity to the sender
34 const exceptions = [ byActor ]
35 await forwardVideoRelatedActivity(activity, undefined, exceptions, video)