1 import { getOrCreateAPVideo } from '../videos'
2 import { forwardVideoRelatedActivity } from '../send/utils'
3 import { Redis } from '../../redis'
4 import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub'
5 import { APProcessorOptions } from '../../../types/activitypub-processor.model'
6 import { MActorSignature } from '../../../types/models'
7 import { LiveManager } from '@server/lib/live/live-manager'
9 async function processViewActivity (options: APProcessorOptions<ActivityCreate | ActivityView>) {
10 const { activity, byActor } = options
11 return processCreateView(activity, byActor)
14 // ---------------------------------------------------------------------------
20 // ---------------------------------------------------------------------------
22 async function processCreateView (activity: ActivityView | ActivityCreate, byActor: MActorSignature) {
23 const videoObject = activity.type === 'View'
25 : (activity.object as ViewObject).object
27 const { video } = await getOrCreateAPVideo({
29 fetchType: 'only-video',
34 await Redis.Instance.addVideoView(video.id)
37 if (video.isOwned()) {
38 // Our live manager will increment the counter and send the view to followers
40 LiveManager.Instance.addViewTo(video.id)
44 // Forward the view but don't resend the activity to the sender
45 const exceptions = [ byActor ]
46 await forwardVideoRelatedActivity(activity, undefined, exceptions, video)