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'
7 async function processViewActivity (activity: ActivityView | ActivityCreate, byActor: ActorModel) {
8 return processCreateView(activity, byActor)
11 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 async function processCreateView (activity: ActivityView | ActivityCreate, byActor: ActorModel) {
20 const videoObject = activity.type === 'View' ? activity.object : (activity.object as ViewObject).object
23 videoObject: videoObject,
24 fetchType: 'only-video' as 'only-video'
26 const { video } = await getOrCreateVideoAndAccountAndChannel(options)
28 await Redis.Instance.addVideoView(video.id)
30 if (video.isOwned()) {
31 // Don't resend the activity to the sender
32 const exceptions = [ byActor ]
33 await forwardVideoRelatedActivity(activity, undefined, exceptions, video)