]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/process/process-view.ts
Stronger model typings
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-view.ts
CommitLineData
848f499d
C
1import { getOrCreateVideoAndAccountAndChannel } from '../videos'
2import { forwardVideoRelatedActivity } from '../send/utils'
3import { Redis } from '../../redis'
4import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub'
1198edf4 5import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
453e83ea 6import { MActorSignature } from '../../../typings/models'
848f499d 7
1198edf4
C
8async function processViewActivity (options: APProcessorOptions<ActivityCreate | ActivityView>) {
9 const { activity, byActor } = options
848f499d
C
10 return processCreateView(activity, byActor)
11}
12
13// ---------------------------------------------------------------------------
14
15export {
16 processViewActivity
17}
18
19// ---------------------------------------------------------------------------
20
453e83ea 21async function processCreateView (activity: ActivityView | ActivityCreate, byActor: MActorSignature) {
848f499d
C
22 const videoObject = activity.type === 'View' ? activity.object : (activity.object as ViewObject).object
23
24 const options = {
453e83ea 25 videoObject,
848f499d
C
26 fetchType: 'only-video' as 'only-video'
27 }
28 const { video } = await getOrCreateVideoAndAccountAndChannel(options)
29
30 await Redis.Instance.addVideoView(video.id)
31
32 if (video.isOwned()) {
33 // Don't resend the activity to the sender
34 const exceptions = [ byActor ]
35 await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
36 }
37}